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

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

Returns the length of the initial 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. Similar to the strspn() C library function. 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.

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

Definition at line 2131 of file uniset.cpp.

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

Referenced by containsAll(), containsNone(), and span().

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

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

    UChar32 c;
    int32_t start=0, prev=0;
    do {
        U16_NEXT(s, start, length, c);
        if(spanCondition!=contains(c)) {
    } while((prev=start)<length);
    return prev;

Generated by  Doxygen 1.6.0   Back to index