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

void Transliterator::_transliterate ( Replaceable text,
UTransPosition index,
const UnicodeString insertion,
UErrorCode status 
) const [private]

This internal method does incremental transliteration. If the 'insertion' is non-null then we append it to 'text' before proceeding. This method calls through to the pure virtual framework method handleTransliterate() to do the actual work.

Parameters:
text the buffer holding transliterated and untransliterated text
index an array of three integers. See transliterate(Replaceable, int[], String).
insertion text to be inserted and possibly transliterated into the translation buffer at index.limit.
status Output param to filled in with a success or an error.
This internal method does keyboard transliteration. If the 'insertion' is non-null then we append it to 'text' before proceeding. This method calls through to the pure virtual framework method handleTransliterate() to do the actual work.

Definition at line 351 of file translit.cpp.

References Replaceable::char32At(), Replaceable::charAt(), UTransPosition::contextLimit, UTransPosition::contextStart, filteredTransliterate(), getMaximumContextLength(), Replaceable::handleReplaceBetween(), UnicodeString::length(), Replaceable::length(), UTransPosition::limit, UTransPosition::start, TRUE, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, UTF_CHAR_LENGTH, and UTF_IS_LEAD.

Referenced by transliterate().

                                                              {
    if (U_FAILURE(status)) {
        return;
    }

    if (!positionIsValid(index, text.length())) {
        status = U_ILLEGAL_ARGUMENT_ERROR;
        return;
    }

//    int32_t originalStart = index.contextStart;
    if (insertion != 0) {
        text.handleReplaceBetween(index.limit, index.limit, *insertion);
        index.limit += insertion->length();
        index.contextLimit += insertion->length();
    }

    if (index.limit > 0 &&
        UTF_IS_LEAD(text.charAt(index.limit - 1))) {
        // Oops, there is a dangling lead surrogate in the buffer.
        // This will break most transliterators, since they will
        // assume it is part of a pair.  Don't transliterate until
        // more text comes in.
        return;
    }

    filteredTransliterate(text, index, TRUE, TRUE);

#if 0
    // TODO
    // I CAN'T DO what I'm attempting below now that the Kleene star
    // operator is supported.  For example, in the rule

    //   ([:Lu:]+) { x } > $1;

    // what is the maximum context length?  getMaximumContextLength()
    // will return 1, but this is just the length of the ante context
    // part of the pattern string -- 1 character, which is a standin
    // for a Quantifier, which contains a StringMatcher, which
    // contains a UnicodeSet.

    // There is a complicated way to make this work again, and that's
    // to add a "maximum left context" protocol into the
    // UnicodeMatcher hierarchy.  At present I'm not convinced this is
    // worth it.

    // ---

    // The purpose of the code below is to keep the context small
    // while doing incremental transliteration.  When part of the left
    // context (between contextStart and start) is no longer needed,
    // we try to advance contextStart past that portion.  We use the
    // maximum context length to do so.
    int32_t newCS = index.start;
    int32_t n = getMaximumContextLength();
    while (newCS > originalStart && n-- > 0) {
        --newCS;
        newCS -= UTF_CHAR_LENGTH(text.char32At(newCS)) - 1;
    }
    index.contextStart = uprv_max(newCS, originalStart);
#endif
}


Generated by  Doxygen 1.6.0   Back to index