Skip to content

Commit

Permalink
just use Pattern.quote instead of sanitize
Browse files Browse the repository at this point in the history
  • Loading branch information
pathikrit committed Jun 3, 2014
1 parent cbb4225 commit 2a26dae
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@ package com.github.verbalexpressions

case class VerbalExpression(prefix: String = "", expression: String = "", suffix: String = "", modifiers: Int = 0) {
import java.util.regex.Pattern

private[this] def sanitize(value: String) = if(value == null) value else Pattern.quote(value)
import java.util.regex.Pattern.quote

def replace(source: String, value: String) = source.replaceAll(toString, value)

def add(value: String) = copy(expression = expression + value)

def andThen(value: String) = add(s"(${sanitize(value)})")
def andThen(value: String) = add(s"(${quote(value)})")

def then = andThen _

def find = andThen _

def maybe(value: String) = add(s"(${sanitize(value)})?")
def maybe(value: String) = add(s"(${quote(value)})?")

def anything = add("(.*)")

def anythingBut(value: String) = add(s"([^${sanitize(value)}]*)")
def anythingBut(value: String) = add(s"([^${quote(value)}]*)")

def something = add("(.+)")

def somethingBut(value: String) = add(s"([^${sanitize(value)}]+)")
def somethingBut(value: String) = add(s"([^${quote(value)}]+)")

def tab = add("\\t")

def word = add("\\w+")

def anyOf(value: String) = add(s"[${sanitize(value)}]")
def anyOf(value: String) = add(s"[${quote(value)}]")

def any = anyOf _

Expand Down Expand Up @@ -80,7 +79,7 @@ case class VerbalExpression(prefix: String = "", expression: String = "", suffix

def repeatPrevious(atleast: Int, atmost: Int) = ???

def multiple(value: String) = add(s"${sanitize(value)}+")
def multiple(value: String) = add(s"${quote(value)}+")

def beginCapture = add("(")

Expand Down

0 comments on commit 2a26dae

Please sign in to comment.