summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2008-02-22 12:31:23 +0000
committermichelou <michelou@epfl.ch>2008-02-22 12:31:23 +0000
commitecca8e2e67426bb43ad01edba87400c0dbd5799c (patch)
tree1f8166f417aa33c5bb0c547bb524f4c8a4cb7c4d
parent07c5d167ad0cde416217f19d3ecb342054a507a0 (diff)
downloadscala-ecca8e2e67426bb43ad01edba87400c0dbd5799c.tar.gz
scala-ecca8e2e67426bb43ad01edba87400c0dbd5799c.tar.bz2
scala-ecca8e2e67426bb43ad01edba87400c0dbd5799c.zip
added Seq[Char] arg to append/insert
-rw-r--r--src/library/scala/StringBuilder.scala27
-rw-r--r--test/files/jvm5/stringbuilder.scala22
2 files changed, 45 insertions, 4 deletions
diff --git a/src/library/scala/StringBuilder.scala b/src/library/scala/StringBuilder.scala
index 21ee6be62b..116ec53490 100644
--- a/src/library/scala/StringBuilder.scala
+++ b/src/library/scala/StringBuilder.scala
@@ -269,6 +269,22 @@ extends (Int => Char) with Proxy {
}
/** <p>
+ * Appends the string representation of the <code>Char</code> sequence
+ * argument to this sequence.
+ * </p>
+ * <p>
+ * The characters of the sequence argument are appended, in order,
+ * to the contents of this sequence. The length of this sequence
+ * increases by the length of the argument.
+ * </p>
+ *
+ * @param x the characters to be appended.
+ * @return a reference to this object.
+ */
+ def append(x: Seq[Char]): StringBuilder =
+ append(x.toArray, 0, x.length)
+
+ /** <p>
* Appends the string representation of the <code>Char</code> array
* argument to this sequence.
* </p>
@@ -494,6 +510,17 @@ extends (Int => Char) with Proxy {
this
}
+ /** Inserts the string representation of the <code>Char</code> sequence
+ * argument into this sequence.
+ *
+ * @param at the offset position.
+ * @param x a character sequence.
+ * @return a reference to this object.
+ * @throws StringIndexOutOfBoundsException if the offset is invalid.
+ */
+ def insert(at: Int, x: Seq[Char]): StringBuilder =
+ insert(at, x.toArray)
+
/** Inserts the string representation of the <code>Char</code> array
* argument into this sequence.
*
diff --git a/test/files/jvm5/stringbuilder.scala b/test/files/jvm5/stringbuilder.scala
index c39a5d7600..d0485fcedc 100644
--- a/test/files/jvm5/stringbuilder.scala
+++ b/test/files/jvm5/stringbuilder.scala
@@ -47,8 +47,14 @@ object Test2 extends TestCase("append") with Assert {
val j0 = new java.lang.StringBuilder("abc") // Java 1.5+
val s0 = new StringBuilder("abc")
- val j1 = j0 append true append 'a' append 9 append -1L append 1.2e-10f append -2.1e+100d
- val s1 = s0 append true append 'a' append 9 append -1L append 1.2e-10f append -2.1e+100d
+ j0 append true append 'a' append 9 append -1L append 1.2e-10f append -2.1e+100d
+ s0 append true append 'a' append 9 append -1L append 1.2e-10f append -2.1e+100d
+ assertEquals("s0.toString equals j0.toString", true, s0.toString equals j0.toString)
+
+ val j1 = new java.lang.StringBuilder // Java 1.5+
+ val s1 = new StringBuilder
+ j1 append "###" append Array('0', '1', '2') append "xyz".subSequence(0, 3)
+ s1 append "###" append Array('0', '1', '2') append List('x', 'y', 'z')
assertEquals("s1.toString equals j1.toString", true, s1.toString equals j1.toString)
}
}
@@ -59,10 +65,18 @@ object Test3 extends TestCase("insert") with Assert {
val j0 = new java.lang.StringBuilder("abc") // Java 1.5+
val s0 = new StringBuilder("abc")
- val j1 = j0 insert (0, true) insert (0, 'a') insert (0, 9) insert (0, -1L)
- val s1 = s0 insert (0, true) insert (0, 'a') insert (0, 9) insert (0, -1L)
+ j0 insert (0, true) insert (0, 'a') insert (0, 9) insert (0, -1L)
+ s0 insert (0, true) insert (0, 'a') insert (0, 9) insert (0, -1L)
+ //println("j0="+j0+", s0="+s0)//debug
+ assertEquals("s0.toString equals j0.toString", true, s0.toString equals j0.toString)
+
+ val j1 = new java.lang.StringBuilder // Java 1.5+
+ val s1 = new StringBuilder
+ j1 insert (0, "###") insert (0, Array('0', '1', '2')) insert (0, "xyz".subSequence(0, 3))
+ s1 insert (0, "###") insert (0, Array('0', '1', '2')) insert (0, List('x', 'y', 'z'))
//println("j1="+j1+", s1="+s1)//debug
assertEquals("s1.toString equals j1.toString", true, s1.toString equals j1.toString)
+
}
}