Use ansi codepage for internal multibyte strings on windows (fixes #976, fixes #974, fixes #444) #979
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes debauchee/barrier#976
Fixes debauchee/barrier#974
Fixes debauchee/barrier#444
Probably conflicts with debauchee/barrier#972, but if you accept both PRs then just "ping" me and I can quickly fix it (either if I can merge the PR branches together, or you can merge one of them to master first and I rebase the other one, or something else..?)
I think it makes sense to have these as simple functions.
Pushed an update, but not sure if it was something like this you had in mind, or something else? (and if so, I'm happy to make another attempt)
Pushed another update, because I managed to track down another one of those codepage issues. Refactored the KnowFolderPaths into a header-only, and added another one, StringConverters.h, for windows string conversions (narrow ansi, narrow utf8, and wide). But again, just let me know if you think it would be better doing it differently!
static
is incorrect for functions that are in the headers and are supposed to be reused in many cpp files. In such case there's a separate copy of the function in each translation unit and we rely on the linker to deduplicate.Better to use
inline
.Even better would be to add a .cpp file for the implementations.
The same applies to a header below.
Better than ever? :)
Tracked down a couple of more issues.. There were multiple similar problems, in client, server and deamon, so it took several attempts to track them down and fix them. Not entirely sure all are properly handled yet, I hope so, and think so, but let's wait a little bit and see if @cheese, reporter of debauchee/barrier#974, will agree...
In general I guess the main solution is to be explicit about use of UTF-8 for strings sent over IPC, and to be sure to use current locale encoding (normally "ANSI" on Windows) for std::string's. E.g. QString::toStdString uses UTF-8, which is somewhat annoying (although UTF-8 Everywhere is a thing, its not a short term solution here).
Edit: Wait a minute.. For the QString conversions I can probably use Qt's to/fromLocal8Bit. I considered those before, but wasn't sure they were matching the MultiByte/ANSI/codepage/whatever-you-call-it kind of strings on Windows, but then found this:
Will rewrite (again) and post back...
Done.
QString::fromLocal8Bit
/QString::toLocal8Bit
to convert between (unicode) QString and (locale-specific) std::string, andQString::fromUtf8
/QString:toUtf8
for reading/writing UTF-8 encoded strings for IPC communication. So encoding is quite explicit. Not usingtoStdString
/fromStdString
, since it returns std::string that are UTF-8 encoded and leads to confusion and problems.Unicode::UTF8ToText
/Unicode::textToUTF8
for UTF-8 specific IPC strings (except in this one place, in DataDirectories, since it is in common lib and do not have access to Unicode class in base lib).PS: Would still be nice to see #974 being tested OK, since there were so many iterations with different issues here..
Thanks!