Logo Search packages:      
Sourcecode: icu version File versions

TransliteratorIDParser::Specs * TransliteratorIDParser::parseFilterID ( const UnicodeString id,
int32_t &  pos,
UBool  allowFilter 
) [static, private]

Parse an ID into component pieces. Take IDs of the form T, T/V, S-T, S-T/V, or S/V-T. If the source is missing, return a source of ANY.

Parameters:
id the id string, in any of several forms
pos INPUT-OUTPUT parameter. On input, pos[0] is the offset of the first character to parse in id. On output, pos[0] is the offset after the last parsed character. If the parse failed, pos[0] will be unchanged.
allowFilter if true, a UnicodeSet pattern is allowed at any location between specs or delimiters, and is returned as the fifth string in the array.
Returns:
a Specs object, or null if the parse failed. If neither source nor target was seen in the parsed id, then the parse fails. If allowFilter is true, then the parsed filter pattern is returned in the Specs object, otherwise the returned filter reference is null. If the parse fails for any reason null is returned.
Parse an ID into component pieces. Take IDs of the form T, T/V, S-T, S-T/V, or S/V-T. If the source is missing, return a source of ANY.
Parameters:
id the id string, in any of several forms
pos INPUT-OUTPUT parameter. On input, pos is the offset of the first character to parse in id. On output, pos is the offset after the last parsed character. If the parse failed, pos will be unchanged.
allowFilter2 if TRUE, a UnicodeSet pattern is allowed at any location between specs or delimiters, and is returned as the fifth string in the array.
Returns:
a Specs object, or NULL if the parse failed. If neither source nor target was seen in the parsed id, then the parse fails. If allowFilter is TRUE, then the parsed filter pattern is returned in the Specs object, otherwise the returned filter reference is NULL. If the parse fails for any reason NULL is returned.

Definition at line 643 of file tridpars.cpp.

References UnicodeString::length(), NULL, UnicodeSet::resemblesPattern(), U_FAILURE, and U_ZERO_ERROR.

Referenced by parseBasicID(), and parseSingleID().

                                                         {
    UnicodeString first;
    UnicodeString source;
    UnicodeString target;
    UnicodeString variant;
    UnicodeString filter;
    UChar delimiter = 0;
    int32_t specCount = 0;
    int32_t start = pos;

    // This loop parses one of the following things with each
    // pass: a filter, a delimiter character (either '-' or '/'),
    // or a spec (source, target, or variant).
    for (;;) {
        ICU_Utility::skipWhitespace(id, pos, TRUE);
        if (pos == id.length()) {
            break;
        }

        // Parse filters
        if (allowFilter && filter.length() == 0 &&
            UnicodeSet::resemblesPattern(id, pos)) {

            ParsePosition ppos(pos);
            UErrorCode ec = U_ZERO_ERROR;
            UnicodeSet set(id, ppos, ec);
            if (U_FAILURE(ec)) {
                pos = start;
                return NULL;
            }
            id.extractBetween(pos, ppos.getIndex(), filter);
            pos = ppos.getIndex();
            continue;
        }

        if (delimiter == 0) {
            UChar c = id.charAt(pos);
            if ((c == TARGET_SEP && target.length() == 0) ||
                (c == VARIANT_SEP && variant.length() == 0)) {
                delimiter = c;
                ++pos;
                continue;
            }
        }

        // We are about to try to parse a spec with no delimiter
        // when we can no longer do so (we can only do so at the
        // start); break.
        if (delimiter == 0 && specCount > 0) {
            break;
        }

        UnicodeString spec = ICU_Utility::parseUnicodeIdentifier(id, pos);
        if (spec.length() == 0) {
            // Note that if there was a trailing delimiter, we
            // consume it.  So Foo-, Foo/, Foo-Bar/, and Foo/Bar-
            // are legal.
            break;
        }

        switch (delimiter) {
        case 0:
            first = spec;
            break;
        case TARGET_SEP:
            target = spec;
            break;
        case VARIANT_SEP:
            variant = spec;
            break;
        }
        ++specCount;
        delimiter = 0;
    }

    // A spec with no prior character is either source or target,
    // depending on whether an explicit "-target" was seen.
    if (first.length() != 0) {
        if (target.length() == 0) {
            target = first;
        } else {
            source = first;
        }
    }

    // Must have either source or target
    if (source.length() == 0 && target.length() == 0) {
        pos = start;
        return NULL;
    }

    // Empty source or target defaults to ANY
    UBool sawSource = TRUE;
    if (source.length() == 0) {
        source = ANY;
        sawSource = FALSE;
    }
    if (target.length() == 0) {
        target = ANY;
    }

    return new Specs(source, target, variant, sawSource, filter);
}


Generated by  Doxygen 1.6.0   Back to index