Skip to content

Enforce consistent handling of (wx)string encoding - #1808

Merged
sirjuddington merged 6 commits into
masterfrom
string_encoding
Apr 22, 2025
Merged

sirjuddington merged 6 commits into
masterfrom
string_encoding

Conversation

@sirjuddington

Copy link
Copy Markdown
Owner

Essentially we want to be using UTF-8 encoded std::strings everywhere possible (and on all platforms), only converting from/to wxString when dealing with wx functions.

  • Set wxNO_IMPLICIT_WXSTRING_ENCODING to ensure we never implicitly convert from/to wxString (without this it would be very difficult to find everywhere this happens)
  • When converting from std::string to wxString, always use wxString::FromUTF8()
  • When converting from wxString to std::string, always use wxString::utf8_string()
  • When constructing wxString from a string literal, use the wxS() macro around the literal to convert to wchar_t if necessary (on Windows wxString is UTF-16 internally)

This should fix all issues with file paths containing unicode characters (and hopefully stop these reoccurring in the future)

Fix #1765
Fix #1589
Fix #1702

Essentially we want to be using UTF-8 encoded std::strings everywhere possible (and on all platforms), only converting from/to wxString when dealing with wx functions.

- Set wxNO_IMPLICIT_WXSTRING_ENCODING to ensure we never implicitly convert from/to wxString (without this it would be very difficult to find everywhere this happens)
- When converting from std::string to wxString, always use wxString::FromUTF8()
- When converting from wxString to std::string, always use wxString::utf8_string()
- When constructing wxString from a string literal, use the wxS() macro around the literal to convert to wchar_t if necessary (on Windows wxString is UTF-16 internally)

This should fix all issues with file paths containing unicode characters (and hopefully stop these reoccurring in the future)
Using wxNO_IMPLICIT_WXSTRING_ENCODING causes build errors within wx when using wx3.2 for some reason.

Also, apparently wx3.3 adds a string_view version of wxString::FromUTF8, but as it isn't in 3.2 we still need wxutil::strFromView
@sirjuddington
sirjuddington merged commit f858423 into master Apr 22, 2025
@sirjuddington
sirjuddington deleted the string_encoding branch November 3, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot export entries to paths containing unicode Import files doesn't work Wad Problems with letters from different alphabets

1 participant