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

void UnicodeSet::applyFilter ( UnicodeSet::Filter  filter,
void *  context,
int32_t  src,
UErrorCode status 
) [private]

Given a filter, set this UnicodeSet to the code points contained by that filter. The filter MUST be property-conformant. That is, if it returns value v for one code point, then it must return v for all affiliated code points, as defined by the inclusions list. See getInclusions(). src is a UPropertySource value.

Generic filter-based scanning code for UCD property UnicodeSets.

Definition at line 944 of file uniset_props.cpp.

References clear(), getRangeCount(), getRangeEnd(), getRangeStart(), isBogus(), U_FAILURE, U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.

Referenced by applyIntPropertyValue(), and applyPropertyAlias().

                                                 {
    // Walk through all Unicode characters, noting the start
    // and end of each range for which filter.contain(c) is
    // true.  Add each range to a set.
    //
    // To improve performance, use the INCLUSIONS set, which
    // encodes information about character ranges that are known
    // to have identical properties. INCLUSIONS contains
    // only the first characters of such ranges.
    //
    // TODO Where possible, instead of scanning over code points,
    // use internal property data to initialize UnicodeSets for
    // those properties.  Scanning code points is slow.
    if (U_FAILURE(status)) return;

    const UnicodeSet* inclusions = getInclusions(src, status);
    if (U_FAILURE(status)) {
        return;
    }

    clear();

    UChar32 startHasProperty = -1;
    int32_t limitRange = inclusions->getRangeCount();

    for (int j=0; j<limitRange; ++j) {
        // get current range
        UChar32 start = inclusions->getRangeStart(j);
        UChar32 end = inclusions->getRangeEnd(j);

        // for all the code points in the range, process
        for (UChar32 ch = start; ch <= end; ++ch) {
            // only add to this UnicodeSet on inflection points --
            // where the hasProperty value changes to false
            if ((*filter)(ch, context)) {
                if (startHasProperty < 0) {
                    startHasProperty = ch;
                }
            } else if (startHasProperty >= 0) {
                add(startHasProperty, ch-1);
                startHasProperty = -1;
            }
        }
    }
    if (startHasProperty >= 0) {
        add((UChar32)startHasProperty, (UChar32)0x10FFFF);
    }
    if (isBogus() && U_SUCCESS(status)) {
        // We likely ran out of memory. AHHH!
        status = U_MEMORY_ALLOCATION_ERROR;
    }
}


Generated by  Doxygen 1.6.0   Back to index