diff options
author | Martin Odersky <odersky@gmail.com> | 2009-01-28 19:17:42 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-01-28 19:17:42 +0000 |
commit | e52898338ef12db769e2b61ffef748faca28e33e (patch) | |
tree | 61eb81bb036ee203970a546d218e3b64ed0e8897 /src/library/scalax/runtime/StringVector.scala | |
parent | a0c64cf5a8856cb8d905530e91ac052351b92efc (diff) | |
download | scala-e52898338ef12db769e2b61ffef748faca28e33e.tar.gz scala-e52898338ef12db769e2b61ffef748faca28e33e.tar.bz2 scala-e52898338ef12db769e2b61ffef748faca28e33e.zip |
added support for strings as collections in 2.8
Diffstat (limited to 'src/library/scalax/runtime/StringVector.scala')
-rw-r--r-- | src/library/scalax/runtime/StringVector.scala | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/library/scalax/runtime/StringVector.scala b/src/library/scalax/runtime/StringVector.scala new file mode 100644 index 0000000000..ee7a805449 --- /dev/null +++ b/src/library/scalax/runtime/StringVector.scala @@ -0,0 +1,54 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Buffer.scala 15799 2008-08-15 18:23:54Z odersky $ + + +package scalax.runtime + +import collection.immutable.Vector +import collection.mutable.{ArrayBuffer, BuilderProxy} +import collection.generic.covariant.VectorTemplate + +object StringVector { + + implicit def unbox(sv: StringVector[Char]): String = sv.mkString + +} + +@cloneable +abstract class StringVector[+A] extends VectorTemplate[StringVector, A] with Vector[A] with Boxed[String] { + + /** The length of the string */ + def length: Int + + /** The element at given index */ + def apply(idx: Int): A + + /** Creates new builder for this collection */ + def newBuilder[B] = new BuilderProxy[StringVector, B] { + val self = new ArrayBuffer[B] + def result: StringVector[B] = new StringVector[B] { + def length = self.length + def apply(n: Int) = self.apply(n) + override def foreach(f: B => Unit) = self.foreach(f) + } + } + + def unbox: String = { + val sb = new StringBuilder + for (x <- this) + sb append x.asInstanceOf[Char] + sb.toString + } + + override def toString = mkString + +} + + |