private TokenStream tokenizeAddress()

in geronimo-mail_2.1_spec/src/main/java/jakarta/mail/internet/AddressParser.java [639:745]


    private TokenStream tokenizeAddress() throws AddressException {

        // get a list for the set of tokens
        final TokenStream tokens = new TokenStream();

        end = addresses.length();    // our parsing end marker

        // now scan along the string looking for the special characters in an internet address.
        while (moreCharacters()) {
            final char ch = currentChar();

            switch (ch) {
                // start of a comment bit...ignore everything until we hit a closing paren.
                case '(':
                    scanComment(tokens);
                    break;
                // a closing paren found outside of normal processing.
                case ')':
                    syntaxError("Unexpected ')'", position);


                // start of a quoted string
                case '"':
                    scanQuotedLiteral(tokens);
                    break;
                // domain literal
                case '[':
                    scanDomainLiteral(tokens);
                    break;

                // a naked closing bracket...not valid except as part of a domain literal.
                case ']':
                    syntaxError("Unexpected ']'", position);

                // special character delimiters
                case '<':
                    tokens.addToken(new AddressToken(LEFT_ANGLE, position));
                    nextChar();
                    break;

                // a naked closing bracket...not valid without a starting one, but
                // we need to handle this in context.
                case '>':
                    tokens.addToken(new AddressToken(RIGHT_ANGLE, position));
                    nextChar();
                    break;
                case ':':
                    tokens.addToken(new AddressToken(COLON, position));
                    nextChar();
                    break;
                case ',':
                    tokens.addToken(new AddressToken(COMMA, position));
                    nextChar();
                    break;
                case '.':
                    tokens.addToken(new AddressToken(PERIOD, position));
                    nextChar();
                    break;
                case ';':
                    tokens.addToken(new AddressToken(SEMICOLON, position));
                    nextChar();
                    break;
                case '@':
                    tokens.addToken(new AddressToken(AT_SIGN, position));
                    nextChar();
                    break;

                // white space characters.  These are mostly token delimiters, but there are some relaxed
                // situations where they get processed, so we need to add a white space token for the first
                // one we encounter in a span.
                case ' ':
                case '\t':
                case '\r':
                case '\n':
                    // add a single white space token
                    tokens.addToken(new AddressToken(WHITESPACE, position));

                    nextChar();
                    // step over any space characters, leaving us positioned either at the end
                    // or the first
                    while (moreCharacters()) {
                        final char nextChar = currentChar();
                        if (nextChar == ' ' || nextChar == '\t' || nextChar == '\r' || nextChar == '\n') {
                            nextChar();
                        }
                        else {
                            break;
                        }
                    }
                    break;

                // potentially an atom...if it starts with an allowed atom character, we
                // parse out the token, otherwise this is invalid.
                default:
                    if (ch < 040 || ch >= 0177) {
                        syntaxError("Illegal character in address", position);
                    }

                    scanAtom(tokens);
                    break;
            }
        }

        // for this end marker, give an end position.
        tokens.addToken(new AddressToken(END_OF_TOKENS, addresses.length()));
        return tokens;
    }