Skip to content

canonical caseless match? #30

Answered by mg152
rowlesmr asked this question in Q&A
Discussion options

You must be logged in to vote

No, it's not the same. The Unicode Standard describes canonical caseless match like this:

A string X is a canonical caseless match for a string Y if and only if:
NFD(toCasefold(NFD(X))) = NFD(toCasefold(NFD(Y)))

So it will look like this with the library:

bool canonical_caseless_match(std::string_view str1, std::string_view str2)
{
    return una::norm::to_nfd_utf8(una::cases::to_casefold_utf8(una::norm::to_nfd_utf8(str1))) ==
           una::norm::to_nfd_utf8(una::cases::to_casefold_utf8(una::norm::to_nfd_utf8(str2)));
}

Of course the performance of this won't be that great. Technically it's possible to implement it better with views but the problem right now the library doesn't have c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mg152
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants