diff --git a/src/openrct2-ui/TextComposition.cpp b/src/openrct2-ui/TextComposition.cpp index 834ab3bd68..1306940c0d 100644 --- a/src/openrct2-ui/TextComposition.cpp +++ b/src/openrct2-ui/TextComposition.cpp @@ -18,8 +18,7 @@ #include #include #include -#include -#include +#include #ifdef __MACOSX__ // macOS uses COMMAND rather than CTRL for many keyboard shortcuts diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index 20601dad3d..c1eb790659 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index 99c0243096..5e74726f5a 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -14,8 +14,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/src/openrct2/core/String.cpp b/src/openrct2/core/String.cpp index 9b8b77e250..f60f73ee95 100644 --- a/src/openrct2/core/String.cpp +++ b/src/openrct2/core/String.cpp @@ -13,6 +13,7 @@ #include #include #include + #ifndef _WIN32 # if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) # include @@ -20,19 +21,15 @@ # include # include # include -#endif - -#ifdef _WIN32 +#else # include #endif -#include "../common.h" -#include "../localisation/ConversionTables.h" -#include "../localisation/Language.h" #include "../util/Util.h" #include "Memory.hpp" #include "String.hpp" #include "StringBuilder.h" +#include "UTF8.h" #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) # include diff --git a/src/openrct2/localisation/UTF8.cpp b/src/openrct2/core/UTF8.cpp similarity index 98% rename from src/openrct2/localisation/UTF8.cpp rename to src/openrct2/core/UTF8.cpp index bd5df3326f..834d4569d3 100644 --- a/src/openrct2/localisation/UTF8.cpp +++ b/src/openrct2/core/UTF8.cpp @@ -7,8 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include "Language.h" -#include "Localisation.h" +#include "UTF8.h" #include #include diff --git a/src/openrct2/core/UTF8.h b/src/openrct2/core/UTF8.h new file mode 100644 index 0000000000..6d38fb6821 --- /dev/null +++ b/src/openrct2/core/UTF8.h @@ -0,0 +1,48 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "String.hpp" + +uint32_t UTF8GetNext(const utf8* char_ptr, const utf8** nextchar_ptr); +bool UTF8IsCodepointStart(const utf8* text); +int32_t UTF8GetCodepointLength(char32_t codepoint); +int32_t UTF8Length(const utf8* text); + +utf8* GetStringEnd(const utf8* text); +size_t GetStringSize(const utf8* text); + +constexpr utf8* UTF8WriteCodepoint(utf8* dst, uint32_t codepoint) +{ + if (codepoint <= 0x7F) + { + dst[0] = static_cast(codepoint); + return dst + 1; + } + if (codepoint <= 0x7FF) + { + dst[0] = 0xC0 | ((codepoint >> 6) & 0x1F); + dst[1] = 0x80 | (codepoint & 0x3F); + return dst + 2; + } + if (codepoint <= 0xFFFF) + { + dst[0] = 0xE0 | ((codepoint >> 12) & 0x0F); + dst[1] = 0x80 | ((codepoint >> 6) & 0x3F); + dst[2] = 0x80 | (codepoint & 0x3F); + return dst + 3; + } + + dst[0] = 0xF0 | ((codepoint >> 18) & 0x07); + dst[1] = 0x80 | ((codepoint >> 12) & 0x3F); + dst[2] = 0x80 | ((codepoint >> 6) & 0x3F); + dst[3] = 0x80 | (codepoint & 0x3F); + return dst + 4; +} diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index 15d97d274c..583e7b7bd8 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -11,6 +11,7 @@ #include "../common.h" #include "../config/Config.h" #include "../core/String.hpp" +#include "../core/UTF8.h" #include "../drawing/IDrawingContext.h" #include "../drawing/IDrawingEngine.h" #include "../drawing/Text.h" diff --git a/src/openrct2/drawing/Font.cpp b/src/openrct2/drawing/Font.cpp index 846b14a018..c1c3a3829c 100644 --- a/src/openrct2/drawing/Font.cpp +++ b/src/openrct2/drawing/Font.cpp @@ -9,8 +9,9 @@ #include "Font.h" +#include "../Diagnostic.h" +#include "../core/UTF8.h" #include "../localisation/FormatCodes.h" -#include "../localisation/Language.h" #include "../localisation/LocalisationService.h" #include "../sprites.h" #include "../util/Util.h" diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index 60abc85e12..d89e151dc5 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -9,6 +9,7 @@ #include "Text.h" +#include "../core/UTF8.h" #include "../localisation/Formatter.h" #include "../localisation/Formatting.h" #include "../localisation/Localisation.h" diff --git a/src/openrct2/interface/Chat.cpp b/src/openrct2/interface/Chat.cpp index 4eb2bef613..9926121875 100644 --- a/src/openrct2/interface/Chat.cpp +++ b/src/openrct2/interface/Chat.cpp @@ -12,6 +12,7 @@ #include "../Context.h" #include "../audio/AudioMixer.h" #include "../audio/audio.h" +#include "../core/UTF8.h" #include "../drawing/Drawing.h" #include "../drawing/Text.h" #include "../localisation/Formatter.h" diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index d35b0a480b..086cc815e9 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -225,6 +225,7 @@ + @@ -752,6 +753,7 @@ + @@ -820,7 +822,6 @@ - diff --git a/src/openrct2/localisation/Language.h b/src/openrct2/localisation/Language.h index 1dff93dc8a..d9bbff487a 100644 --- a/src/openrct2/localisation/Language.h +++ b/src/openrct2/localisation/Language.h @@ -96,40 +96,7 @@ uint8_t LanguageGetIDFromLocale(const char* locale); const char* LanguageGetString(StringId id); bool LanguageOpen(int32_t id); -uint32_t UTF8GetNext(const utf8* char_ptr, const utf8** nextchar_ptr); -bool UTF8IsCodepointStart(const utf8* text); -int32_t UTF8GetCodepointLength(char32_t codepoint); -int32_t UTF8Length(const utf8* text); - std::string RCT2StringToUTF8(std::string_view src, RCT2LanguageId languageId); bool LanguageGetLocalisedScenarioStrings(const utf8* scenarioFilename, StringId* outStringIds); void LanguageFreeObjectString(StringId stringId); StringId LanguageAllocateObjectString(const std::string& target); - -constexpr utf8* UTF8WriteCodepoint(utf8* dst, uint32_t codepoint) -{ - if (codepoint <= 0x7F) - { - dst[0] = static_cast(codepoint); - return dst + 1; - } - if (codepoint <= 0x7FF) - { - dst[0] = 0xC0 | ((codepoint >> 6) & 0x1F); - dst[1] = 0x80 | (codepoint & 0x3F); - return dst + 2; - } - if (codepoint <= 0xFFFF) - { - dst[0] = 0xE0 | ((codepoint >> 12) & 0x0F); - dst[1] = 0x80 | ((codepoint >> 6) & 0x3F); - dst[2] = 0x80 | (codepoint & 0x3F); - return dst + 3; - } - - dst[0] = 0xF0 | ((codepoint >> 18) & 0x07); - dst[1] = 0x80 | ((codepoint >> 12) & 0x3F); - dst[2] = 0x80 | ((codepoint >> 6) & 0x3F); - dst[3] = 0x80 | (codepoint & 0x3F); - return dst + 4; -} diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index 12c863b897..4b5a553b26 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -26,9 +26,6 @@ void FormatReadableSize(char* buf, size_t bufSize, uint64_t sizeBytes); */ void FormatReadableSpeed(char* buf, size_t bufSize, uint64_t sizeBytesPerSec); -utf8* GetStringEnd(const utf8* text); -size_t GetStringSize(const utf8* text); - // The maximum number of characters allowed for string/money conversions (anything above will risk integer overflow issues) constexpr size_t kMoneyStringMaxlength = 14; money64 StringToMoney(const char* string_to_monetise); diff --git a/src/openrct2/network/DiscordService.cpp b/src/openrct2/network/DiscordService.cpp index ccfe7f095e..9cc8ed98fe 100644 --- a/src/openrct2/network/DiscordService.cpp +++ b/src/openrct2/network/DiscordService.cpp @@ -15,8 +15,8 @@ # include "../OpenRCT2.h" # include "../core/Console.hpp" # include "../core/String.hpp" +# include "../core/UTF8.h" # include "../localisation/Formatting.h" -# include "../localisation/Localisation.h" # include "../world/Park.h" # include "network.h" diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 05320a6d98..158e4cd541 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -14,8 +14,8 @@ #include "../../config/Config.h" #include "../../core/Numerics.hpp" #include "../../core/String.hpp" +#include "../../core/UTF8.h" #include "../../interface/Viewport.h" -#include "../../localisation/Formatter.h" #include "../../localisation/Formatting.h" #include "../../localisation/Localisation.h" #include "../../localisation/StringIds.h" diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 0f18aacac5..1c6dd305a0 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -12,9 +12,8 @@ #include "../common.h" #include "../core/Guard.hpp" #include "../core/Path.hpp" +#include "../core/UTF8.h" #include "../interface/Window.h" -#include "../localisation/Language.h" -#include "../localisation/Localisation.h" #include "../platform/Platform.h" #include "../scenes/title/TitleScene.h" #include "zlib.h"