blob: c12243bed79f8140477d82eaf2cde54217b849a0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/* __ *\
** ________ ___ / / ___ 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
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] {
/** 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 ArrayBuffer[B].mapResult[StringVector] { // !!! Adriaan: can't drop [StringVector] here
buf => new StringVector[B] {
def length = buf.length
def apply(n: Int) = buf.apply(n)
override def foreach(f: B => Unit) = buf.foreach(f)
}
}
def unbox: String = {
val sb = new StringBuilder
for (x <- this)
sb append x.asInstanceOf[Char]
sb.toString
}
override def toString = mkString
}
|