Package com.google.gwt.regexp.shared

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


      // style attribute must exist and must be quoted properly
      // IE9 does not include style attributes text if their value is not valid
      // we therefore don't expect non-quoted styles like <h1 style=color id="abc"...
      String value = getOuterHTML(elem);
     
      RegExp quotesPattern = RegExp.compile("(?:\".*?\"|\'.*?\'|[^\'\"]+|['\"])", "g"); // g=global: = all-matches
      RegExp stylePattern = RegExp.compile("[\\s]style\\s*="); // e.g. match: <h1 style=
      MatchResult m = quotesPattern.exec(value);

      int i = 0;
      boolean styleFound = false;
      String styleContent = "";
      String nonQ = "";
      while (quotesPattern.getLastIndex() > 0) {
        if (i % 2 == 0) {
          nonQ = m.getGroup(0); // not in quotes - so check
          MatchResult ms = stylePattern.exec(nonQ);
          styleFound = ms.getGroupCount() > 0;
          if (!styleFound && nonQ.indexOf('>') > -1) {
            break; // no more attributes
          }
        } else if (styleFound) {
View Full Code Here


      ArrayList<String> nodeNames = new ArrayList<String>();
      ArrayList<String> xmlnsNames = new ArrayList<String>();
      ArrayList<String> xmlnsUris = new ArrayList<String>();
      namespaceBindings = new ArrayList<NamespaceBinding>();
     
      RegExp quotesPattern = RegExp.compile("(?:\"(.|\n)*?\"|\'(.|\n)*?\'|[^\'\"]+|['\"])", "gm"); // g=global: = all-matches m=multiline
      MatchResult m = quotesPattern.exec(value);

      int i = 0;
      String nonQ = "";
      boolean awaitingXmlnsUri = false;
      while (quotesPattern.getLastIndex() > 0) {
       
        if (i % 2 == 0) {
          nonQ = m.getGroup(0); // not in quotes - so check
          StringBuffer sb = new StringBuffer();
          boolean endOfTag = false;
          boolean isName = !(i == 0);// first part is not a name: e.g. \r\n<H1 style="
          int start = 0;
          if (i == 0) {
            start = nonQ.indexOf('<') + 1;          
          }
          for (int x = start; x < nonQ.length(); x++) {
            int[] offsetChar = skipWhitespace(x, nonQ, false);
            int offset = offsetChar[0];
           
            if(offset > 0 && !(isName)) {
              // no whitespace allow in an unquoted value, so we're back on a name
              isName = true;
            }
            char ch = (char)offsetChar[1];
            if (ch == '\0') break;
            if (ch == '=') {
              // part after the '=' is the value, until next whitespace
              isName = false;
              String attName = sb.toString();
             
              if (attName.startsWith("xmlns")) {
                xmlnsNames.add(attName);
                awaitingXmlnsUri = true;
              } else if(attName.length() != 0) {
                nodeNames.add(attName);
                awaitingXmlnsUri = false;
              }

              sb = new StringBuffer();
              continue;
            } else if (ch == '>') {
              endOfTag = true;
              break;
            }
           
            if (isName) {
              sb.append(ch);
            }          
            x += offset;
          } // end for
          if (endOfTag) {
            break;
          }
        } else if (awaitingXmlnsUri) {// ends if i % 2
          xmlnsUris.add(m.getGroup(0));
        }
        i++;
        m = quotesPattern.exec(value);
      } // end while
     
      HTMLAttributeNode[] nodeArray = new HTMLAttributeNode[nodeNames.size()];
      for (int y = 0; y < nodeNames.size(); y++) {
        String name = nodeNames.get(y);
View Full Code Here

     *             {@link #getCaptionPositionFromElement(Element)} instead
     */
    @Deprecated
    public CaptionPosition getCaptionPositionFromElement(
            com.google.gwt.user.client.Element captionWrap) {
        RegExp captionPositionRegexp = RegExp.compile("v-caption-on-(\\S+)");

        // Get caption position from the classname
        MatchResult matcher = captionPositionRegexp.exec(captionWrap
                .getClassName());
        if (matcher == null || matcher.getGroupCount() < 2) {
            return CaptionPosition.TOP;
        }
        String captionClass = matcher.getGroup(1);
View Full Code Here

     *            to vaadin element
     * @return true if path refers to UI element, false otherwise
     */
    public static boolean isUIElement(String path) {
        String regex = "^\\/{0,2}(com\\.vaadin\\.ui\\.)?V?UI[\\/\\[]?";
        RegExp regexp = RegExp.compile(regex);
        return regexp.test(path);
    }
View Full Code Here

     *            to vaadin element
     * @return true if path refers to Notification element, false otherwise
     */
    public static boolean isNotificationElement(String path) {
        String regex = "^\\/{0,2}(com\\.vaadin\\.ui\\.)?V?Notification[\\/\\[]?";
        RegExp regexp = RegExp.compile(regex);
        return regexp.test(path);
    }
View Full Code Here

     * @param args     Arguments to apply into format
     * @return Formatted string.
     * @see <a href="http://stackoverflow.com/questions/3126232/string-formatter-in-gwt">Stack Overflow</a>
     */
    public static String format(final String format, final Object... args) {
        RegExp regex = RegExp.compile("%[a-z]");
        SplitResult split = regex.split(format);
        StringBuffer msg = new StringBuffer();

        for (int pos = 0; pos < split.length() - 1; pos += 1) {
            msg.append(split.get(pos));
            msg.append(args[pos].toString());
View Full Code Here

  * Generates a {@link URLPattern} from a {@link Page#path()}
  * @param urlTemplate The {@link Page#path()}
  * @return A {@link URLPattern} used to match URLs
  */
  public static URLPattern generatePattern(String urlTemplate) {
    RegExp regex = RegExp.compile(URLPattern.paramRegex, "g");
    List<String> paramList = new ArrayList<String>();

    MatchResult mr = null;
    StringBuilder sb = new StringBuilder();

    // Ensure matching at beginning of line
    sb.append("^");

    int endOfPreviousPattern = 0;
    int startOfNextPattern = 0;

    while ((mr = regex.exec(urlTemplate)) != null) {
      addParamName(paramList, mr);
      startOfNextPattern = mr.getIndex();
     
      // Append any string literal that may occur in the URL path
      // before the next parameter.
      sb.append(urlTemplate, endOfPreviousPattern, startOfNextPattern);
     
      // Append regex for matching the parameter value
      sb.append(URLPattern.urlSafe);
     
      endOfPreviousPattern = regex.getLastIndex();
    }

    // Append any remaining trailing string literals
    sb.append(urlTemplate, endOfPreviousPattern, urlTemplate.length());

View Full Code Here

   * @throws IllegalStateException
   *           If a path parameter is missing from the given state map.
   * @return The constructed URL path without the application context.
   */
  public String printURL(ImmutableMultimap<String, String> state) {
    RegExp re = RegExp.compile(paramRegex, "g");
    String url = this.urlTemplate;
   
    MatchResult mr;

    while ((mr = re.exec(this.urlTemplate)) != null) {
      String toReplace = mr.getGroup(0);
      String key = mr.getGroup(1);
      if (toReplace.contains(key)) {
        url = url.replace(toReplace, state.get(key).iterator().next());
      }
View Full Code Here

    assert model.getQuery() != null;
    assert model.getSearchPattern() != null;

    edges.clear();
    String text = line.getText();
    RegExp regex = model.getSearchPattern();
    /*
     * 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) {
View Full Code Here

    JsonArray<PathUtil> files = recentFiles.slice(1, MAX_RECENT_FILES+1);
    if (searchIndex != null && !StringUtils.isNullOrEmpty(query)) {
      // TODO: Results come back in the order they appear in the tree
      // there needs to be some sort of twiddler that re-ranks the results so
      // that filenames that are better matches appear higher.
      RegExp reQuery = RegExpUtils.createRegExpForWildcardPattern(
          query, ClientStringUtils.containsUppercase(query) ? "" : "i");
      files = searchIndex.getMatches(reQuery, 5);
    }

    // we don't have anything to display
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.