Package com.google.gwt.regexp.shared

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


    private static RegExp dateTimePattern =
            RegExp.compile("\\-?([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])T([0-9][0-9]):([0-9][0-9]):([0-9][0-9])(\\.[0-9]*)?([-+Z].*)?");

    public static ConversionResult makeDateTimeValue(CharSequence s) {
        String str = s.toString();
        MatchResult match = dateTimePattern.exec(str);
        if (match == null) {
            return badDate("wrong format", str);
        }
        DateTimeValue dt = new DateTimeValue();
        dt.year = DurationValue.simpleInteger(match.getGroup(1));
        if (str.startsWith("-")) {
          dt.year = dt.year - 1; // no year zero in lexical space for XSD 1.0 - so -1 becomes 0 and -2 becomes -1 etc.
            dt.year = -dt.year;
        }
        dt.month = DurationValue.simpleInteger(match.getGroup(2));
        dt.day = DurationValue.simpleInteger(match.getGroup(3));
        dt.hour = DurationValue.simpleInteger(match.getGroup(4));
        dt.minute = DurationValue.simpleInteger(match.getGroup(5));
        dt.second = DurationValue.simpleInteger(match.getGroup(6));
        String frac = match.getGroup(7);
        if (frac != null && frac.length() > 0) {
            double fractionalSeconds = Double.parseDouble(frac);
            dt.microsecond = (int)(Math.round(fractionalSeconds * 1000000));
        }
        String tz = match.getGroup(8);
        int tzmin = parseTimezone(tz);
        if (tzmin == BAD_TIMEZONE) {
            return badDate("Invalid timezone", str);
        }
        dt.setTimezoneInMinutes(tzmin);
View Full Code Here


            RegExp.compile("(-?[0-9]+-[0-9][0-9])(Z|[+-][0-9][0-9]:[0-9][0-9])?");

    private GYearMonthValue(){}

    public static ConversionResult makeGYearMonthValue(CharSequence value) {
        MatchResult m = regex.exec(Whitespace.trimWhitespace(value).toString());
        if (m == null) {
            return new ValidationFailure("Cannot convert '" + value + "' to a gYearMonth");
        }
        GYearMonthValue g = new GYearMonthValue();
        String base = m.getGroup(1);
        String tz = m.getGroup(2);
        String date = (base==null ? "" : base) + "-01" + (tz==null ? "" : tz);
        g.typeLabel = BuiltInAtomicType.G_YEAR_MONTH;
        return setLexicalValue(g, date);
    }
View Full Code Here

      // 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) {
          styleContent = m.getGroup(0);
View Full Code Here

      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
     
View Full Code Here

                    + "\\[(\\d+)\\]");

    @Override
    public com.google.gwt.user.client.Element getSubPartElement(String subPart) {
        if (SUBPART_ROW_COL_REGEXP.test(subPart)) {
            MatchResult result = SUBPART_ROW_COL_REGEXP.exec(subPart);
            int rowIx = Integer.valueOf(result.getGroup(1));
            int colIx = Integer.valueOf(result.getGroup(2));
            VScrollTableRow row = scrollBody.getRowByRowIndex(rowIx);
            if (row != null) {
                Element rowElement = row.getElement();
                if (colIx < rowElement.getChildCount()) {
                    return rowElement.getChild(colIx).getFirstChild().cast();
                }
            }

        } else if (SUBPART_ROW_REGEXP.test(subPart)) {
            MatchResult result = SUBPART_ROW_REGEXP.exec(subPart);
            int rowIx = Integer.valueOf(result.getGroup(1));
            VScrollTableRow row = scrollBody.getRowByRowIndex(rowIx);
            if (row != null) {
                return row.getElement();
            }

        } else if (SUBPART_HEADER_REGEXP.test(subPart)) {
            MatchResult result = SUBPART_HEADER_REGEXP.exec(subPart);
            int headerIx = Integer.valueOf(result.getGroup(1));
            HeaderCell headerCell = tHead.getHeaderCell(headerIx);
            if (headerCell != null) {
                return headerCell.getElement();
            }

        } else if (SUBPART_FOOTER_REGEXP.test(subPart)) {
            MatchResult result = SUBPART_FOOTER_REGEXP.exec(subPart);
            int footerIx = Integer.valueOf(result.getGroup(1));
            FooterCell footerCell = tFoot.getFooterCell(footerIx);
            if (footerCell != null) {
                return footerCell.getElement();
            }
        }
View Full Code Here

    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);
        CaptionPosition captionPosition = CaptionPosition.valueOf(
                CaptionPosition.class, captionClass.toUpperCase());
        return captionPosition;
    }
