Skip to content
Snippets Groups Projects
Commit a41ca203 authored by Matei Zaharia's avatar Matei Zaharia
Browse files

Added splitWords function in Utils

parent 9f20b6b4
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,9 @@ package spark
import java.io._
private object Utils {
import scala.collection.mutable.ArrayBuffer
object Utils {
def serialize[T](o: T): Array[Byte] = {
val bos = new ByteArrayOutputStream
val oos = new ObjectOutputStream(bos)
......@@ -25,4 +27,27 @@ private object Utils {
}
return ois.readObject.asInstanceOf[T]
}
def isAlpha(c: Char) = {
(c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
}
def splitWords(s: String): Seq[String] = {
val buf = new ArrayBuffer[String]
var i = 0
while (i < s.length) {
var j = i
while (j < s.length && isAlpha(s.charAt(j))) {
j += 1
}
if (j > i) {
buf += s.substring(i, j);
}
i = j
while (i < s.length && !isAlpha(s.charAt(i))) {
i += 1
}
}
return buf
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment