Browse files

SI-8107: Use Regex.quote

  • Loading branch information...
1 parent 780ceca commit 2fe767806b44aea3f6f53735301b11fd2ffae08b @qerub qerub committed Dec 29, 2013
View
4 src/library/scala/Enumeration.scala
@@ -11,7 +11,7 @@ package scala
import scala.collection.{ mutable, immutable, generic, SortedSetLike, AbstractSet }
import java.lang.reflect.{ Modifier, Method => JMethod, Field => JField }
import scala.reflect.NameTransformer._
-import java.util.regex.Pattern
+import scala.util.matching.Regex
/** Defines a finite set of values specific to the enumeration. Typically
* these values enumerate all possible forms something can take and provide
@@ -64,7 +64,7 @@ abstract class Enumeration (initial: Int) extends Serializable {
*/
override def toString =
((getClass.getName stripSuffix MODULE_SUFFIX_STRING split '.').last split
- Pattern.quote(NAME_JOIN_STRING)).last
+ Regex.quote(NAME_JOIN_STRING)).last
/** The mapping from the integer used to identify values to the actual
* values. */
View
4 src/library/scala/collection/immutable/StringLike.scala
@@ -164,8 +164,8 @@ self =>
* @return the resulting string
*/
def replaceAllLiterally(literal: String, replacement: String): String = {
- val arg1 = java.util.regex.Pattern.quote(literal)
- val arg2 = java.util.regex.Matcher.quoteReplacement(replacement)
+ val arg1 = Regex.quote(literal)
+ val arg2 = Regex.quoteReplacement(replacement)
toString.replaceAll(arg1, arg2)
}
View
6 src/repl/scala/tools/nsc/interpreter/JavapClass.scala
@@ -11,7 +11,6 @@ import java.lang.{ ClassLoader => JavaClassLoader, Iterable => JIterable }
import scala.tools.nsc.util.ScalaClassLoader
import java.io.{ ByteArrayInputStream, CharArrayWriter, FileNotFoundException, PrintWriter, Writer }
import java.util.{ Locale }
-import java.util.regex.Pattern
import java.util.concurrent.ConcurrentLinkedQueue
import javax.tools.{ Diagnostic, DiagnosticCollector, DiagnosticListener,
ForwardingJavaFileManager, JavaFileManager, JavaFileObject,
@@ -20,6 +19,7 @@ import scala.reflect.io.{ AbstractFile, Directory, File, Path }
import scala.io.Source
import scala.util.{ Try, Success, Failure }
import scala.util.Properties.lineSeparator
+import scala.util.matching.Regex
import scala.collection.JavaConverters
import scala.collection.generic.Clearable
import java.net.URL
@@ -608,12 +608,12 @@ object JavapClass {
// class k, candidate f without prefix
def isFunOfClass(k: String, f: String) = {
- val p = (s"${Pattern quote k}\\$$+anonfun").r
+ val p = (s"${Regex quote k}\\$$+anonfun").r
(p findPrefixOf f).nonEmpty
}
// class k, candidate f without prefix, method m
def isFunOfMethod(k: String, m: String, f: String) = {
- val p = (s"${Pattern quote k}\\$$+anonfun\\$$${Pattern quote m}\\$$").r
+ val p = (s"${Regex quote k}\\$$+anonfun\\$$${Regex quote m}\\$$").r
(p findPrefixOf f).nonEmpty
}
def isFunOfTarget(k: String, m: Option[String], f: String) =
View
7 src/repl/scala/tools/nsc/interpreter/Naming.scala
@@ -8,6 +8,7 @@ package tools.nsc
package interpreter
import scala.util.Properties.lineSeparator
+import scala.util.matching.Regex
/** This is for name logic which is independent of the compiler (notice there's no Global.)
* That includes at least generating, metaquoting, mangling, and unmangling.
@@ -38,12 +39,10 @@ trait Naming {
//
// $line3.$read.$iw.$iw.Bippy =
// $line3.$read$$iw$$iw$Bippy@4a6a00ca
-
- private def noMeta(s: String) = "\\Q" + s + "\\E"
lazy val lineRegex = {
val sn = sessionNames
- val members = List(sn.read, sn.eval, sn.print) map noMeta mkString ("(?:", "|", ")")
- debugging("lineRegex")(noMeta(sn.line) + """\d+[./]""" + members + """[$.]""")
+ val members = List(sn.read, sn.eval, sn.print) map Regex.quote mkString ("(?:", "|", ")")
+ debugging("lineRegex")(Regex.quote(sn.line) + """\d+[./]""" + members + """[$.]""")
}
private def removeLineWrapper(s: String) = s.replaceAll(lineRegex, "")

0 comments on commit 2fe7678

Please sign in to comment.