Package com.google.gwt.regexp.shared

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


     * see if we hit an interesting character other than prefixed tab. if we do
     * we'll measure that to that point and append a {@link ColumnOffset} if it
     * 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) {
View Full Code Here


     * wildcard or if we should replace it with it's regex equivalent.
     *
     *  NOTE: * is replaced with \S+ (matches all non-whitespace characters) and
     * ? is replaced with a single \S to match any non-whitespace
     */
    RegExp mimicLookbehind = RegExp.compile("([\\\\]*)([?*])", "g");
    StringBuilder wildcardStr = new StringBuilder(escaped);
   
    for (MatchResult match = mimicLookbehind.exec(wildcardStr.toString()); match != null;
        match = mimicLookbehind.exec(wildcardStr.toString())) {
      // in some browsers an optional group is null, in others its empty string
      if (match.getGroup(1) != null && !match.getGroup(1).isEmpty()) {
        // We undo double-escaping of backslashes performed by the naive escape
        int offset = match.getGroup(1).length() / 2;
        wildcardStr.delete(match.getIndex(), match.getIndex() + offset);
        /*
         * An even number of slashes means the wildcard was not escaped so we
         * must replace it with its regex equivalent.
         */
        if (offset % 2 == 0) {
          if (match.getGroup(2).equals("?")) {
            wildcardStr.replace(match.getIndex() + offset, match.getIndex() + offset + 1, "\\S");
            // we added 1 more character, so we remove 1 less from the index
            offset -= 1;
          } else {
            wildcardStr.replace(match.getIndex() + offset, match.getIndex() + offset + 1, "\\S+");
            // we added 2 characters, so we need to remove 2 less from the index
            offset -= 2;
          }
        }
        mimicLookbehind.setLastIndex(mimicLookbehind.getLastIndex() - offset);
      } else if (match.getGroup(2).equals("?")) {
        wildcardStr.replace(match.getIndex(), match.getIndex() + 1, "\\S");
        mimicLookbehind.setLastIndex(mimicLookbehind.getLastIndex() + 1);
      } else {
        wildcardStr.replace(match.getIndex(), match.getIndex() + 1, "\\S+");
        mimicLookbehind.setLastIndex(mimicLookbehind.getLastIndex() + 2);
      }
    }

    return wildcardStr.toString();
  }
View Full Code Here

   */
  private static String format(String template, Object... args) {
    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());

View Full Code Here

*/
public class RegexpUtilTests extends TestCase {

