Experimental cross platform utf8 support.

This commit is contained in:
Zed A. Shaw 2026-04-17 00:45:06 -04:00
parent d6dd68bcef
commit 3d44b7ccc5
3 changed files with 23 additions and 4 deletions

View file

@ -11,7 +11,8 @@ project('lel-guecs', 'cpp',
# use this for common options only for our executables # use this for common options only for our executables
cpp_args=[ cpp_args=[
'-Wno-deprecated-declarations' '-Wno-deprecated-declarations',
'-I../subprojects/utf8cpp-4.0.9/source',
] ]
link_args=[] link_args=[]
# these are passed as override_defaults # these are passed as override_defaults
@ -50,6 +51,7 @@ catch2 = subproject('catch2').get_variable('catch2_with_main_dep')
fmt = subproject('fmt').get_variable('fmt_dep') fmt = subproject('fmt').get_variable('fmt_dep')
json = subproject('nlohmann_json').get_variable('nlohmann_json_dep') json = subproject('nlohmann_json').get_variable('nlohmann_json_dep')
freetype2 = subproject('freetype2').get_variable('freetype_dep') freetype2 = subproject('freetype2').get_variable('freetype_dep')
utf8cpp = subproject('utf8cpp').get_variable('utf8cpp_dep')
flac = subproject('flac').get_variable('flac_dep') flac = subproject('flac').get_variable('flac_dep')
ogg = subproject('ogg').get_variable('libogg_dep') ogg = subproject('ogg').get_variable('libogg_dep')
@ -64,7 +66,7 @@ sfml_window = subproject('sfml').get_variable('sfml_window_dep')
lib_depends = [ fmt, sfml_graphics, sfml_system, sfml_window ] lib_depends = [ fmt, sfml_graphics, sfml_system, sfml_window ]
lib_sfml_depends = [ lib_sfml_depends = [
fmt, json, freetype2, flac, ogg, fmt, json, freetype2, flac, ogg, utf8cpp,
vorbis, vorbisfile, vorbisenc, sfml_audio, vorbis, vorbisfile, vorbisenc, sfml_audio,
] ]

View file

@ -3,6 +3,7 @@
#include <cassert> #include <cassert>
#include <fmt/core.h> #include <fmt/core.h>
#include <iostream> #include <iostream>
#include <utf8.h>
namespace guecs { namespace guecs {
using std::make_shared; using std::make_shared;
@ -237,7 +238,14 @@ namespace guecs {
} }
wstring to_wstring(const string& str) { wstring to_wstring(const string& str) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter; std::wstring result = L"";
return $converter.from_bytes(str);
try {
utf8::utf8to32(str.begin(), str.end(), std::back_inserter(result));
} catch(const utf8::exception& e) {
std::cerr << e.what() << std::endl;
}
return result;
} }
} }

9
wraps/utf8cpp.wrap Normal file
View file

@ -0,0 +1,9 @@
[wrap-git]
directory=utf8cpp-4.0.9
url=https://github.com/nemtrif/utfcpp.git
revision=v4.0.9
depth=1
method=cmake
[provide]
utf8cpp = utf8cpp_dep