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

Perform localized comparison on Windows via wstring #40062

Merged
merged 3 commits into from
May 6, 2020

Conversation

jbytheway
Copy link
Contributor

@jbytheway jbytheway commented May 1, 2020

Summary

SUMMARY: None

Purpose of change

On OS X and Windows the existing solution for localized comparison seems to be struggling.

@akirashirosawa found a workaround for OS X. This is intended to be a workaround for Windows. It's necessary because on Windows the locale cannot be assumed to be UTF-8 (indeed, it almost certainly isn't).

Describe the solution

Perform the comparison on std::wstring rather than string, which should sidestep any character encoding issues.

Describe alternatives you've considered

We could do a similar trick with std::u32string, but I suspect that would be poorly supported on Windows.

Testing

I can't test, but @ScampsAdams experiment here suggest that this should work.

@jbytheway jbytheway marked this pull request as draft May 1, 2020 20:29
@jbytheway jbytheway changed the title Perform localized comparison via wstring Perform localized comparison on Windows via wstring May 4, 2020
@jbytheway jbytheway marked this pull request as ready for review May 4, 2020 01:54
@jbytheway
Copy link
Contributor Author

In light of the discussion in #40041 I've updated this PR to apply to Windows only. That looks like it ought to give us the best results there. So I'm marking this one ready for review.

@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Info / User Interface Game - player communication, menus, etc. Translation I18n labels May 4, 2020
@jbytheway jbytheway force-pushed the comparison_via_wstring branch 2 times, most recently from b058dd1 to 5352ff1 Compare May 4, 2020 13:45
@ifreund ifreund added the OS: Windows Issues related to Windows operating system label May 4, 2020
@jbytheway
Copy link
Contributor Author

Added some tests to this PR.

On Windows the existing solution for localized comparison seems to do
the wrong thing, but evidence suggests that comparison of wstring should
work.

Convert the strings before comparison on Windows.

At the same time, do the reverse conversion on MacOS (this won't
actually be used anywhere in the current code, but it seemse a good idea
to implement it while we had the experimental data to suggest it was
necessary.

See CleverRaven#40041 for more discussion.
@ZhilkinSerg ZhilkinSerg merged commit 58a8ed4 into CleverRaven:master May 6, 2020
@jbytheway jbytheway deleted the comparison_via_wstring branch May 7, 2020 00:53
@ScampsAdams
Copy link

It works, case-insensitive. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Info / User Interface Game - player communication, menus, etc. OS: Windows Issues related to Windows operating system Translation I18n
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants