summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cldc-library/scala/runtime/RichString.scala43
-rw-r--r--src/dotnet-library/scala/runtime/RichString.scala52
-rw-r--r--src/library/scala/runtime/RichString.scala6
3 files changed, 72 insertions, 29 deletions
diff --git a/src/cldc-library/scala/runtime/RichString.scala b/src/cldc-library/scala/runtime/RichString.scala
index baee912802..40e208246d 100644
--- a/src/cldc-library/scala/runtime/RichString.scala
+++ b/src/cldc-library/scala/runtime/RichString.scala
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
+** / __/ __// _ | / / / _ | (c) 2002-2008, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
@@ -64,6 +64,16 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
case that => super.containsSlice(that)
}
+ override def reverse: RichString = {
+ val buf = new StringBuilder
+ var i = self.length - 1
+ while (i >= 0) {
+ buf append (self charAt i)
+ i -= 1
+ }
+ new RichString(buf.toString)
+ }
+
override def compare(other: String) = self compareTo other
private def isLineBreak(c: Char) = c == LF || c == FF
@@ -128,11 +138,14 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
linesWithSeparators map (line => new RichString(line).stripLineEnd)
/** Returns this string with first character converted to upper case */
- def capitalize: String = {
- val chars = self.toCharArray
- chars(0) = chars(0).toUpperCase
- new String(chars)
- }
+ def capitalize: String =
+ if (self == null) null
+ else if (self.length == 0) ""
+ else {
+ val chars = self.toCharArray
+ chars(0) = chars(0).toUpperCase
+ new String(chars)
+ }
/** <p>
* For every line in this string:
@@ -178,10 +191,11 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
self.split(re)
}
*/
- def toByte: Byte = java.lang.Byte.parseByte(self)
- def toShort: Short = java.lang.Short.parseShort(self)
- def toInt: Int = java.lang.Integer.parseInt(self)
- def toLong: Long = java.lang.Long.parseLong(self)
+ def toBoolean: Boolean = parseBoolean(self)
+ def toByte: Byte = java.lang.Byte.parseByte(self)
+ def toShort: Short = java.lang.Short.parseShort(self)
+ def toInt: Int = java.lang.Integer.parseInt(self)
+ def toLong: Long = java.lang.Long.parseLong(self)
//def toFloat: Float = java.lang.Float.parseFloat(self)
//def toDouble: Double = java.lang.Double.parseDouble(self)
}
@@ -192,5 +206,14 @@ object RichString {
private final val FF: Char = 0x0C
private final val CR: Char = 0x0D
private final val SU: Char = 0x1A
+
+ private def parseBoolean(s: String): Boolean =
+ if (s != null) s.toLowerCase match {
+ case "true" => true
+ case "false" => false
+ case _ => throw new NumberFormatException("For input string: \""+s+"\"")
+ }
+ else
+ throw new NumberFormatException("For input string: \"null\"")
}
diff --git a/src/dotnet-library/scala/runtime/RichString.scala b/src/dotnet-library/scala/runtime/RichString.scala
index 150edc000e..d94f7430c0 100644
--- a/src/dotnet-library/scala/runtime/RichString.scala
+++ b/src/dotnet-library/scala/runtime/RichString.scala
@@ -21,10 +21,16 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
override def mkString = self
override def slice(from: Int, until: Int): RichString = {
- val from0 = if (from < 0) 0 else from
- val until0 = if (from >= until || from >= self.length) return new RichString("")
- else if (until > self.length) self.length else until
- new RichString(self.substring(from0, until0))
+ val len = self.length
+ new RichString(
+ if (from >= until || from >= len)
+ ""
+ else {
+ val from0 = if (from < 0) 0 else from
+ val until0 = if (until > len) len else until
+ self.substring(from0, until0)
+ }
+ )
}
//override def ++ [B >: A](that: Iterable[B]): Seq[B] = {
@@ -57,6 +63,16 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
case that => super.containsSlice(that)
}
+ override def reverse: RichString = {
+ val buf = new StringBuilder
+ var i = self.length - 1
+ while (i >= 0) {
+ buf append (self charAt i)
+ i -= 1
+ }
+ new RichString(buf.toString)
+ }
+
override def compare(other: String) = self compareTo other
private final val LF: Char = 0x0A
@@ -126,11 +142,14 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
linesWithSeparators map (line => new RichString(line).stripLineEnd)
/** Returns this string with first character converted to upper case */
- def capitalize: String = {
- val chars = self.toCharArray
- chars(0) = chars(0).toUpperCase
- new String(chars)
- }
+ def capitalize: String =
+ if (self == null) null
+ else if (self.length == 0) ""
+ else {
+ val chars = self.toCharArray
+ chars(0) = chars(0).toUpperCase
+ new String(chars)
+ }
/** <p>
* For every line in this string:
@@ -141,7 +160,7 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
* </blockquote>
*/
def stripMargin(marginChar: Char): String = {
- val buf = new StringBuilder()
+ val buf = new StringBuilder
for (line <- linesWithSeparators) {
val len = line.length
var index = 0
@@ -166,11 +185,12 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
def split(separators: Array[Char]): Array[String] = self.Split(separators)
- def toByte: Byte = System.Byte.Parse(self)
- def toShort: Short = System.Int16.Parse(self)
- def toInt: Int = System.Int32.Parse(self)
- def toLong: Long = System.Int64.Parse(self)
- def toFloat: Float = System.Single.Parse(self)
- def toDouble: Double = System.Double.Parse(self)
+ def toBoolean: Boolean = System.Boolean.Parse(self)
+ def toByte: Byte = System.Byte.Parse(self)
+ def toShort: Short = System.Int16.Parse(self)
+ def toInt: Int = System.Int32.Parse(self)
+ def toLong: Long = System.Int64.Parse(self)
+ def toFloat: Float = System.Single.Parse(self)
+ def toDouble: Double = System.Double.Parse(self)
}
diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala
index de6e4bdbd9..afd80afb66 100644
--- a/src/library/scala/runtime/RichString.scala
+++ b/src/library/scala/runtime/RichString.scala
@@ -65,11 +65,11 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
}
override def reverse: RichString = {
- val buf = new StringBuffer
+ val buf = new StringBuilder
var i = self.length - 1
while (i >= 0) {
buf append (self charAt i)
- i = i - 1
+ i -= 1
}
new RichString(buf.toString)
}
@@ -156,7 +156,7 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
* </blockquote>
*/
def stripMargin(marginChar: Char): String = {
- val buf = new StringBuilder()
+ val buf = new StringBuilder
for (line <- linesWithSeparators) {
val len = line.length
var index = 0