View Full Code Here

            }

            float size = 0;
            Unit unit = null;

            MatchResult matcher = sizePattern.exec(s);
            if (matcher.getGroupCount() > 1) {

                size = Float.parseFloat(matcher.getGroup(1));
                if (size < 0) {
                    size = -1;
                    unit = Unit.PX;

                } else {
                    String symbol = matcher.getGroup(2);
                    unit = unitByType(symbol);
                }
            } else {
                throw new IllegalArgumentException("Invalid size argument: \""
                        + s + "\" (should match " + sizePattern.getSource()
View Full Code Here

                     * request and served non-UIDL content (for instance, a
                     * login page if the session has expired.) If the response
                     * contains a magic substring, do a synchronous refresh. See
                     * #8241.
                     */
                    MatchResult refreshToken = RegExp.compile(
                            UIDL_REFRESH_TOKEN + "(:\\s*(.*?))?(\\s|$)").exec(
                            response.getText());
                    if (refreshToken != null) {
                        redirect(refreshToken.getGroup(2));
                        return;
                    }
                }

                // for(;;);[realjson]
View Full Code Here

   
    int i = 0;
    while (i < format.length()) {
      if (format.charAt(i) == '%') {
        final String subStr = format.substring(i);
        final MatchResult match = convPattern.exec(subStr);
        if (match == null || match.getIndex() != 0) {
          throw new IllegalArgumentException("Bad conversion at index " + i + " in format String: " + format);
        }
       
        if (match.getGroup(2) != null && !match.getGroup(2).equals("")) {
          throw new UnsupportedOperationException("Flags are not yet supported in this implementation.");
        }
  
        // TODO: check preconditions and possibly throw IllegalFormatException
        final Object arg;
        final int width;
        final int prec;
        final String suffix;
        final Conversion conv = getConversion(match.getGroup(5).charAt(0));
        final boolean autoIndexed = match.getGroup(1) == null || match.getGroup(1).equals("");

        if (conv.equals(Conversion.escLit) || conv.equals(Conversion.line)) {
          arg = null;
        }
        else if (autoIndexed) {
          arg = args[count];
        }
        else {
          arg = args[Integer.valueOf(match.getGroup(1)) - 1];
        }

        if (match.getGroup(3) == null || match.getGroup(3).equals("")) {
          width = 0;
        }
        else {
          width = Integer.valueOf(match.getGroup(3));
        }

        if (match.getGroup(4) == null || match.getGroup(4).equals("")) {
          prec = Integer.MAX_VALUE;
        }
        else {
          prec = Integer.valueOf(match.getGroup(4));
        }

        if (match.getGroup(6) == null || match.getGroup(6).equals("")) {
          suffix = "";
        }
        else {
          suffix = match.getGroup(6);
        }

        final boolean upper = match.getGroup(5).toUpperCase().equals(match.getGroup(5));
        String replacement;
        try {
          replacement = buildReplacement(conv, upper, width, prec, suffix, arg);
        }
        catch (Exception e) {
          throw new IllegalArgumentException("Error processing substitution " + (count + 1) + ".\nFormat: "
                  + originalFormat + "\nArgs: " + Arrays.toString(args), e);
        }
       
        buffer.append(replacement);
        i += match.getGroup(0).length();

        // Auto-index is incremented for non-explicitly indexed conversions
        if (autoIndexed)
          count += 1;
      }
View Full Code Here

  */
  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);
     
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.