Package com.google.gwt.regexp.shared

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


  public static MatchResult findMatchBeforeIndex(
      RegExp regexp, String text, int exclusiveEndIndex) {
    regexp.setLastIndex(0);

    // Find the last match without going over our startIndex
    MatchResult lastMatch = null;
    for (MatchResult result = regexp.exec(text);
        result != null && result.getIndex() < exclusiveEndIndex; result = regexp.exec(text)) {
      lastMatch = result;
    }
View Full Code Here


    StringBuilder builder = new StringBuilder();
    ArgumentFormatHelper helper = new ArgumentFormatHelper(args);

    RegExp formatMatcher = RegExp.compile("(%s)|(%d)", "ig");
    int lastIndex = 0;
    MatchResult result = formatMatcher.exec(template);
    while (result != null) {
      String fragment = template.substring(lastIndex, result.getIndex() - 1);
      builder.append(fragment);
      builder.append(helper.next());

      lastIndex = result.getIndex() + result.getGroup(0).length();
    }

    String lastFragment = template.substring(lastIndex, template.length());
    builder.append(lastFragment);
    builder.append(helper.rest());
View Full Code Here

  }

  private ParseUtils.ExtendedParseResult<State> parse(String text) {
    JsonArray<Token> tokens = JsonCollections.createArray();
    while (text.length() > 0) {
      MatchResult result = PARSER.exec(text);
      if (result == null) {
        throw new IllegalArgumentException("Can't parse: " + text);
      }
      String value;
      TokenType type;
      if (result.getGroup(2) != null) {
        value = result.getGroup(2);
        type = VARIABLE;
      } else if (result.getGroup(3) != null) {
        value = result.getGroup(3);
        type = NULL;
      } else if (result.getGroup(4) != null) {
        value = result.getGroup(4);
        type = WHITESPACE;
      } else {
        throw new IllegalArgumentException("Can't parse: " + result.getGroup(1));
      }
      tokens.add(new Token("test", type, value));
      text = text.substring(value.length());
    }
    ParseResult<State> parseResult = new ParseResult<State>(tokens, TestUtils.createMockState());
View Full Code Here

    String hyphenated = camelCaseMap.get(name);

    // Convert the name to hyphenated format if not in the cache.
    if (hyphenated == null) {
      hyphenated = "";
      MatchResult matches;
      while ((matches = camelCaseWord.exec(name)) != null) {
        String word = matches.getGroup(0);
        if (caseWord.exec(word) == null) {
          // The first letter is already lowercase, probably the first word.
          hyphenated += word;
        } else {
          // Hyphenate the first letter.
          hyphenated += "-" + matches.getGroup(1).toLowerCase();
          if (matches.getGroupCount() > 1) {
            hyphenated += matches.getGroup(2);
          }
        }
      }
      camelCaseMap.put(name, hyphenated);
    }
View Full Code Here

      if (name.startsWith("-") && name.length() > 1) {
        name = name.substring(1);
      }

      camelCase = "";
      MatchResult matches;
      while ((matches = maybeHyphenatedWord.exec(name)) != null) {
        String word = matches.getGroup(0);
        if (!word.startsWith("-")) {
          // The word is not hyphenated. Probably the first word.
          camelCase += word;
        } else {
          // Remove hyphen and uppercase next letter.
          camelCase += matches.getGroup(2).toUpperCase();
          if (matches.getGroupCount() > 2) {
            camelCase += matches.getGroup(3);
          }
        }
      }
      putCamelCaseName(hyphenatedMap, name, camelCase);
    }
View Full Code Here

      @Override
      public ActionResult doAction(ActionSource source) {
        Preconditions.checkNotNull(editor, "Editor cannot be null");

        MatchResult match = numbers.exec(lastQuery);
        // if the user clicks us without specifying a line
        if (match == null) {
          return ActionResult.DO_NOTHING;
        }

        int line = Integer.parseInt(match.getGroup(1));
        int realLine = Math.min(editor.getDocument().getLineCount() - 1, Math.max(line - 1, 0));
        editor.scrollTo(realLine, 0);
        editor.getFocusManager().focus();

        return ActionResult.CLOSE;
View Full Code Here

      }
      if (emptyB && !emptyA) {
        return 1;
      }

      MatchResult resultA = CHUNK_FROM_BEGINNING.exec(a);
      MatchResult resultB = CHUNK_FROM_BEGINNING.exec(b);

      String chunkA = resultA.getGroup(0);
      String chunkB = resultB.getGroup(0);

      boolean isNumA = !StringUtils.isNullOrEmpty(resultA.getGroup(1));
      boolean isNumB = !StringUtils.isNullOrEmpty(resultB.getGroup(1));
      if (isNumA && !isNumB) {
        return -1;
      }
      if (isNumB && !isNumA) {
        return 1;
View Full Code Here

      if (direction == SearchDirection.DOWN) {
        if (line == startLine) {
          // the - 1 is to make sure we include the character at the cursor.
          match = cursorColumn - 1;
        }
        MatchResult result;
        while ((result = RegExpUtils.findMatchAfterIndex(regExp, lineText, match)) != null) {
          match = result.getIndex();
          if (checkForMatch(line, number, match, shouldRenderLine)) {
            return false;
          }
        }
      } else {
        int endColumn = line.length() - 1;
        if (line == startLine) {
          endColumn = cursorColumn - 2;
        }
        // first get all matches
        JsonArray<Integer> matches = JsonCollections.createArray();
        MatchResult result;
        while ((result = RegExpUtils.findMatchAfterIndex(regExp, lineText, match)) != null) {
          match = result.getIndex();
          if (match <= endColumn) {
            matches.add(match);
          } else {
            break;
          }
View Full Code Here

  }

  private static String calculateTriggeringString(SelectionModel selection) {
    String cursorLine = selection.getCursorLine().getText();
    int cursorColumn = selection.getCursorColumn();
    MatchResult matchResult = ID_REGEXP.exec(cursorLine.substring(0, cursorColumn));
    if (matchResult == null) {
      return "";
    }
    return matchResult.getGroup(0);
  }
View Full Code Here

    // tryMatchUrl("/* Go to http://www.google.com/.*/", "http://www.google.com/");
  }

  private void tryMatchUrl(String text, @Nullable String url) {
    DynamicReferenceProvider.REGEXP_URL.setLastIndex(0);
    MatchResult matchResult = DynamicReferenceProvider.REGEXP_URL.exec(text);
    if (url == null) {
      assertNull(matchResult);
      return;
    }
    assertNotNull(matchResult);
    assertEquals(url, matchResult.getGroup(0));
  }
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.