diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-12-12 07:57:40 -0800 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-12-12 07:57:40 -0800 |
commit | 73cddba169a3b1fc1519a6128275dddceec3299a (patch) | |
tree | 13348d04fc2be20eff5bb9d2ee5ddaaaf8cef5d3 /src/reflect | |
parent | 2b686791f08389900b0bd9d96a7aba8cf2b9f53d (diff) | |
parent | 30f779b4d9b699800e323eeba31cf04c16b4fbcd (diff) | |
download | scala-73cddba169a3b1fc1519a6128275dddceec3299a.tar.gz scala-73cddba169a3b1fc1519a6128275dddceec3299a.tar.bz2 scala-73cddba169a3b1fc1519a6128275dddceec3299a.zip |
Merge pull request #3218 from som-snytt/issue/8027-repl-dbltab
SI-8027 REPL double tab regression
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/scala/reflect/internal/util/StringOps.scala | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/reflect/scala/reflect/internal/util/StringOps.scala b/src/reflect/scala/reflect/internal/util/StringOps.scala index 14f349f502..efb8126ff0 100644 --- a/src/reflect/scala/reflect/internal/util/StringOps.scala +++ b/src/reflect/scala/reflect/internal/util/StringOps.scala @@ -23,12 +23,16 @@ trait StringOps { def oempty(xs: String*) = xs filterNot (x => x == null || x == "") def ojoin(xs: String*): String = oempty(xs: _*) mkString " " def longestCommonPrefix(xs: List[String]): String = xs match { - case Nil => "" - case xs if xs contains "" => "" - case x :: xs => - val ch = x charAt 0 - if (xs exists (_.head != ch)) "" - else "" + ch + longestCommonPrefix(xs map (_ substring 1)) + case Nil => "" + case w :: Nil => w + case _ => + def lcp(ss: List[String]): String = { + val w :: ws = ss + if (w == "") "" + else if (ws exists (s => s == "" || (s charAt 0) != (w charAt 0))) "" + else w.substring(0, 1) + lcp(ss map (_ substring 1)) + } + lcp(xs) } /** Like String#trim, but trailing whitespace only. */ |