public final boolean addStringCaseClosure ( String s , UnicodeSet set ) { int i , length , start , limit , result , unfoldOffset , unfoldRows , unfoldRowWidth , unfoldStringWidth ; if ( unfold == null || s == null ) { return false ; /* no reverse case folding data, or no string */ } length = s . length ( ) ; if ( length <= 1 ) { /* the string is too short to find any match */ /* * more precise would be: * if(!u_strHasMoreChar32Than(s, length, 1)) * but this does not make much practical difference because * a single supplementary code point would just not be found */ return false ; } unfoldRows = unfold [ UNFOLD_ROWS ] ; unfoldRowWidth = unfold [ UNFOLD_ROW_WIDTH ] ; unfoldStringWidth = unfold [ UNFOLD_STRING_WIDTH ] ; //unfoldCPWidth=unfoldRowWidth-unfoldStringWidth; if ( length > unfoldStringWidth ) { /* the string is too long to find any match */ return false ; } /* do a binary search for the string */ start = 0 ; limit = unfoldRows ; while ( start < limit ) { i = ( start + limit ) / 2 ; unfoldOffset = ( ( i + 1 ) * unfoldRowWidth ) ; // +1 to skip the header values above result = strcmpMax ( s , unfoldOffset , unfoldStringWidth ) ; if ( result == 0 ) { /* found the string: add each code point, and its case closure */ int c ; for ( i = unfoldStringWidth ; i < unfoldRowWidth && unfold [ unfoldOffset + i ] != 0 ; i += UTF16 . getCharCount ( c ) ) { c = UTF16 . charAt ( unfold , unfoldOffset , unfold . length , i ) ; set . add ( c ) ; addCaseClosure ( c , set ) ; } return true ; } else if ( result < 0 ) { limit = i ; } else /* result>0 */ { start = i + 1 ; } } return false ; /* string not found */ }
Maps the string to single code points and adds the associated case closure mappings . The string is mapped to code points if it is their full case folding string . In other words this performs a reverse full case folding and then adds the case closure items of the resulting code points . If the string is found and its closure applied then the string itself is added as well as part of its code points closure .