Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new and extend existing til::string helpers #16772

Merged
merged 3 commits into from
Feb 28, 2024

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Feb 27, 2024

wstring_case_insensitive_compare is not a great name for what it
does as it's incorrect to use for regular (human readable) strings.
This PR thus renames it to env_key_sorter.

compare_string_ordinal was renamed to compare_ordinal_insensitive
to make sure callers know that the comparison is insensitive
(this may otherwise be incorrect in certain contexts after all).
The return value was changed to match memcmp so that the API
is detached from its underlying implementation (= NLS).

compare_linguistic_insensitive and contains_linguistic_insensitive
were added to sort and filter human-readable strings respectively.

prefix_split was extended to allow for needles that are just a
single character. This significantly improves the generated assembly
and is also usually what someone would want to actually use.
I've left the string-as-needle variant in just in case.

This PR is prep-work for #2664

@lhecker lhecker added the Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. label Feb 27, 2024
Comment on lines +158 to +162
const auto comparator = [&](const Editor::Font& lhs, const Editor::Font& rhs) {
const auto a = lhs.LocalizedName();
const auto b = rhs.LocalizedName();
return til::compare_linguistic_insensitive(a, b) < 0;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot to mention that this also fixes a minor bug. The < operator on strings is not safe for proper Unicode comparisons. It's based on wmemcmp which tests for binary equivalence, so it neither works for case-sensitive nor case-insensitive comparisons in the context of Unicode. For instance, because a composed and decomposed grapheme doesn't compare equal.

@zadjii-msft zadjii-msft merged commit badc00e into main Feb 28, 2024
20 checks passed
@zadjii-msft zadjii-msft deleted the dev/lhecker/til-string branch February 28, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants