diff options
author | michelou <michelou@epfl.ch> | 2008-02-26 20:19:52 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2008-02-26 20:19:52 +0000 |
commit | 8c86276228df700d65dc035bff84e0b73be6b016 (patch) | |
tree | c3f8dc016d460362b96110ad7febfbf3e6a18cd6 /src/cldc-library | |
parent | 79740bedb4742546027c931926b339834b5fac6c (diff) | |
download | scala-8c86276228df700d65dc035bff84e0b73be6b016.tar.gz scala-8c86276228df700d65dc035bff84e0b73be6b016.tar.bz2 scala-8c86276228df700d65dc035bff84e0b73be6b016.zip |
updated RichString on dotnet/cldc
Diffstat (limited to 'src/cldc-library')
-rw-r--r-- | src/cldc-library/scala/runtime/RichString.scala | 43 |
1 files changed, 33 insertions, 10 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\"") } |