Package com.google.gwt.regexp.shared

Examples of com.google.gwt.regexp.shared.MatchResult


  public final boolean isValid(String value, ConstraintValidatorContext context) {
    if (value == null) {
      return true;
    }
    MatchResult match = pattern.exec(value);
    if (match == null) {
      return false;
    }
    // Must match the entire string
    return match.getGroup(0).length() == value.length();
  }
View Full Code Here


    /*
     * We must not forget to clear the lastIndex since it is a global regex, if
     * we don't it can lead to a false negative for matches.
     */
    regex.setLastIndex(0);
    MatchResult match = regex.exec(text);
    if (match == null || match.getGroup(0).isEmpty()) {
      return false;
    }
   
    do {
      int start = regex.getLastIndex() - match.getGroup(0).length();
      edges.add(start);
      edges.add(regex.getLastIndex());
      match = regex.exec(text);
    } while (match != null && !match.getGroup(0).isEmpty());

    // Handles the edge cases of matching at beginning or end of a line
    inMatch = true;
    if (edges.get(0) != 0) {
      inMatch = false;
View Full Code Here

   * Finds the next character which is not a mark or other character. Will
   * return column if the end of the line is reached or column is a non-mark or
   * other character.
   */
  public static int findNextCharacterInclusive(String text, int column) {
    MatchResult result = RegExpUtils.findMatchAfterIndex(
        UnicodeUtils.regexpNotMarkOrOtherExcludingTabAndNewline, text, column - 1);
    // if result is null, then it's likely we're at the \n (I think).
    return result == null ? column : result.getIndex();
  }
View Full Code Here

     */
    if (column + 1 >= text.length()) {
      return text.length() + 1;
    }

    MatchResult match = RegExpUtils.findMatchAfterIndex(
        UnicodeUtils.regexpNotMarkOrOtherExcludingTabAndNewline, text, column);
    if (match == null) {
      return text.length() + 1;
    } else {
      return match.getIndex();
    }
  }
View Full Code Here

   *
   * @returns true if match is found
   */
  private boolean selectNextMatchOnLine(LineInfo line, int startIndex, int endIndex) {
    searchPattern.setLastIndex(startIndex);
    MatchResult result = searchPattern.exec(line.line().getText());

    if (result == null || result.getIndex() >= endIndex) {
      return false;
    }

    moveAndSelectMatch(line, result.getIndex(), result.getGroup(0).length());
    return true;
  }
View Full Code Here

     */
    if (column - 1 < 0) {
      return -1;
    }

    MatchResult match = RegExpUtils.findMatchBeforeIndex(
        UnicodeUtils.regexpNotMarkOrOtherExcludingTabAndNewline, text, column);
    if (match == null) {
      return -1;
    } else {
      return match.getIndex();
    }
  }
View Full Code Here

  /**
   * Counts number of whitespaces at the beginning of line.
   */
  public static int countWhitespacesAtTheBeginningOfLine(String text) {
    MatchResult result = RegExpUtils.findMatchAfterIndex(
        UnicodeUtils.regexpNotWhitespaceExcludingNewlineAndCarriageReturn, text, -1);

    return result == null ? text.length() : result.getIndex();
  }
View Full Code Here

   */
  private boolean selectPreviousMatchOnLine(LineInfo line, int startIndex, int endIndex) {
    searchPattern.setLastIndex(0);

    // Find the last match without going over our startIndex
    MatchResult lastMatch = null;
    for (MatchResult result = searchPattern.exec(line.line().getText());
        result != null && result.getIndex() < endIndex && result.getIndex() >= startIndex;
        result = searchPattern.exec(line.line().getText())) {
      lastMatch = result;
    }

    if (lastMatch == null) {
      return false;
    }

    moveAndSelectMatch(line, lastMatch.getIndex(), lastMatch.getGroup(0).length());
    return true;
  }
View Full Code Here

   * findMatchAfterIndex or findMatchBeforeIndex. Once the result is obtained it
   * will return either the match index or the appropriate bound column
   * (text.length() or -1).
   */
  private static int directionalRegexp(boolean forward, RegExp regexp, String text, int column) {
    MatchResult result =
        forward ? RegExpUtils.findMatchAfterIndex(regexp, text, column)
            : RegExpUtils.findMatchBeforeIndex(regexp, text, column);
    int fallback = forward ? text.length() : -1;
    return result == null ? fallback : result.getIndex();
  }
View Full Code Here

     * is a special size. Rinse and repeat.
     */
    LineDimensionsUtils.markTimeline(getClass(), "Beginning measure line");
    RegExp regexp = UnicodeUtils.regexpNonAsciiTabOrCarriageReturn;
    regexp.setLastIndex(cache.measuredOffset.column);
    MatchResult result = regexp.exec(line.getText());

    if (result != null) {
      double x = 0;
      do {
        // Calculate any x offset up to this point in the line
        ColumnOffset offset = cache.getLastColumnOffsetInCache();
        double baseXOffset = smartColumnToX(offset, result.getIndex());

        /*
         * TODO: we can be smarter here, if i > 1, then this character
         * is a mark. We could separate out the RegExp into non-spacing,
         * enclosing-marks v. spacing-marks and already know which are supposed
         * to be zero-width based on which groups are null.
         */
        String match = result.getGroup(0);
        for (int i = 0; i < match.length(); i++) {
          x = addOffsetForResult(cache, match.charAt(i), result.getIndex() + i, line, baseXOffset);
          baseXOffset = x;
        }
        result = regexp.exec(line.getText());
        // we have to ensure we measure through the last zero-width character.
      } while (result != null && result.getIndex() < endColumn && x < endX);
    }

    if (result == null) {
      cache.measuredOffset = ColumnOffsetCache.FULLY_MEASURED;
      return;
View Full Code Here

TOP

Related Classes of com.google.gwt.regexp.shared.MatchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.