/* ********************************************************************** * Copyright (C) 2001 IBM and others. All rights reserved. ********************************************************************** * Date Name Description * 07/02/2001 synwee Creation. ********************************************************************** */ #include "unicode/usearch.h" #include "unicode/ustring.h" #include "unormimp.h" #include "unicode/uchar.h" #include "cmemory.h" #include "ucol_imp.h" #include "usrchimp.h" // internal definition --------------------------------------------------- #define LAST_BYTE_MASK_ 0xFF #define SECOND_LAST_BYTE_SHIFT_ 8 #define SUPPLEMENTARY_MIN_VALUE_ 0x10000 static const uint16_t *FCD_ = NULL; // internal methods ------------------------------------------------- /** * Getting the mask for collation strength * @param strength collation strength * @return collation element mask */ inline uint32_t getMask(UCollationStrength strength) { switch (strength) { case UCOL_PRIMARY: return UCOL_PRIMARYORDERMASK; case UCOL_SECONDARY: return UCOL_SECONDARYORDERMASK | UCOL_PRIMARYORDERMASK; default: return UCOL_TERTIARYORDERMASK | UCOL_SECONDARYORDERMASK | UCOL_PRIMARYORDERMASK; } } /** * This is to squeeze the 21bit ces into a 256 table * @param ce collation element * @return collapsed version of the collation element */ inline int hash(uint32_t ce) { // the old value UCOL_PRIMARYORDER(ce) % MAX_TABLE_SIZE_ does not work // well with the new collation where most of the latin 1 characters // are of the value xx000xxx. their hashes will most of the time be 0 // to be discussed on the hash algo. return UCOL_PRIMARYORDER(ce) % MAX_TABLE_SIZE_; } /** * Initializing the fcd tables * @param status error status if any */ inline void initializeFCD(UErrorCode *status) { if (FCD_ == NULL) { FCD_ = unorm_getFCDTrie(status); } } /** * Gets the fcd value for a character at the argument index. * This method takes into accounts of the supplementary characters. * @param str UTF16 string where character for fcd retrieval resides * @param offset position of the character whose fcd is to be retrieved, to be * overwritten with the next character position, taking * surrogate characters into consideration. * @param strlength length of the argument string * @return fcd value */ inline uint16_t getFCD(const UChar *str, UTextOffset *offset, int32_t strlength) { UTextOffset temp = *offset; uint16_t result; UChar ch = str[temp]; result = unorm_getFCD16(FCD_, ch); temp ++; if (result && temp != strlength && UTF_IS_FIRST_SURROGATE(ch)) { ch = str[temp]; if (UTF_IS_SECOND_SURROGATE(ch)) { result = unorm_getFCD16FromSurrogatePair(FCD_, result, ch); temp ++; } else { result = 0; } } *offset = temp; return result; } /** * Getting the modified collation elements taking into account the collation * attributes * @param strsrch string search data * @param sourcece * @return the modified collation element */ inline uint32_t getCE(const UStringSearch *strsrch, uint32_t sourcece) { // note for tertiary we can't use the collator->tertiaryMask, that // is a preprocessed mask that takes into account case options. since // we are only concerned with exact matches, we don't need that. sourcece &= strsrch->ceMask; if (strsrch->toShift) { // alternate handling here, since only the 16 most significant digits // is only used, we can safely do a compare without masking // if the ce is a variable, we mask and get only the primary values // no shifting to quartenary is required since all primary values // less than variabletop will need to be masked off anyway. if (strsrch->variableTop > sourcece) { if (strsrch->strength == UCOL_QUATERNARY) { sourcece &= UCOL_PRIMARYORDERMASK; } else { sourcece = UCOL_IGNORABLE; } } } return sourcece; } /** * Allocate a memory and returns NULL if it failed * @param size to allocate * @param status error status if any * @return newly allocated array, NULL otherwise */ inline void * allocateMemory(uint32_t size, UErrorCode *status) { uint32_t *result = (uint32_t *)uprv_malloc(size); if (result == NULL) { *status = U_MEMORY_ALLOCATION_ERROR; } return result; } /** * Adds a uint32_t value to a destination array. * Creates a new array if we run out of space. The caller will have to * manually deallocate the newly allocated array. * @param destination target array * @param offset destination offset to add value * @param destinationlength target array size, return value for the new size * @param value to be added * @param increments incremental size expected * @param status error status if any * @return new destination array, destination if there was no new allocation */ inline uint32_t * addTouint32_tArray(uint32_t *destination, uint32_t offset, uint32_t *destinationlength, uint32_t value, uint32_t increments, UErrorCode *status) { if (U_FAILURE(*status)) { return NULL; } uint32_t newlength = *destinationlength; if (offset + 1 == newlength) { newlength += increments; uint32_t *temp = (uint32_t *)allocateMemory( sizeof(uint32_t) * newlength, status); if (temp == NULL) { return NULL; } uprv_memcpy(temp, destination, sizeof(uint32_t) * offset); *destinationlength = newlength; destination = temp; } destination[offset] = value; return destination; } /** * Initializing the ce table for a pattern. * Stores non-ignorable collation keys. * Table size will be estimated by the size of the pattern text. Table * expansion will be perform as we go along. Adding 1 to ensure that the table * size definitely increases. * @param strsrch string search data * @param status error status if any * @return total number of expansions */ inline uint16_t initializePatternCETable(UStringSearch *strsrch, UErrorCode *status) { if (U_SUCCESS(*status)) { UPattern *pattern = &(strsrch->pattern); uint32_t cetablesize = INITIAL_ARRAY_SIZE_; uint32_t *cetable = pattern->CEBuffer; uint32_t patternlength = pattern->textLength; UCollationElements *coleiter = strsrch->utilIter; if (coleiter == NULL) { coleiter = ucol_openElements(strsrch->collator, pattern->text, patternlength, status); strsrch->utilIter = coleiter; } else { init_collIterate(strsrch->collator, pattern->text, pattern->textLength, &coleiter->iteratordata_); } if (pattern->CE != cetable && pattern->CE) { uprv_free(pattern->CE); } uint16_t offset = 0; uint16_t result = 0; uint32_t ce; while ((ce = ucol_next(coleiter, status)) != UCOL_NULLORDER) { uint32_t newce = getCE(strsrch, ce); if (newce) { uint32_t *temp = addTouint32_tArray(cetable, offset, &cetablesize, newce, patternlength - ucol_getOffset(coleiter) + 1, status); if (U_FAILURE(*status)) { return 0; } offset ++; if (cetable != temp && cetable != pattern->CEBuffer) { uprv_free(cetable); } cetable = temp; } result += ucol_getMaxExpansion(coleiter, ce) - 1; } cetable[offset] = 0; pattern->CE = cetable; pattern->CELength = offset; return result; } return 0; } /** * Initializes the pattern struct * @param strsrch UStringSearch data storage * @param splitsize array of size 2 containing * 1) the total number of characters from start to * the last base character, including any contracting * accents of the last base character. * 2) the total number of characters from the * the first base character, to the end, including any * contracting accents of the first base character. * @param status for errors if it occurs * @return expansionsize the total expansion size of the pattern */ inline int16_t initializePattern(UStringSearch *strsrch, UErrorCode *status) { UPattern *pattern = &(strsrch->pattern); const UChar *patterntext = pattern->text; int32_t length = pattern->textLength; UTextOffset index = 0; pattern->hasPrefixAccents = getFCD(patterntext, &index, length) >> SECOND_LAST_BYTE_SHIFT_; index = length; UTF_BACK_1(patterntext, 0, index); pattern->hasSuffixAccents = getFCD(patterntext, &index, length) & LAST_BYTE_MASK_; return initializePatternCETable(strsrch, status); } /** * Initializing shift tables, with the default values. * If a corresponding default value is 0, the shift table is not set. * @param shift table for forwards shift * @param backshift table for backwards shift * @param cetable table containing pattern ce * @param cesize size of the pattern ces * @param expansionsize total size of the expansions * @param defaultforward the default forward value * @param defaultbackward the default backward value */ inline void setShiftTable(int16_t shift[], int16_t backshift[], uint32_t *cetable, int32_t cesize, int16_t expansionsize, int16_t defaultforward, int16_t defaultbackward) { // estimate the value to shift. to do that we estimate the smallest // number of characters to give the relevant ces, ie approximately // the number of ces minus their expansion, since expansions can come // from a character. int32_t count; for (count = 0; count < MAX_TABLE_SIZE_; count ++) { shift[count] = defaultforward; } cesize --; // down to the last index for (count = 0; count < cesize; count ++) { // number of ces from right of array to the count int temp = defaultforward - count - 1; shift[hash(cetable[count])] = temp > 1 ? temp : 1; } shift[hash(cetable[cesize])] = 1; // for ignorables we just shift by one. see test examples. shift[hash(0)] = 1; for (count = 0; count < MAX_TABLE_SIZE_; count ++) { backshift[count] = defaultbackward; } for (count = cesize; count > 0; count --) { // the original value count does not seem to work backshift[hash(cetable[count])] = count > expansionsize ? count - expansionsize : 1; } backshift[hash(cetable[0])] = 1; backshift[hash(0)] = 1; } /** * Building of the pattern collation element list and the boyer moore strsrch * table. * The canonical match will only be performed after the default match fails. * For both cases we need to remember the size of the composed and decomposed * versions of the string. Since the Boyer-Moore shift calculations shifts by * a number of characters in the text and tries to match the pattern from that * offset, the shift value can not be too large in case we miss some * characters. To choose a right shift size, we estimate the NFC form of the * and use its size as a shift guide. The NFC form should be the small * possible representation of the pattern. Anyways, we'll err on the smaller * shift size. Hence the calculation for minlength. * Canonical match will be performed slightly differently. We'll split the * pattern into 3 parts, the prefix accents (PA), the middle string bounded by * the first and last base character (MS), the ending accents (EA). Matches * will be done on MS first, and only when we match MS then some processing * will be required for the prefix and end accents in order to determine if * they match PA and EA. Hence the default shift values * for the canonical match will take the size of either end's accent into * consideration. Forwards search will take the end accents into consideration * for the default shift values and the backwards search will take the prefix * accents into consideration. * If pattern has no non-ignorable ce, we return a illegal argument error. * @param strsrch UStringSearch data storage * @param status for errors if it occurs */ inline void initialize(UStringSearch *strsrch, UErrorCode *status) { int16_t expandlength = initializePattern(strsrch, status); if (U_SUCCESS(*status) && strsrch->pattern.CELength > 0) { UPattern *pattern = &strsrch->pattern; int32_t cesize = pattern->CELength; int16_t minlength = cesize > expandlength ? cesize - expandlength : 1; pattern->defaultShiftSize = minlength; setShiftTable(pattern->shift, pattern->backShift, pattern->CE, cesize, expandlength, minlength, minlength); } else { strsrch->pattern.defaultShiftSize = 0; } } /** * Determine whether the target text in UStringSearch bounded by the offset * start and end is one or more whole units of text as * determined by the breakiterator in UStringSearch. * @param strsrch string search data * @param start target text start offset * @param end target text end offset */ inline UBool isBreakUnit(const UStringSearch *strsrch, UTextOffset start, UTextOffset end) { UBreakIterator *breakiterator = strsrch->search->breakIter; if (breakiterator) { UTextOffset startindex = ubrk_first(breakiterator); UTextOffset endindex = ubrk_last(breakiterator); // out-of-range indexes are never boundary positions if (start < startindex || start > endindex || end < startindex || end > endindex) { return FALSE; } // otherwise, we can use following() on the position before the // specified one and return true of the position we get back is the // one the user specified return (start == startindex || ubrk_following(breakiterator, start - 1) == start) && (end == endindex || ubrk_following(breakiterator, end - 1) == end); } return TRUE; } /** * Getting the next base character offset if current offset is an accent, * or the current offset if the current character contains a base character. * accents the following base character will be returned * @param text string * @param textoffset current offset * @param textlength length of text string * @return the next base character or the current offset * if the current character is contains a base character. */ inline UTextOffset getNextBaseOffset(const UChar *text, UTextOffset textoffset, int32_t textlength) { if (textoffset < textlength) { UTextOffset temp = textoffset; if (getFCD(text, &temp, textlength) >> SECOND_LAST_BYTE_SHIFT_) { while (temp < textlength) { UTextOffset result = temp; if ((getFCD(text, &temp, textlength) >> SECOND_LAST_BYTE_SHIFT_) == 0) { return result; } } return textlength; } } return textoffset; } /** * Gets the next base character offset depending on the string search pattern * data * @param strsrch string search data * @param textoffset current offset, one offset away from the last character * to search for. * @return start index of the next base character or the current offset * if the current character is contains a base character. */ inline UTextOffset getNextUStringSearchBaseOffset(UStringSearch *strsrch, UTextOffset textoffset) { if (strsrch->pattern.hasSuffixAccents && textoffset < strsrch->search->textLength) { int32_t textlength = strsrch->search->textLength; UTextOffset temp = textoffset; const UChar *text = strsrch->search->text; UTF_BACK_1(text, 0, temp); if (getFCD(text, &temp, textlength) & LAST_BYTE_MASK_) { return getNextBaseOffset(text, textoffset, textlength); } } return textoffset; } /** * Shifting the collation element iterator position forward to prepare for * a following match. If the last character is a unsafe character, we'll only * shift by 1 to capture contractions, normalization etc. * @param text strsrch string search data * @param textoffset start text position to do search * @param ce the text ce which failed the match. * @param patternceindex index of the ce within the pattern ce buffer which * failed the match * @param status error if any * @return final offset */ inline UTextOffset shiftForward(UStringSearch *strsrch, UTextOffset textoffset, uint32_t ce, int32_t patternceindex, UErrorCode *status) { if (U_SUCCESS(*status)) { if (strsrch->search->isOverlap) { if (textoffset > 0) { textoffset ++; } else { textoffset = strsrch->pattern.defaultShiftSize; } } else { if (ce != UCOL_NULLORDER) { int32_t shift = strsrch->pattern.shift[hash(ce)]; // this is to adjust for characters in the middle of the substring // for matching that failed. int32_t adjust = strsrch->pattern.CELength - patternceindex; if (adjust > 1 && shift >= adjust) { shift -= adjust - 1; } textoffset += shift; } else { textoffset += strsrch->pattern.defaultShiftSize; } } textoffset = getNextUStringSearchBaseOffset(strsrch, textoffset); // check for unsafe characters // * if it is the start or middle of a contraction: to be done after // a initial match is found // * thai or lao base consonant character: similar to contraction // * high surrogate character: similar to contraction // * next character is a accent: shift to the next base character if (textoffset <= strsrch->search->textLength) { ucol_setOffset(strsrch->textIter, textoffset, status); } } return textoffset; } /** * sets match not found * @param strsrch string search data * @param status error status if any */ inline void setMatchNotFound(UStringSearch *strsrch, UErrorCode *status) { strsrch->search->matchedIndex = USEARCH_DONE; strsrch->search->matchedLength = 0; if (strsrch->search->isForwardSearching) { ucol_setOffset(strsrch->textIter, strsrch->search->textLength, status); } else { ucol_setOffset(strsrch->textIter, 0, status); } } /** * Gets the offset to the next safe point in text. * ie. not the middle of a contraction, swappable characters or supplementary * characters. * @param collator collation sata * @param text string to work with * @param textoffset offset in string * @param textlength length of text string * @return offset to the next safe character */ inline UTextOffset getNextSafeOffset(const UCollator *collator, const UChar *text, UTextOffset textoffset, int32_t textlength) { UTextOffset result = textoffset; // first contraction character while (result != textlength && ucol_unsafeCP(text[result], collator)) { result ++; } return result; } /** * This checks for accents in the potential match started with a . * composite character. * This is really painful... we have to check that composite character do not * have any extra accents. We have to normalize the potential match and find * the immediate decomposed character before the match. * The first composite character would have been taken care of by the fcd * checks in checkForwardExactMatch. * This is the slow path after the fcd of the first character and * the last character has been checked by checkForwardExactMatch and we * determine that the potential match has extra non-ignorable preceding * ces. * E.g. looking for \u0301 acute in \u01FA A ring above and acute, * checkExtraMatchAccent should fail since there is a middle ring in \u01FA * Note here that accents checking are slow and cautioned in the API docs. * @param strsrch string search data * @param start index of the potential unfriendly composite character * @param end index of the potential unfriendly composite character * @param status error status if any * @return TRUE if there is non-ignorable accents before at the beginning * of the match, FALSE otherwise. */ UBool checkExtraMatchAccents(const UStringSearch *strsrch, UTextOffset start, UTextOffset end, UErrorCode *status) { UBool result = FALSE; if (strsrch->pattern.hasPrefixAccents) { UTextOffset length = end - start; UTextOffset offset = 0; const UChar *text = strsrch->search->text + start; UTF_FWD_1(text, offset, length); // we are only concerned with the first composite character if (unorm_quickCheck(text, offset, UNORM_NFD, status) == UNORM_NO) { UTextOffset safeoffset = getNextSafeOffset( strsrch->collator, text, 0, length); if (safeoffset != length) { safeoffset ++; } UChar *norm = NULL; UChar buffer[INITIAL_ARRAY_SIZE_]; int32_t size = unorm_normalize(text, safeoffset, UNORM_NFD, 0, buffer, INITIAL_ARRAY_SIZE_, status); if (size >= INITIAL_ARRAY_SIZE_) { norm = (UChar *)allocateMemory((size + 1) * sizeof(UChar), status); if (norm == NULL) { return TRUE; } size = unorm_normalize(text, safeoffset, UNORM_NFD, 0, norm, size, status); } else { norm = buffer; } UCollationElements *coleiter = strsrch->utilIter; ucol_setText(coleiter, norm, size, status); uint32_t firstce = strsrch->pattern.CE[0]; UBool ignorable = TRUE; uint32_t ce = UCOL_IGNORABLE; while (U_SUCCESS(*status) && ce != firstce) { offset = ucol_getOffset(coleiter); if (ce != firstce && ce != UCOL_IGNORABLE) { ignorable = FALSE; } ce = ucol_next(coleiter, status); } UChar32 codepoint; UTF_PREV_CHAR(norm, 0, offset, codepoint); result = !ignorable && (u_getCombiningClass(codepoint) != 0); if (norm != buffer) { uprv_free(norm); } } } return result; } /** * Used by exact matches, checks if there are accents before the match. * This is really painful... we have to check that composite characters at * the start of the matches have to not have any extra accents. * We check the FCD of the character first, if it starts with an accent and * the first pattern ce does not match the first ce of the character, we bail. * Otherwise we try normalizing the first composite * character and find the immediate decomposed character before the match to * see if it is an non-ignorable accent. * Now normalizing the first composite character is enough because we ensure * that when the match is passed in here with extra beginning ces, the * first or last ce that match has to occur within the first character. * E.g. looking for \u0301 acute in \u01FA A ring above and acute, * checkExtraMatchAccent should fail since there is a middle ring in \u01FA * Note here that accents checking are slow and cautioned in the API docs. * @param strsrch string search data * @param start offset * @param end offset * @return TRUE if there are accents on either side of the match, * FALSE otherwise */ UBool hasAccentsBeforeMatch(const UStringSearch *strsrch, UTextOffset start, UTextOffset end) { if (strsrch->pattern.hasPrefixAccents) { UCollationElements *coleiter = strsrch->textIter; UErrorCode status = U_ZERO_ERROR; // we have been iterating forwards previously uint32_t ignorable = TRUE; uint32_t firstce = strsrch->pattern.CE[0]; ucol_setOffset(coleiter, start, &status); uint32_t ce = getCE(strsrch, ucol_next(coleiter, &status)); while (ce != firstce) { if (ce != UCOL_IGNORABLE) { ignorable = FALSE; } ce = getCE(strsrch, ucol_next(coleiter, &status)); if (U_FAILURE(status)) { return TRUE; } } if (!ignorable && inNormBuf(coleiter)) { // within normalization buffer, discontiguous handled here return TRUE; } // within text UTextOffset temp = start; UBool accent = (getFCD(strsrch->search->text, &temp, strsrch->search->textLength) >> SECOND_LAST_BYTE_SHIFT_); if (!accent) { return checkExtraMatchAccents(strsrch, start, end, &status); } if (!ignorable) { return TRUE; } if (start > 0) { temp = start; UTF_BACK_1(strsrch->search->text, 0, temp); if (getFCD(strsrch->search->text, &temp, strsrch->search->textLength) & LAST_BYTE_MASK_) { ucol_setOffset(coleiter, start, &status); ce = ucol_previous(coleiter, &status); if (U_FAILURE(status) || (ce != UCOL_NULLORDER && ce != UCOL_IGNORABLE)) { return TRUE; } } } } return FALSE; } /** * Used by exact matches, checks if there are accents bounding the match. * Note this is the initial boundary check. If the potential match * starts or ends with composite characters, the accents in those * characters will be determined later. * Not doing backwards iteration here, since discontiguos contraction for * backwards collation element iterator, use up too many characters. * E.g. looking for \u030A ring in \u01FA A ring above and acute, * should fail since there is a acute at the end of \u01FA * Note here that accents checking are slow and cautioned in the API docs. * @param strsrch string search data * @param start offset of match * @param end end offset of the match * @return TRUE if there are accents on either side of the match, * FALSE otherwise */ UBool hasAccentsAfterMatch(const UStringSearch *strsrch, UTextOffset start, UTextOffset end) { if (strsrch->pattern.hasSuffixAccents) { const UChar *text = strsrch->search->text; UTextOffset temp = end; int32_t textlength = strsrch->search->textLength; UTF_BACK_1(text, 0, temp); if (getFCD(text, &temp, textlength) & LAST_BYTE_MASK_) { uint32_t firstce = strsrch->pattern.CE[0]; UCollationElements *coleiter = strsrch->textIter; UErrorCode status = U_ZERO_ERROR; ucol_setOffset(coleiter, start, &status); while (getCE(strsrch, ucol_next(coleiter, &status)) != firstce) { if (U_FAILURE(status)) { return TRUE; } } int32_t count = 1; while (count < strsrch->pattern.CELength) { ucol_next(coleiter, &status); if (U_FAILURE(status)) { return TRUE; } count ++; } uint32_t ce = getCE(strsrch, ucol_next(coleiter, &status)); if (ce != UCOL_NULLORDER && ce != UCOL_IGNORABLE) { if (ucol_getOffset(coleiter) <= end) { return TRUE; } if (getFCD(text, &end, textlength) >> SECOND_LAST_BYTE_SHIFT_) { return TRUE; } } } } return FALSE; } /** * Checks if the offset runs out of the text string * @param offset * @param textlength of the text string * @return TRUE if offset is out of bounds, FALSE otherwise */ inline UBool isOutOfBounds(int32_t textlength, UTextOffset offset) { return offset < 0 || offset > textlength; } /** * Checks for identical match * @param strsrch string search data * @param start offset of possible match * @param end offset of possible match * @return TRUE if identical match is found */ inline UBool checkIdentical(const UStringSearch *strsrch, UTextOffset start, UTextOffset end) { int32_t length = end - start; if (strsrch->strength != UCOL_IDENTICAL) { return TRUE; } if (strsrch->pattern.textLength != length) { return FALSE; } return (uprv_memcmp(strsrch->pattern.text, strsrch->search->text + start, length * sizeof(UChar)) == 0); } /** * Checks to see if the match is repeated * @param strsrch string search data * @param start new match start index * @param end new match end index * @return TRUE if the the match is repeated, FALSE otherwise */ inline UBool checkRepeatedMatch(UStringSearch *strsrch, UTextOffset start, UTextOffset end) { UTextOffset lastmatchindex = strsrch->search->matchedIndex; UBool result; if (lastmatchindex == USEARCH_DONE) { return FALSE; } if (strsrch->search->isForwardSearching) { result = start <= lastmatchindex; } else { result = start >= lastmatchindex; } if (!strsrch->search->isOverlap) { if (strsrch->search->isForwardSearching) { result = start < lastmatchindex + strsrch->search->matchedLength; } else { result = end > lastmatchindex; } } return result; } /** * Gets the collation element iterator's current offset. * @param coleiter collation element iterator * @param forwards flag TRUE if we are moving in th forwards direction * @return current offset */ inline UTextOffset getColElemIterOffset(const UCollationElements *coleiter, UBool forwards) { UTextOffset result = ucol_getOffset(coleiter); // intricacies of the the backwards collation element iterator if (!forwards && inNormBuf(coleiter) && !isFCDPointerNull(coleiter)) { result ++; } return result; } /** * Checks match for contraction. * If the match ends with a partial contraction we fail. * If the match starts too far off (because of backwards iteration) we try to * chip off the extra characters * @param strsrch string search data * @param start offset of potential match, to be modified if necessary * @param end offset of potential match, to be modified if necessary * @param status error status if any * @return TRUE if match passes the contraction test, FALSE otherwise */ UBool checkNextExactContractionMatch(UStringSearch *strsrch, UTextOffset *start, UTextOffset *end, UErrorCode *status) { UCollationElements *coleiter = strsrch->textIter; int32_t textlength = strsrch->search->textLength; UTextOffset temp = *start; const UCollator *collator = strsrch->collator; const UChar *text = strsrch->search->text; // This part checks if either ends of the match contains potential // contraction. If so we'll have to iterate through them if ((*end < textlength && ucol_unsafeCP(text[*end], collator)) || (*start < textlength && ucol_unsafeCP(text[*start + 1], collator))) { int32_t expansion = getExpansionPrefix(coleiter); UBool expandflag = expansion > 0; ucol_setOffset(coleiter, *start, status); while (expansion > 0) { // getting rid of the redundant ce, caused by setOffset. // since backward contraction/expansion may have extra ces if we // are in the normalization buffer, hasAccentsBeforeMatch would // have taken care of it. // E.g. the character \u01FA will have an expansion of 3, but if // we are only looking for acute and ring \u030A and \u0301, we'll // have to skip the first ce in the expansion buffer. ucol_next(coleiter, status); if (ucol_getOffset(coleiter) != temp) { *start = temp; temp = ucol_getOffset(coleiter); } expansion --; } uint32_t *patternce = strsrch->pattern.CE; int32_t patterncelength = strsrch->pattern.CELength; int32_t count = 0; while (count < patterncelength) { uint32_t ce = getCE(strsrch, ucol_next(coleiter, status)); if (ce == UCOL_IGNORABLE) { continue; } if (expandflag && count == 0 && ucol_getOffset(coleiter) != temp) { *start = temp; temp = ucol_getOffset(coleiter); } if (U_FAILURE(*status) || ce != patternce[count]) { (*end) ++; *end = getNextUStringSearchBaseOffset(strsrch, *end); return FALSE; } count ++; } } return TRUE; } /** * Checks and sets the match information if found. * Checks *