/** * Returns the number of matching characters, zero for no match. * <p> * This method is called to check for a match. * The parameter <code>pos</code> represents the current position to be * checked in the string <code>buffer</code> (a character array which must * not be changed). * The API guarantees that <code>pos</code> is a valid index for <code>buffer</code>. * <p> * The matching code may check one character or many. * It may check characters preceeding <code>pos</code> as well as those after. * <p> * It must return zero for no match, or a positive number if a match was found. * The number indicates the number of characters that matched. * * @param buffer the text content to match against, do not change * @param pos the starting position for the match, valid for buffer * @return the number of matching characters, zero for no match * @since 2.4 */ public int isMatch(char[] buffer, int pos) { return isMatch(buffer, pos, 0, buffer.length); }
/** * Searches the string builder using the matcher to find the first * match searching from the given index. * <p> * Matchers can be used to perform advanced searching behaviour. * For example you could write a matcher to find the character 'a' * followed by a number. * * @param matcher the matcher to use, null returns -1 * @param startIndex the index to start at, invalid index rounded to edge * @return the first index matched, or -1 if not found */ public int indexOf(StrMatcher matcher, int startIndex) { startIndex = (startIndex < 0 ? 0 : startIndex); if (matcher == null || startIndex >= size) { return -1; } int len = size; char[] buf = buffer; for (int i = startIndex; i < len; i++) { if (matcher.isMatch(buf, i, startIndex, len) > 0) { return i; } } return -1; }
/** * Searches the string builder using the matcher to find the last * match searching from the given index. * <p> * Matchers can be used to perform advanced searching behaviour. * For example you could write a matcher to find the character 'a' * followed by a number. * * @param matcher the matcher to use, null returns -1 * @param startIndex the index to start at, invalid index rounded to edge * @return the last index matched, or -1 if not found */ public int lastIndexOf(StrMatcher matcher, int startIndex) { startIndex = (startIndex >= size ? size - 1 : startIndex); if (matcher == null || startIndex < 0) { return -1; } char[] buf = buffer; int endIndex = startIndex + 1; for (int i = startIndex; i >= 0; i--) { if (matcher.isMatch(buf, i, 0, endIndex) > 0) { return i; } } return -1; }
/** * Consume whitespace from the current parse position. * * @param pattern String to read * @param pos current position */ private void seekNonWs(String pattern, ParsePosition pos) { int len = 0; char[] buffer = pattern.toCharArray(); do { len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); }
char[] buf = buffer; for (int i = from; i < to && replaceCount != 0; i++) { int removeLen = matcher.isMatch(buf, i, from, to); if (removeLen > 0) { replaceImpl(i, i + removeLen, removeLen, replaceStr, replaceLen);
getIgnoredMatcher().isMatch(chars, start, start, len), getTrimmerMatcher().isMatch(chars, start, start, len)); if (removeLen == 0 || getDelimiterMatcher().isMatch(chars, start, start, len) > 0 || getQuoteMatcher().isMatch(chars, start, start, len) > 0) { break; int delimLen = getDelimiterMatcher().isMatch(chars, start, start, len); if (delimLen > 0) { addToken(tokens, ""); int quoteLen = getQuoteMatcher().isMatch(chars, start, start, len); if (quoteLen > 0) { return readWithQuotes(chars, start + quoteLen, len, workArea, tokens, start, quoteLen);
int pos = offset; while (pos < bufEnd) { int startMatchLen = prefixMatcher.isMatch(chars, pos, offset, bufEnd); if (startMatchLen == 0) { while (pos < bufEnd) { if (isEnableSubstitutionInVariables() && (endMatchLen = prefixMatcher.isMatch(chars, pos, offset, bufEnd)) != 0) { endMatchLen = suffixMatcher.isMatch(chars, pos, offset, bufEnd); if (endMatchLen == 0) {
int delimLen = getDelimiterMatcher().isMatch(chars, pos, start, len); if (delimLen > 0) { int ignoredLen = getIgnoredMatcher().isMatch(chars, pos, start, len); if (ignoredLen > 0) { pos += ignoredLen; int trimmedLen = getTrimmerMatcher().isMatch(chars, pos, start, len); if (trimmedLen > 0) { workArea.append(chars, pos, trimmedLen);
private int consumeDelimiters(char[] chars, int start, int delim) { while (delim > 0 && start < chars.length - delim) { start += delim; delim = delimiterMatcher.isMatch(chars, start); } return start; }
/** * Returns the number of matching characters, zero for no match. * <p> * This method is called to check for a match. * The parameter <code>pos</code> represents the current position to be * checked in the string <code>buffer</code> (a character array which must * not be changed). * The API guarantees that <code>pos</code> is a valid index for <code>buffer</code>. * <p> * The matching code may check one character or many. * It may check characters preceeding <code>pos</code> as well as those after. * <p> * It must return zero for no match, or a positive number if a match was found. * The number indicates the number of characters that matched. * * @param buffer the text content to match against, do not change * @param pos the starting position for the match, valid for buffer * @return the number of matching characters, zero for no match * @since 2.4 */ public int isMatch(char[] buffer, int pos) { return isMatch(buffer, pos, 0, buffer.length); }
/** * Returns the number of matching characters, zero for no match. * <p> * This method is called to check for a match. * The parameter <code>pos</code> represents the current position to be * checked in the string <code>buffer</code> (a character array which must * not be changed). * The API guarantees that <code>pos</code> is a valid index for <code>buffer</code>. * <p> * The matching code may check one character or many. * It may check characters preceeding <code>pos</code> as well as those after. * <p> * It must return zero for no match, or a positive number if a match was found. * The number indicates the number of characters that matched. * * @param buffer the text content to match against, do not change * @param pos the starting position for the match, valid for buffer * @return the number of matching characters, zero for no match * @since 2.4 */ public int isMatch(char[] buffer, int pos) { return isMatch(buffer, pos, 0, buffer.length); }
/** * Returns the number of matching characters, zero for no match. * <p> * This method is called to check for a match. * The parameter <code>pos</code> represents the current position to be * checked in the string <code>buffer</code> (a character array which must * not be changed). * The API guarantees that <code>pos</code> is a valid index for <code>buffer</code>. * <p> * The matching code may check one character or many. * It may check characters preceeding <code>pos</code> as well as those after. * <p> * It must return zero for no match, or a positive number if a match was found. * The number indicates the number of characters that matched. * * @param buffer the text content to match against, do not change * @param pos the starting position for the match, valid for buffer * @return the number of matching characters, zero for no match * @since 2.4 */ public int isMatch(char[] buffer, int pos) { return isMatch(buffer, pos, 0, buffer.length); }
/** * Returns the number of matching characters, zero for no match. * <p> * This method is called to check for a match. * The parameter <code>pos</code> represents the current position to be * checked in the string <code>buffer</code> (a character array which must * not be changed). * The API guarantees that <code>pos</code> is a valid index for <code>buffer</code>. * <p> * The matching code may check one character or many. * It may check characters preceeding <code>pos</code> as well as those after. * <p> * It must return zero for no match, or a positive number if a match was found. * The number indicates the number of characters that matched. * * @param buffer the text content to match against, do not change * @param pos the starting position for the match, valid for buffer * @return the number of matching characters, zero for no match * @since 2.4 */ public int isMatch(char[] buffer, int pos) { return isMatch(buffer, pos, 0, buffer.length); }
/** * Returns the number of matching characters, zero for no match. * <p> * This method is called to check for a match. * The parameter <code>pos</code> represents the current position to be * checked in the string <code>buffer</code> (a character array which must * not be changed). * The API guarantees that <code>pos</code> is a valid index for <code>buffer</code>. * <p> * The matching code may check one character or many. * It may check characters preceeding <code>pos</code> as well as those after. * <p> * It must return zero for no match, or a positive number if a match was found. * The number indicates the number of characters that matched. * * @param buffer the text content to match against, do not change * @param pos the starting position for the match, valid for buffer * @return the number of matching characters, zero for no match * @since 2.4 */ public int isMatch(char[] buffer, int pos) { return isMatch(buffer, pos, 0, buffer.length); }
/** * Consume whitespace from the current parse position. * * @param pattern String to read * @param pos current position */ private void seekNonWs(String pattern, ParsePosition pos) { int len = 0; char[] buffer = pattern.toCharArray(); do { len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); }
/** * Consume whitespace from the current parse position. * * @param pattern String to read * @param pos current position */ private void seekNonWs(String pattern, ParsePosition pos) { int len = 0; char[] buffer = pattern.toCharArray(); do { len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); }
/** * Consume whitespace from the current parse position. * * @param pattern String to read * @param pos current position */ private void seekNonWs(String pattern, ParsePosition pos) { int len = 0; char[] buffer = pattern.toCharArray(); do { len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); }
/** * Consume whitespace from the current parse position. * * @param pattern String to read * @param pos current position */ private void seekNonWs(String pattern, ParsePosition pos) { int len = 0; char[] buffer = pattern.toCharArray(); do { len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); }
/** * Consume whitespace from the current parse position. * * @param pattern String to read * @param pos current position */ private void seekNonWs(String pattern, ParsePosition pos) { int len = 0; char[] buffer = pattern.toCharArray(); do { len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); }
private int readNextToken(char[] chars, int pos, Collection<String> tokens) { if (pos >= chars.length) { return -1; } int ws = whitespaceMatcher.isMatch(chars, pos); if (ws > 0) { pos += ws; } if (pos >= chars.length) { return -1; } int delim = delimiterMatcher.isMatch(chars, pos); if (delim > 0) { if (quashDelimiters) { pos = consumeDelimiters(chars, pos, delim); } else { addToken(buffer, ""); return pos + delim; } } int quote = quoteMatcher.isMatch(chars, pos); return readQuotedToken(chars, pos, tokens, quote); }