  /* Tests for createWildcardRegex */
  public void testWildcardRegex() {
    RegExp re = RegExpUtils.createRegExpForWildcardPattern("t?st", "g");
    assertEquals("t\\Sst", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("t*t", "g");
    assertEquals("t\\S+t", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("t*?*", "g");
    assertEquals("t\\S+\\S\\S+", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("t*{?}*", "g");
    assertEquals("t\\S+\\{\\S\\}\\S+", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("*", "g");
    assertEquals("\\S+", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("?", "g");
    assertEquals("\\S", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("\\alex", "g");
    assertEquals("\\\\alex", re.getSource());

    // lets test all the escape characters (minus ? and *, i.e. .+()[]{}\)
    re = RegExpUtils.createRegExpForWildcardPattern(".+$^|()[]{}\\", "g");
    assertEquals("\\.\\+\\$\\^\\|\\(\\)\\[\\]\\{\\}\\\\", re.getSource());
  }
View Full Code Here

    re = RegExpUtils.createRegExpForWildcardPattern(".+$^|()[]{}\\", "g");
    assertEquals("\\.\\+\\$\\^\\|\\(\\)\\[\\]\\{\\}\\\\", re.getSource());
  }

  public void testEscapedWildcardRegex() {
    RegExp re = RegExpUtils.createRegExpForWildcardPattern("\\*", "g");
    assertEquals("\\*", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("\\?", "g");
    assertEquals("\\?", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("\\?\\?\\*\\*\\?", "g");
    assertEquals("\\?\\?\\*\\*\\?", re.getSource());
   
    re = RegExpUtils.createRegExpForWildcardPattern("j\\?uni? t*est\\*", "g");
    assertEquals("j\\?uni\\S t\\S+est\\*", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("...\\?", "g");
    assertEquals("\\.\\.\\.\\?", re.getSource());
   
    re = RegExpUtils.createRegExpForWildcardPattern("\\\\*", "g");
    assertEquals("\\\\\\S+", re.getSource());
   
    re = RegExpUtils.createRegExpForWildcardPattern("\\\\?", "g");
    assertEquals("\\\\\\S", re.getSource());

    re = RegExpUtils.createRegExpForWildcardPattern("\\\\\\*", "g");
    assertEquals("\\\\\\*", re.getSource());
  }
View Full Code Here

    re = RegExpUtils.createRegExpForWildcardPattern("\\\\\\*", "g");
    assertEquals("\\\\\\*", re.getSource());
  }
 
  public void testGetNumberMatchesIsCorrect() {
    RegExp re = RegExp.compile("a","g");
    assertEquals(2, RegExpUtils.getNumberOfMatches(re, "aall"));
   
    re = RegExp.compile("\\S+", "g");
    assertEquals(1, RegExpUtils.getNumberOfMatches(re,"hahahahahaha"));
   
View Full Code Here

          searchPath = new PathUtil(query.substring(0, query.lastIndexOf(PathUtil.SEP)));
          query = query.substring(query.lastIndexOf(PathUtil.SEP) + 1);
        }

        // Only the non folder part (if it exists) is supported for wildcards
        RegExp reQuery = RegExpUtils.createRegExpForWildcardPattern(
            query, ClientStringUtils.containsUppercase(query) ? "" : "i");
        return searchIndex.getMatchesRelativeToPath(searchPath, reQuery, MAX_AUTOCOMPLETE_RESULTS);
      }

      @Override
View Full Code Here

  public static final String UPDATE = "update";
  // public static final String STYLE = "style";
  public static final String USER = "user";

  public static String parseClientContent(String content) {
    RegExp p = RegExp.compile("\\[{2}((?:.)*?)\\]{2}", "g");
    MatchResult m;
    StringBuffer sb = new StringBuffer();
    int beginIndex = 0;
    while ((m = p.exec(content)) != null) {
      String one = m.getGroup(1);
      String[] split = one.split("\\|");
      int endIndex = m.getIndex();

      sb.append(content.substring(beginIndex, endIndex));

      sb.append("<a href=\"/#!p:" + URL.encodeQueryString(split[0])
          + "\">" + (split.length > 1 ? split[1] : split[0]) + "</a>");

      beginIndex = p.getLastIndex();
    }

    sb.append(content.substring(beginIndex));

    return sb.toString();
View Full Code Here

          final TextField fieldInput = new TextField();
          fieldInput.setValue("first");
          fieldInput.setAllowBlank(false);
          fieldInput.addValidator(new MaxLengthValidator(20));
          final RegExp regex = RegExp.compile("\\s");
          fieldInput.addValidator(new Validator<String>() {
            public List<EditorError> validate(Editor<String> editor, String value) {
              if (regex.test(value)) {
                List<EditorError> errors = new ArrayList<EditorError>();
                errors.add(new DefaultEditorError(editor, "Field name cannot contain spaces.", ""));
                return errors;
              }
              return null;
View Full Code Here

   * parsed.
   */
  public static String getLinkHost(String link) {
    if (link != null) {
      // It doesn't seem as if java.net.URL is GWT-friendly.  Thus...  GWT regular expressions!
      RegExp regExp = RegExp.compile("(\\w+?)://([\\-\\.\\w]+?)/.*");
      // toLowerCase is okay because nothing we're interested in is case sensitive.
      MatchResult result = regExp.exec(link.toLowerCase());

      if (result != null) {
        String protocol = result.getGroup(1);
        String host = result.getGroup(2);
        if (PROTOCOL_WHITELIST.contains(protocol)) {
View Full Code Here

TOP

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

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.