aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/java/util/regex/Matcher.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gandalf@gcc.gnu.org>2012-03-23 15:19:26 +0000
committerAndrew John Hughes <gandalf@gcc.gnu.org>2012-03-23 15:19:26 +0000
commit0563022a206294757effa44686727bffc4f7c2bd (patch)
treefebe3d4d4c0c994db223fee8e819bde6582494c9 /libjava/classpath/java/util/regex/Matcher.java
parent21669dfe20db0246ece395db5558a081a5c7088f (diff)
downloadgcc-0563022a206294757effa44686727bffc4f7c2bd.zip
gcc-0563022a206294757effa44686727bffc4f7c2bd.tar.gz
gcc-0563022a206294757effa44686727bffc4f7c2bd.tar.bz2
Merge GNU Classpath 0.99 into libjava.
From-SVN: r185741
Diffstat (limited to 'libjava/classpath/java/util/regex/Matcher.java')
-rw-r--r--libjava/classpath/java/util/regex/Matcher.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/libjava/classpath/java/util/regex/Matcher.java b/libjava/classpath/java/util/regex/Matcher.java
index be57471..8d033d5 100644
--- a/libjava/classpath/java/util/regex/Matcher.java
+++ b/libjava/classpath/java/util/regex/Matcher.java
@@ -169,6 +169,12 @@ public final class Matcher implements MatchResult
if (match != null)
{
int endIndex = match.getEndIndex();
+ // Is the match within input limits?
+ if (endIndex > input.length())
+ {
+ match = null;
+ return false;
+ }
// Are we stuck at the same position?
if (!first && endIndex == position)
{
@@ -608,4 +614,27 @@ public final class Matcher implements MatchResult
return snapshot;
}
+ /**
+ * Returns a literalized string of s where characters {@code $} and {@code
+ * \\} are escaped.
+ *
+ * @param s the string to literalize.
+ * @return the literalized string.
+ * @since 1.5
+ */
+ public static String quoteReplacement(String s)
+ {
+ if (s == null)
+ throw new NullPointerException();
+ CPStringBuilder sb = new CPStringBuilder();
+ for (int i = 0; i < s.length(); i++)
+ {
+ char ch = s.charAt(i);
+ if (ch == '$' || ch == '\\')
+ sb.append('\\');
+ sb.append(ch);
+ }
+ return sb.toString();
+ }
+
}