Logo Search packages:      
Sourcecode: icu version File versions

int32_t SimpleDateFormat::matchString ( const UnicodeString text,
int32_t  start,
UCalendarDateFields  field,
const UnicodeString stringArray,
int32_t  stringArrayCount,
Calendar cal 
) const [private]

Private code-size reduction function used by subParse.

textthe time text being parsed.
startwhere to start parsing.
fieldthe date field being parsed.
stringArraythe string array to parsed.
stringArrayCountthe size of the array.
cala Calendar set to the date and time to be formatted into a date/time string.
the new start position if matching succeeded; a negative number indicating matching failure, otherwise.

Definition at line 2425 of file smpdtfmt.cpp.

References UnicodeString::compareBetween(), UnicodeString::extract(), UnicodeString::fastCopyFrom(), UnicodeString::foldCase(), Calendar::getType(), INT32_MAX, UnicodeString::length(), Calendar::set(), UCAL_DAY_OF_WEEK, and UCAL_MONTH.

Referenced by subParse().

    int32_t i = 0;
    int32_t count = dataCount;

    if (field == UCAL_DAY_OF_WEEK) i = 1;

    // There may be multiple strings in the data[] array which begin with
    // the same prefix (e.g., Cerven and Cervenec (June and July) in Czech).
    // We keep track of the longest match, and return that.  Note that this
    // unfortunately requires us to test all array elements.
    int32_t bestMatchLength = 0, bestMatch = -1;

    // {sfb} kludge to support case-insensitive comparison
    // {markus 2002oct11} do not just use caseCompareBetween because we do not know
    // the length of the match after case folding
    // {alan 20040607} don't case change the whole string, since the length
    // can change
    // TODO we need a case-insensitive startsWith function
    UnicodeString lcase, lcaseText;
    text.extract(start, INT32_MAX, lcaseText);

    for (; i < count; ++i)
        // Always compare if we have no match yet; otherwise only compare
        // against potentially better matches (longer strings).

        int32_t length = lcase.length();

        if (length > bestMatchLength &&
            lcaseText.compareBetween(0, length, lcase, 0, length) == 0)
            bestMatch = i;
            bestMatchLength = length;
    if (bestMatch >= 0)
        // Adjustment for Hebrew Calendar month Adar II
        if (!strcmp(cal.getType(),"hebrew") && field==UCAL_MONTH && bestMatch==13) {
        else {
            cal.set(field, bestMatch);

        // Once we have a match, we have to determine the length of the
        // original source string.  This will usually be == the length of
        // the case folded string, but it may differ (e.g. sharp s).

        // Most of the time, the length will be the same as the length
        // of the string from the locale data.  Sometimes it will be
        // different, in which case we will have to figure it out by
        // adding a character at a time, until we have a match.  We do
        // this all in one loop, where we try 'len' first (at index
        // i==0).
        int32_t len = data[bestMatch].length(); // 99+% of the time
        int32_t n = text.length() - start;
        for (i=0; i<=n; ++i) {
            int32_t j=i;
            if (i == 0) {
                j = len;
            } else if (i == len) {
                continue; // already tried this when i was 0
            text.extract(start, j, lcaseText);
            if (lcase == lcaseText) {
                return start + j;

    return -start;

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