Logo Search packages:      
Sourcecode: icu version File versions

U_CDECL_END UBool TransliteratorIDParser::parseCompoundID ( const UnicodeString id,
int32_t  dir,
UnicodeString canonID,
UVector list,
UnicodeSet *&  globalFilter 
) [static]

Parse a compound ID, consisting of an optional forward global filter, a separator, one or more single IDs delimited by separators, an an optional reverse global filter. The separator is a semicolon. The global filters are UnicodeSet patterns. The reverse global filter must be enclosed in parentheses.

Parameters:
id the pattern the parse
dir the direction.
canonID OUTPUT parameter that receives the canonical ID, consisting of canonical IDs for all elements, as returned by parseSingleID(), separated by semicolons. Previous contents are discarded.
list OUTPUT parameter that receives a list of SingleID objects representing the parsed IDs. Previous contents are discarded.
globalFilter OUTPUT parameter that receives a pointer to a newly created global filter for this ID in this direction, or null if there is none.
Returns:
true if the parse succeeds, that is, if the entire id is consumed without syntax error.
Parse a compound ID, consisting of an optional forward global filter, a separator, one or more single IDs delimited by separators, an an optional reverse global filter. The separator is a semicolon. The global filters are UnicodeSet patterns. The reverse global filter must be enclosed in parentheses.
Parameters:
id the pattern the parse
dir the direction.
canonID OUTPUT parameter that receives the canonical ID, consisting of canonical IDs for all elements, as returned by parseSingleID(), separated by semicolons. Previous contents are discarded.
list OUTPUT parameter that receives a list of SingleID objects representing the parsed IDs. Previous contents are discarded.
globalFilter OUTPUT parameter that receives a pointer to a newly created global filter for this ID in this direction, or NULL if there is none.
Returns:
TRUE if the parse succeeds, that is, if the entire id is consumed without syntax error.

Definition at line 325 of file tridpars.cpp.

References UVector::addElement(), UnicodeString::append(), TransliteratorIDParser::SingleID::canonID, UVector::elementAt(), UVector::insertElementAt(), NULL, parseGlobalFilter(), parseSingleID(), UVector::removeAllElements(), UVector::setDeleter(), UVector::size(), UnicodeString::truncate(), U_FAILURE, and U_ZERO_ERROR.

Referenced by Transliterator::createInstance(), and CompoundTransliterator::init().

                                                                         {
    UErrorCode ec = U_ZERO_ERROR;
    int32_t i;
    int32_t pos = 0;
    int32_t withParens = 1;
    list.removeAllElements();
    UnicodeSet* filter;
    globalFilter = NULL;
    canonID.truncate(0);

    // Parse leading global filter, if any
    withParens = 0; // parens disallowed
    filter = parseGlobalFilter(id, pos, dir, withParens, &canonID);
    if (filter != NULL) {
        if (!ICU_Utility::parseChar(id, pos, ID_DELIM)) {
            // Not a global filter; backup and resume
            canonID.truncate(0);
            pos = 0;
        }
        if (dir == FORWARD) {
            globalFilter = filter;
        } else {
            delete filter;
        }
        filter = NULL;
    }

    UBool sawDelimiter = TRUE;
    for (;;) {
        SingleID* single = parseSingleID(id, pos, dir);
        if (single == NULL) {
            break;
        }
        if (dir == FORWARD) {
            list.addElement(single, ec);
        } else {
            list.insertElementAt(single, 0, ec);
        }
        if (U_FAILURE(ec)) {
            goto FAIL;
        }
        if (!ICU_Utility::parseChar(id, pos, ID_DELIM)) {
            sawDelimiter = FALSE;
            break;
        }
    }

    if (list.size() == 0) {
        goto FAIL;
    }

    // Construct canonical ID
    for (i=0; i<list.size(); ++i) {
        SingleID* single = (SingleID*) list.elementAt(i);
        canonID.append(single->canonID);
        if (i != (list.size()-1)) {
            canonID.append(ID_DELIM);
        }
    }

    // Parse trailing global filter, if any, and only if we saw
    // a trailing delimiter after the IDs.
    if (sawDelimiter) {
        withParens = 1; // parens required
        filter = parseGlobalFilter(id, pos, dir, withParens, &canonID);
        if (filter != NULL) {
            // Don't require trailing ';', but parse it if present
            ICU_Utility::parseChar(id, pos, ID_DELIM);

            if (dir == REVERSE) {
                globalFilter = filter;
            } else {
                delete filter;
            }
            filter = NULL;
        }
    }

    // Trailing unparsed text is a syntax error
    ICU_Utility::skipWhitespace(id, pos, TRUE);
    if (pos != id.length()) {
        goto FAIL;
    }

    return TRUE;

 FAIL:
    UObjectDeleter save = list.setDeleter(_deleteSingleID);
    list.removeAllElements();
    list.setDeleter(save);
    delete globalFilter;
    globalFilter = NULL;
    return FALSE;
}


Generated by  Doxygen 1.6.0   Back to index