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

int32_t UnicodeSet::spanBack ( const UChar *  s,
int32_t  length,
USetSpanCondition  spanCondition 
) const

Returns the start of the trailing substring of the input string which consists only of characters and strings that are contained in this set (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), or only of characters and strings that are not contained in this set (USET_SPAN_NOT_CONTAINED). See USetSpanCondition for details. Unpaired surrogates are treated according to contains() of their surrogate code points. This function works faster with a frozen set and with a non-negative string length argument.

Parameters:
s start of the string
length of the string; can be -1 for NUL-terminated
spanCondition specifies the containment condition
Returns:
the start of the trailing substring according to the spanCondition; the string length if the end of the string does not fit the spanCondition ICU 3.8
See also:
USetSpanCondition

Definition at line 2168 of file uniset.cpp.

References contains(), UVector::isEmpty(), NULL, U16_PREV, u_strlen(), USET_SPAN_CONTAINED, and USET_SPAN_NOT_CONTAINED.

Referenced by spanBack().

                                                                                                  {
    if(length>0 && bmpSet!=NULL) {
        return (int32_t)(bmpSet->spanBack(s, s+length, spanCondition)-s);
    }
    if(length<0) {
        length=u_strlen(s);
    }
    if(length==0) {
        return 0;
    }
    if(stringSpan!=NULL) {
        return stringSpan->spanBack(s, length, spanCondition);
    } else if(!strings->isEmpty()) {
        uint32_t which= spanCondition==USET_SPAN_NOT_CONTAINED ?
                            UnicodeSetStringSpan::BACK_UTF16_NOT_CONTAINED :
                            UnicodeSetStringSpan::BACK_UTF16_CONTAINED;
        UnicodeSetStringSpan strSpan(*this, *strings, which);
        if(strSpan.needsStringSpanUTF16()) {
            return strSpan.spanBack(s, length, spanCondition);
        }
    }

    if(spanCondition!=USET_SPAN_NOT_CONTAINED) {
        spanCondition=USET_SPAN_CONTAINED;  // Pin to 0/1 values.
    }

    UChar32 c;
    int32_t prev=length;
    do {
        U16_PREV(s, 0, length, c);
        if(spanCondition!=contains(c)) {
            break;
        }
    } while((prev=length)>0);
    return prev;
}


Generated by  Doxygen 1.6.0   Back to index