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

int32_t ICU_Utility::parsePattern ( const UnicodeString rule,
int32_t  pos,
int32_t  limit,
const UnicodeString pattern,
int32_t *  parsedInts 
) [static]

Parse a pattern string starting at offset pos. Keywords are matched case-insensitively. Spaces may be skipped and may be optional or required. Integer values may be parsed, and if they are, they will be returned in the given array. If successful, the offset of the next non-space character is returned. On failure, -1 is returned.

patternmust only contain lowercase characters, which will match their uppercase equivalents as well. A space character matches one or more required spaces. A '~' character matches zero or more optional spaces. A '#' character matches an integer and stores it in parsedInts, which the caller must ensure has enough capacity.
parsedIntsarray to receive parsed integers. Caller must ensure that parsedInts.length is >= the number of '#' signs in 'pattern'.
the position after the last character parsed, or -1 if the parse failed

Definition at line 84 of file util_props.cpp.

References UnicodeString::charAt(), UnicodeString::length(), parseInteger(), and skipWhitespace().

Referenced by NameUnicodeTransliterator::handleTransliterate().

    // TODO Update this to handle surrogates
    int32_t p;
    int32_t intCount = 0; // number of integers parsed
    for (int32_t i=0; i<pattern.length(); ++i) {
        UChar cpat = pattern.charAt(i);
        UChar c;
        switch (cpat) {
        case 32 /*' '*/:
            if (pos >= limit) {
                return -1;
            c = rule.charAt(pos++);
            if (!uprv_isRuleWhiteSpace(c)) {
                return -1;
            // FALL THROUGH to skipWhitespace
        case 126 /*'~'*/:
            pos = skipWhitespace(rule, pos);
        case 35 /*'#'*/:
            p = pos;
            parsedInts[intCount++] = parseInteger(rule, p, limit);
            if (p == pos) {
                // Syntax error; failed to parse integer
                return -1;
            pos = p;
            if (pos >= limit) {
                return -1;
            c = (UChar) u_tolower(rule.charAt(pos++));
            if (c != cpat) {
                return -1;
    return pos;

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index