Logo Search packages:      
Sourcecode: icu version File versions  Download package

UnicodeSet * TransliteratorIDParser::parseGlobalFilter ( const UnicodeString id,
int32_t &  pos,
int32_t  dir,
int32_t &  withParens,
UnicodeString canonID 
) [static]

Parse a global filter of the form "[f]" or "([f])", depending on 'withParens'.

Parameters:
id the pattern the parse
pos INPUT-OUTPUT parameter. On input, the position of the first character to parse. On output, the position after the last character parsed.
dir the direction.
withParens INPUT-OUTPUT parameter. On entry, if withParens[0] is 0, then parens are disallowed. If it is 1, then parens are requires. If it is -1, then parens are optional, and the return result will be set to 0 or 1.
canonID OUTPUT parameter. The pattern for the filter added to the canonID, either at the end, if dir is FORWARD, or at the start, if dir is REVERSE. The pattern will be enclosed in parentheses if appropriate, and will be suffixed with an ID_DELIM character. May be null.
Returns:
a UnicodeSet object or null. A non-null results indicates a successful parse, regardless of whether the filter applies to the given direction. The caller should discard it if withParens != (dir == REVERSE).
Parse a global filter of the form "[f]" or "([f])", depending on 'withParens'.
Parameters:
id the pattern the parse
pos INPUT-OUTPUT parameter. On input, the position of the first character to parse. On output, the position after the last character parsed.
dir the direction.
withParens INPUT-OUTPUT parameter. On entry, if withParens is 0, then parens are disallowed. If it is 1, then parens are requires. If it is -1, then parens are optional, and the return result will be set to 0 or 1.
canonID OUTPUT parameter. The pattern for the filter added to the canonID, either at the end, if dir is FORWARD, or at the start, if dir is REVERSE. The pattern will be enclosed in parentheses if appropriate, and will be suffixed with an ID_DELIM character. May be NULL.
Returns:
a UnicodeSet object or NULL. A non-NULL results indicates a successful parse, regardless of whether the filter applies to the given direction. The caller should discard it if withParens != (dir == REVERSE).

Definition at line 254 of file tridpars.cpp.

References UnicodeString::append(), ParsePosition::getIndex(), UnicodeString::insert(), UnicodeString::length(), NULL, UnicodeSet::resemblesPattern(), TRUE, U_FAILURE, U_ZERO_ERROR, and USET_IGNORE_SPACE.

Referenced by parseCompoundID().

                                                                              {
    UnicodeSet* filter = NULL;
    int32_t start = pos;

    if (withParens == -1) {
        withParens = ICU_Utility::parseChar(id, pos, OPEN_REV) ? 1 : 0;
    } else if (withParens == 1) {
        if (!ICU_Utility::parseChar(id, pos, OPEN_REV)) {
            pos = start;
            return NULL;
        }
    }

    ICU_Utility::skipWhitespace(id, pos, TRUE);

    if (UnicodeSet::resemblesPattern(id, pos)) {
        ParsePosition ppos(pos);
        UErrorCode ec = U_ZERO_ERROR;
        filter = new UnicodeSet(id, ppos, USET_IGNORE_SPACE, NULL, ec);
        /* test for NULL */
        if (filter == 0) {
            pos = start;
            return 0;
        }
        if (U_FAILURE(ec)) {
            delete filter;
            pos = start;
            return NULL;
        }

        UnicodeString pattern;
        id.extractBetween(pos, ppos.getIndex(), pattern);
        pos = ppos.getIndex();

        if (withParens == 1 && !ICU_Utility::parseChar(id, pos, CLOSE_REV)) {
            pos = start;
            return NULL;
        }

        // In the forward direction, append the pattern to the
        // canonID.  In the reverse, insert it at zero, and invert
        // the presence of parens ("A" <-> "(A)").
        if (canonID != NULL) {
            if (dir == FORWARD) {
                if (withParens == 1) {
                    pattern.insert(0, OPEN_REV);
                    pattern.append(CLOSE_REV);
                }
                canonID->append(pattern).append(ID_DELIM);
            } else {
                if (withParens == 0) {
                    pattern.insert(0, OPEN_REV);
                    pattern.append(CLOSE_REV);
                }
                canonID->insert(0, pattern);
                canonID->insert(pattern.length(), ID_DELIM);
            }
        }
    }

    return filter;
}


Generated by  Doxygen 1.6.0   Back to index