Logo Search packages:      
Sourcecode: icu version File versions

int32_t SimpleDateFormat::compareSimpleAffix ( const UnicodeString affix,
const UnicodeString input,
int32_t  pos 
) const [private]

Return the length matched by the given affix, or -1 if none. Runs of white space in the affix, match runs of white space in the input.

Parameters:
affixpattern string, taken as a literal
inputinput text
posoffset into input at which to begin matching
Returns:
length of input that matches, or -1 if match failure

Definition at line 3451 of file smpdtfmt.cpp.

References UnicodeString::char32At(), FALSE, PatternProps::isWhiteSpace(), UnicodeString::length(), skipPatternWhiteSpace(), skipUWhiteSpace(), TRUE, and U16_LENGTH.

                                      {
    int32_t start = pos;
    for (int32_t i=0; i<affix.length(); ) {
        UChar32 c = affix.char32At(i);
        int32_t len = U16_LENGTH(c);
        if (PatternProps::isWhiteSpace(c)) {
            // We may have a pattern like: \u200F \u0020
            //        and input text like: \u200F \u0020
            // Note that U+200F and U+0020 are Pattern_White_Space but only
            // U+0020 is UWhiteSpace.  So we have to first do a direct
            // match of the run of Pattern_White_Space in the pattern,
            // then match any extra characters.
            UBool literalMatch = FALSE;
            while (pos < input.length() &&
                   input.char32At(pos) == c) {
                literalMatch = TRUE;
                i += len;
                pos += len;
                if (i == affix.length()) {
                    break;
                }
                c = affix.char32At(i);
                len = U16_LENGTH(c);
                if (!PatternProps::isWhiteSpace(c)) {
                    break;
                }
            }

            // Advance over run in pattern
            i = skipPatternWhiteSpace(affix, i);

            // Advance over run in input text
            // Must see at least one white space char in input,
            // unless we've already matched some characters literally.
            int32_t s = pos;
            pos = skipUWhiteSpace(input, pos);
            if (pos == s && !literalMatch) {
                return -1;
            }

            // If we skip UWhiteSpace in the input text, we need to skip it in the pattern.
            // Otherwise, the previous lines may have skipped over text (such as U+00A0) that
            // is also in the affix.
            i = skipUWhiteSpace(affix, i);
        } else {
            if (pos < input.length() &&
                input.char32At(pos) == c) {
                i += len;
                pos += len;
            } else {
                return -1;
            }
        }
    }
    return pos - start;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index