diff options
author | Paul Phillips <paulp@improving.org> | 2011-05-31 05:08:07 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-05-31 05:08:07 +0000 |
commit | 35f7c2bde563b501e9661aace1e1610990b51544 (patch) | |
tree | 8edd9b4f4fdbae46112f0d848230db2e49f7d55c /src/compiler/scala/tools/util/StringOps.scala | |
parent | 82eaeed3b1bf3d4e9a6b4c4dedfeed0e603e56e7 (diff) | |
download | scala-35f7c2bde563b501e9661aace1e1610990b51544.tar.gz scala-35f7c2bde563b501e9661aace1e1610990b51544.tar.bz2 scala-35f7c2bde563b501e9661aace1e1610990b51544.zip |
Moved some pure string manipulation functions o...
Moved some pure string manipulation functions out of the base class
for all Reporters and into a more suitable home. "Please, help stamp
out inheritance abuse. If you won't do it for yourself do it for your
children... or your subclass's children." Also removed some dead
reporter code (not used anywhere, including the IDE.) No review.
Diffstat (limited to 'src/compiler/scala/tools/util/StringOps.scala')
-rw-r--r-- | src/compiler/scala/tools/util/StringOps.scala | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/util/StringOps.scala b/src/compiler/scala/tools/util/StringOps.scala index 63cfc06702..65ff582011 100644 --- a/src/compiler/scala/tools/util/StringOps.scala +++ b/src/compiler/scala/tools/util/StringOps.scala @@ -16,7 +16,7 @@ package util * @author Martin Odersky * @version 1.0 */ -object StringOps { +trait StringOps { def onull(s: String) = if (s == null) "" else s def oempty(xs: String*) = xs filterNot (x => x == null || x == "") def ojoin(xs: Seq[String], sep: String) = oempty(xs: _*) mkString sep @@ -53,4 +53,37 @@ object StringOps { def splitAt(str: String, idx: Int, doDropIndex: Boolean = false): Option[(String, String)] = if (idx == -1) None else Some(str take idx, str drop (if (doDropIndex) idx + 1 else idx)) + + /** Returns a string meaning "n elements". + * + * @param n ... + * @param elements ... + * @return ... + */ + def countElementsAsString(n: Int, elements: String): String = + n match { + case 0 => "no " + elements + "s" + case 1 => "one " + elements + case 2 => "two " + elements + "s" + case 3 => "three " + elements + "s" + case 4 => "four " + elements + "s" + case _ => "" + n + " " + elements + "s" + } + + /** Turns a count into a friendly English description if n<=4. + * + * @param n ... + * @return ... + */ + def countAsString(n: Int): String = + n match { + case 0 => "none" + case 1 => "one" + case 2 => "two" + case 3 => "three" + case 4 => "four" + case _ => "" + n + } } + +object StringOps extends StringOps { } |