See the following example code. The UStringSearch iterator misses the pattern
when searching backwards. From stepping through the code, it seems that this is
because the pattern.defaultShiftSize is 2, so the test for matches falls in the
middle of the matching part of the target.
ie, in this case:
ta != ::
da != ::
...
it != ::
:b != ::
y: != ::
etc. If 1 char is appended to the target string (and the length adjusted to 23
in the call to usearch_openFromCollator()) the match succeeds.
:; cat usr.c
#include <stdio.h>
#include <unicode/utypes.h>
#include <unicode/ustring.h>
#include <unicode/ucol.h>
#include <unicode/usearch.h>
int main(int argc, char **argv) {
UCollator *coll;
UErrorCode ec;
UChar usrcstr[32], value[2];
UStringSearch *search;
int32_t pos= -1;
int first = (argc==1);
ec=U_ZERO_ERROR;
coll=ucol_open("en_GB", &ec);
if (U_FAILURE(ec)) {
printf("ucol_open failed: %s\n", u_errorName(ec));
exit(-1);
}
u_uastrcpy(usrcstr, "QBitArray::bitarr_data");
u_uastrcpy(value, "::");
ec=U_ZERO_ERROR;
ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_PRIMARY, &ec);
ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_ON, &ec);
ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE,
&ec);
search=usearch_openFromCollator(value, 2, usrcstr, 22, coll, NULL,
&ec);
if(U_FAILURE(ec)) {
printf("usearch_openFromCollator failed: %s\n",
u_errorName(ec));
exit(-1);
}
if(first) {
pos=usearch_first(search, &ec);
} else {
pos=usearch_last(search, &ec);
}
printf("pos is %d\n", pos);
exit(0);
}
:; ./usr
pos is 9
:; ./usr a
pos is -1