/** * Resets this matcher. * * <p> Resetting a matcher discards all of its explicit state information * and sets its append position to zero. The matcher's region is set to the * default region, which is its entire character sequence. The anchoring * and transparency of this matcher's region boundaries are unaffected. * * @return This matcher */ public Matcher reset() { first = -1; last = 0; oldLast = -1; for(int i=0; i<groups.length; i++) groups[i] = -1; for(int i=0; i<locals.length; i++) locals[i] = -1; lastAppendPosition = 0; from = 0; to = getTextLength(); return this; }
/** * Resets this matcher. * * <p> Resetting a matcher discards all of its explicit state information * and sets its append position to zero. The matcher's region is set to the * default region, which is its entire character sequence. The anchoring * and transparency of this matcher's region boundaries are unaffected. * * @return This matcher */ public Matcher reset() { first = -1; last = 0; oldLast = -1; for(int i=0; i<groups.length; i++) groups[i] = -1; for(int i=0; i<locals.length; i++) locals[i] = -1; lastAppendPosition = 0; from = 0; to = getTextLength(); return this; }
Exception in thread "main" java.lang.NullPointerException at java.util.regex.Matcher.getTextLength(Matcher.java:1140) at java.util.regex.Matcher.reset(Matcher.java:291) at java.util.regex.Matcher.<init>(Matcher.java:211) at java.util.regex.Pattern.matcher(Pattern.java:888) Java Result: 1
/** * Implements a terminal append-and-replace step. * * <p> This method reads characters from the input sequence, starting at * the append position, and appends them to the given string buffer. It is * intended to be invoked after one or more invocations of the {@link * #appendReplacement appendReplacement} method in order to copy the * remainder of the input sequence. </p> * * @param sb * The target string buffer * * @return The target string buffer */ public StringBuffer appendTail(StringBuffer sb) { sb.append(text, lastAppendPosition, getTextLength()); return sb; }
/** * Implements a terminal append-and-replace step. * * <p> This method reads characters from the input sequence, starting at * the append position, and appends them to the given string buffer. It is * intended to be invoked after one or more invocations of the {@link * #appendReplacement appendReplacement} method in order to copy the * remainder of the input sequence. </p> * * @param sb * The target string buffer * * @return The target string buffer */ public StringBuffer appendTail(StringBuffer sb) { sb.append(text, lastAppendPosition, getTextLength()); return sb; }
boolean match(Matcher matcher, int i, CharSequence seq) { int endIndex = (matcher.anchoringBounds) ? matcher.to : matcher.getTextLength(); if (i == endIndex) { matcher.hitEnd = true; return next.match(matcher, i, seq); } return false; } }
boolean match(Matcher matcher, int i, CharSequence seq) { int endIndex = (matcher.anchoringBounds) ? matcher.to : matcher.getTextLength(); if (i == endIndex) { matcher.hitEnd = true; return next.match(matcher, i, seq); } return false; } }
boolean match(Matcher matcher, int i, CharSequence seq) { int startIndex = matcher.from; int endIndex = matcher.to; if (!matcher.anchoringBounds) { startIndex = 0; endIndex = matcher.getTextLength(); } // Perl does not match ^ at end of input even after newline if (i == endIndex) { matcher.hitEnd = true; return false; } if (i > startIndex) { char ch = seq.charAt(i-1); if (ch != '\n') { return false; } } return next.match(matcher, i, seq); } }
/** * Resets this matcher and then attempts to find the next subsequence of * the input sequence that matches the pattern, starting at the specified * index. * * <p> If the match succeeds then more information can be obtained via the * <tt>start</tt>, <tt>end</tt>, and <tt>group</tt> methods, and subsequent * invocations of the {@link #find()} method will start at the first * character not matched by this match. </p> * * @throws IndexOutOfBoundsException * If start is less than zero or if start is greater than the * length of the input sequence. * * @return <tt>true</tt> if, and only if, a subsequence of the input * sequence starting at the given index matches this matcher's * pattern */ public boolean find(int start) { int limit = getTextLength(); if ((start < 0) || (start > limit)) throw new IndexOutOfBoundsException("Illegal start index"); reset(); return search(start); }
boolean match(Matcher matcher, int i, CharSequence seq) { int startIndex = matcher.from; int endIndex = matcher.to; if (!matcher.anchoringBounds) { startIndex = 0; endIndex = matcher.getTextLength(); } // Perl does not match ^ at end of input even after newline if (i == endIndex) { matcher.hitEnd = true; return false; } if (i > startIndex) { char ch = seq.charAt(i-1); if (ch != '\n' && ch != '\r' && (ch|1) != '\u2029' && ch != '\u0085' ) { return false; } // Should treat /r/n as one newline if (ch == '\r' && seq.charAt(i) == '\n') return false; } return next.match(matcher, i, seq); } }
boolean match(Matcher matcher, int i, CharSequence seq) { int startIndex = matcher.from; int endIndex = matcher.to; if (!matcher.anchoringBounds) { startIndex = 0; endIndex = matcher.getTextLength(); } // Perl does not match ^ at end of input even after newline if (i == endIndex) { matcher.hitEnd = true; return false; } if (i > startIndex) { char ch = seq.charAt(i-1); if (ch != '\n') { return false; } } return next.match(matcher, i, seq); } }
boolean match(Matcher matcher, int i, CharSequence seq) { int startIndex = matcher.from; int endIndex = matcher.to; if (!matcher.anchoringBounds) { startIndex = 0; endIndex = matcher.getTextLength(); } // Perl does not match ^ at end of input even after newline if (i == endIndex) { matcher.hitEnd = true; return false; } if (i > startIndex) { char ch = seq.charAt(i-1); if (ch != '\n' && ch != '\r' && (ch|1) != '\u2029' && ch != '\u0085' ) { return false; } // Should treat /r/n as one newline if (ch == '\r' && seq.charAt(i) == '\n') return false; } return next.match(matcher, i, seq); } }
/** * Resets this matcher and then attempts to find the next subsequence of * the input sequence that matches the pattern, starting at the specified * index. * * <p> If the match succeeds then more information can be obtained via the * <tt>start</tt>, <tt>end</tt>, and <tt>group</tt> methods, and subsequent * invocations of the {@link #find()} method will start at the first * character not matched by this match. </p> * * @throws IndexOutOfBoundsException * If start is less than zero or if start is greater than the * length of the input sequence. * * @return <tt>true</tt> if, and only if, a subsequence of the input * sequence starting at the given index matches this matcher's * pattern */ public boolean find(int start) { int limit = getTextLength(); if ((start < 0) || (start > limit)) throw new IndexOutOfBoundsException("Illegal start index"); reset(); return search(start); }
boolean match(Matcher matcher, int i, CharSequence seq) { int savedTo = matcher.to; boolean conditionMatched = false; // Relax transparent region boundaries for lookahead if (matcher.transparentBounds) matcher.to = matcher.getTextLength(); try { conditionMatched = cond.match(matcher, i, seq); } finally { // Reinstate region boundaries matcher.to = savedTo; } return conditionMatched && next.match(matcher, i, seq); } }
boolean match(Matcher matcher, int i, CharSequence seq) { int savedTo = matcher.to; boolean conditionMatched = false; // Relax transparent region boundaries for lookahead if (matcher.transparentBounds) matcher.to = matcher.getTextLength(); try { conditionMatched = cond.match(matcher, i, seq); } finally { // Reinstate region boundaries matcher.to = savedTo; } return conditionMatched && next.match(matcher, i, seq); } }
boolean match(Matcher matcher, int i, CharSequence seq) { int endIndex = (matcher.anchoringBounds) ? matcher.to : matcher.getTextLength(); if (i < endIndex) { char ch = seq.charAt(i); if (ch == '\n') { // If not multiline, then only possible to // match at very end or one before end if (multiline == false && i != endIndex - 1) return false; // If multiline return next.match without setting // matcher.hitEnd if (multiline) return next.match(matcher, i, seq); } else { return false; } } // Matching because at the end or 1 before the end; // more input could change this so set hitEnd matcher.hitEnd = true; // If a $ matches because of end of input, then more input // could cause it to fail! matcher.requireEnd = true; return next.match(matcher, i, seq); } boolean study(TreeInfo info) {
boolean match(Matcher matcher, int i, CharSequence seq) { int endIndex = (matcher.anchoringBounds) ? matcher.to : matcher.getTextLength(); if (i < endIndex) { char ch = seq.charAt(i); if (ch == '\n') { // If not multiline, then only possible to // match at very end or one before end if (multiline == false && i != endIndex - 1) return false; // If multiline return next.match without setting // matcher.hitEnd if (multiline) return next.match(matcher, i, seq); } else { return false; } } // Matching because at the end or 1 before the end; // more input could change this so set hitEnd matcher.hitEnd = true; // If a $ matches because of end of input, then more input // could cause it to fail! matcher.requireEnd = true; return next.match(matcher, i, seq); } boolean study(TreeInfo info) {
int check(Matcher matcher, int i, CharSequence seq) { int ch; boolean left = false; int startIndex = matcher.from; int endIndex = matcher.to; if (matcher.transparentBounds) { startIndex = 0; endIndex = matcher.getTextLength(); } if (i > startIndex) { ch = Character.codePointBefore(seq, i); left = (isWord(ch) || ((Character.getType(ch) == Character.NON_SPACING_MARK) && hasBaseCharacter(matcher, i-1, seq))); } boolean right = false; if (i < endIndex) { ch = Character.codePointAt(seq, i); right = (isWord(ch) || ((Character.getType(ch) == Character.NON_SPACING_MARK) && hasBaseCharacter(matcher, i, seq))); } else { // Tried to access char past the end matcher.hitEnd = true; // The addition of another char could wreck a boundary matcher.requireEnd = true; } return ((left ^ right) ? (right ? LEFT : RIGHT) : NONE); } boolean match(Matcher matcher, int i, CharSequence seq) {
boolean match(Matcher matcher, int i, CharSequence seq) { int savedTo = matcher.to; boolean conditionMatched = false; // Relax transparent region boundaries for lookahead if (matcher.transparentBounds) matcher.to = matcher.getTextLength(); try { if (i < matcher.to) { conditionMatched = !cond.match(matcher, i, seq); } else { // If a negative lookahead succeeds then more input // could cause it to fail! matcher.requireEnd = true; conditionMatched = !cond.match(matcher, i, seq); } } finally { // Reinstate region boundaries matcher.to = savedTo; } return conditionMatched && next.match(matcher, i, seq); } }
boolean match(Matcher matcher, int i, CharSequence seq) { int savedTo = matcher.to; boolean conditionMatched = false; // Relax transparent region boundaries for lookahead if (matcher.transparentBounds) matcher.to = matcher.getTextLength(); try { if (i < matcher.to) { conditionMatched = !cond.match(matcher, i, seq); } else { // If a negative lookahead succeeds then more input // could cause it to fail! matcher.requireEnd = true; conditionMatched = !cond.match(matcher, i, seq); } } finally { // Reinstate region boundaries matcher.to = savedTo; } return conditionMatched && next.match(matcher, i, seq); } }