Ejemplo n.º 1
0
 protected String hvalue() throws ParseException {
   StringBuffer retval = new StringBuffer();
   while (lexer.hasMoreChars()) {
     char la = lexer.lookAhead(0);
     // Look for a character that can terminate a URL.
     if (la == '+'
         || la == '?'
         || la == ':'
         || la == '['
         || la == ']'
         || la == '/'
         || la == '$'
         || la == '_'
         || la == '-'
         || la == '"'
         || la == '!'
         || la == '~'
         || la == '*'
         || la == '.'
         || la == '('
         || la == ')'
         || Lexer.isAlpha(la)
         || Lexer.isDigit(la)) {
       lexer.consume(1);
       retval.append(la);
     } else if (la == '%') {
       retval.append(escaped());
     } else break;
   }
   return retval.toString();
 }
Ejemplo n.º 2
0
 protected boolean isEscaped() {
   try {
     char next = lexer.lookAhead(0);
     char next1 = lexer.lookAhead(1);
     char next2 = lexer.lookAhead(2);
     return (next == '%' && Lexer.isHexDigit(next1) && Lexer.isHexDigit(next2));
   } catch (Exception ex) {
     return false;
   }
 }
Ejemplo n.º 3
0
 /** Parser for the local phone #. */
 private String local_number() throws ParseException {
   StringBuffer s = new StringBuffer();
   if (debug) dbg_enter("local_number");
   try {
     int lc = 0;
     while (lexer.hasMoreChars()) {
       char la = lexer.lookAhead(0);
       if (la == '*'
           || la == '#'
           || la == '-'
           || la == '.'
           || la == '('
           || la == ')'
           || Lexer.isDigit(la)) {
         lexer.consume(1);
         s.append(la);
         lc++;
       } else if (lc > 0) break;
       else throw createParseException("unexepcted " + la);
     }
     return s.toString();
   } finally {
     if (debug) dbg_leave("local_number");
   }
 }
Ejemplo n.º 4
0
 protected String escaped() throws ParseException {
   if (debug) dbg_enter("escaped");
   try {
     StringBuffer retval = new StringBuffer();
     char next = lexer.lookAhead(0);
     char next1 = lexer.lookAhead(1);
     char next2 = lexer.lookAhead(2);
     if (next == '%' && Lexer.isHexDigit(next1) && Lexer.isHexDigit(next2)) {
       lexer.consume(3);
       retval.append(next);
       retval.append(next1);
       retval.append(next2);
     } else throw createParseException("escaped");
     return retval.toString();
   } finally {
     if (debug) dbg_leave("escaped");
   }
 }
Ejemplo n.º 5
0
  /**
   * Parser for telephone subscriber.
   *
   * @return the parsed telephone number.
   */
  public final TelephoneNumber parseTelephoneNumber() throws ParseException {
    TelephoneNumber tn;

    if (debug) dbg_enter("telephone_subscriber");
    lexer.selectLexer("charLexer");
    try {
      char c = lexer.lookAhead(0);
      if (c == '+') tn = global_phone_number();
      else if (Lexer.isAlpha(c)
          || Lexer.isDigit(c)
          || c == '-'
          || c == '*'
          || c == '.'
          || c == '('
          || c == ')'
          || c == '#') {
        tn = local_phone_number();
      } else throw createParseException("unexpected char " + c);
      return tn;
    } finally {
      if (debug) dbg_leave("telephone_subscriber");
    }
  }
Ejemplo n.º 6
0
 protected String uricNoSlash() {
   if (debug) dbg_enter("uricNoSlash");
   try {
     try {
       char la = lexer.lookAhead(0);
       if (isEscaped()) {
         String retval = lexer.charAsString(3);
         lexer.consume(3);
         return retval;
       } else if (isUnreserved(la)) {
         lexer.consume(1);
         return Lexer.charAsString(la);
       } else if (isReservedNoSlash(la)) {
         lexer.consume(1);
         return Lexer.charAsString(la);
       } else return null;
     } catch (ParseException ex) {
       return null;
     }
   } finally {
     if (debug) dbg_leave("uricNoSlash");
   }
 }
Ejemplo n.º 7
0
  /** Parser for the base phone number. */
  private String base_phone_number() throws ParseException {
    StringBuffer s = new StringBuffer();

    if (debug) dbg_enter("base_phone_number");
    try {
      int lc = 0;
      while (lexer.hasMoreChars()) {
        char w = lexer.lookAhead(0);
        if (Lexer.isDigit(w) || w == '-' || w == '.' || w == '(' || w == ')') {
          lexer.consume(1);
          s.append(w);
          lc++;
        } else if (lc > 0) break;
        else throw createParseException("unexpected " + w);
      }
      return s.toString();
    } finally {
      if (debug) dbg_leave("base_phone_number");
    }
  }
Ejemplo n.º 8
0
 protected static boolean isUnreserved(char next) {
   return Lexer.isAlpha(next) || Lexer.isDigit(next) || isMark(next);
 }