CoriEngine
Loading...
Searching...
No Matches
UTF.hpp
Go to the documentation of this file.
1#pragma once
2#include <utf8.h>
3
4namespace Cori {
5 namespace Utility {
11 inline std::u32string Utf8ToUtf32(const std::string_view& view) {
12 std::u32string dest;
13
14 if (!view.empty()) {
15 try {
16 dest.reserve(utf8::distance(view.begin(), view.end()));
17 } catch (const utf8::invalid_utf8& e) {
18 CORI_CORE_ERROR_TAGGED({ Logger::Tags::Utility::Self, Logger::Tags::Utility::UTF }, "Failed to convert to UTF-8 to UTF-32, Error: {}", e.what());
19 }
20
21 try {
22 utf8::utf8to32(view.begin(), view.end(), std::back_inserter(dest));
23 } catch (const utf8::invalid_utf8& e) {
24 CORI_CORE_ERROR_TAGGED({ Logger::Tags::Utility::Self, Logger::Tags::Utility::UTF }, "Failed to convert to UTF-8 to UTF-32, Error: {}", e.what());
25 dest.clear();
26 }
27 }
28
29 return dest;
30 }
31
37 inline std::u32string Utf8ToUtf32(const std::string& string) {
38 return Utf8ToUtf32(std::string_view(string));
39 }
40 }
41}
#define CORI_CORE_ERROR_TAGGED(...)
Definition Logger.hpp:1039
A namespace for utilities of different kinds.
Definition AABB.hpp:7
std::u32string Utf8ToUtf32(const std::string_view &view)
Converts a UTF-8 variable length encoded string to a UTF-32 fixed length encoded string.
Definition UTF.hpp:11
Global engine namespace.
static constexpr char Self[]
Definition Logger.hpp:150
static constexpr char UTF[]
Definition Logger.hpp:152