A StringSearch object with its default collator's strength set to
Collator::SECONDARY fails to match a pattern which occurs at the end of the
input string, even if it matches exactly.
For example, the following code sets m_ichMinFound to -1:
StringSearch * m_piter;
UErrorCode m_error = U_ZERO_ERROR;
int m_ichMinFound;
u_setDataDirectory("c:\\fw\\distfiles\\Icu34\\icudt34l"); // Happens to be
where my data lives :-)
u_init(&m_error);
wchar_t * pattern = L"a\xe1"; // L"aá" NFC
wchar_t * searchData = L"aa\xe1"; // L"aaá" NFC
m_piter = new StringSearch(pattern, searchData, Locale::createFromName("en"),
0, m_error);
m_piter->getCollator()->setStrength(Collator::SECONDARY);
m_piter->reset(); // seems to be needed to make MOST cases work after setting
strength
m_ichMinFound = m_piter->first(m_error);
On the other hand, the code works as expected if an additional 'a' is appended
to both strings, setting m_ichMinFound to 1.
It may be that there is a more appropriate way to request matching diacritics
when initializing a StringSeach using a Locale. If so I failed to find it (when
searching the 2.8 docs some time ago). But this approach works for almost all
cases; it seems to me it should either work for all cases or clearly return an
error condition.