mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Move CSStringConverter from localisation to rct12 folder (#22280)
This commit is contained in:
@@ -38,7 +38,6 @@
|
||||
#include "interface/Screenshot.h"
|
||||
#include "interface/Viewport.h"
|
||||
#include "interface/Window.h"
|
||||
#include "localisation/Localisation.h"
|
||||
#include "management/Finance.h"
|
||||
#include "management/Marketing.h"
|
||||
#include "management/Research.h"
|
||||
@@ -48,6 +47,7 @@
|
||||
#include "object/ObjectList.h"
|
||||
#include "object/WaterEntry.h"
|
||||
#include "platform/Platform.h"
|
||||
#include "rct12/CSStringConverter.h"
|
||||
#include "ride/Ride.h"
|
||||
#include "ride/RideRatings.h"
|
||||
#include "ride/Station.h"
|
||||
|
||||
@@ -282,7 +282,6 @@
|
||||
<ClInclude Include="interface\Window_internal.h" />
|
||||
<ClInclude Include="interface\ZoomLevel.h" />
|
||||
<ClInclude Include="Limits.h" />
|
||||
<ClInclude Include="localisation\ConversionTables.h" />
|
||||
<ClInclude Include="localisation\Currency.h" />
|
||||
<ClInclude Include="localisation\CurrencyTypes.h" />
|
||||
<ClInclude Include="localisation\Date.h" />
|
||||
@@ -388,6 +387,7 @@
|
||||
<ClInclude Include="platform\Platform.h" />
|
||||
<ClInclude Include="profiling\Profiling.h" />
|
||||
<ClInclude Include="profiling\ProfilingMacros.hpp" />
|
||||
<ClInclude Include="rct12\CSStringConverter.h" />
|
||||
<ClInclude Include="rct12\EntryList.h" />
|
||||
<ClInclude Include="rct12\Limits.h" />
|
||||
<ClInclude Include="rct12\RCT12.h" />
|
||||
@@ -811,8 +811,6 @@
|
||||
<ClCompile Include="interface\Window.cpp" />
|
||||
<ClCompile Include="interface\Window_internal.cpp" />
|
||||
<ClCompile Include="interface\ZoomLevel.cpp" />
|
||||
<ClCompile Include="localisation\ConversionTables.cpp" />
|
||||
<ClCompile Include="localisation\Convert.cpp" />
|
||||
<ClCompile Include="localisation\Currency.cpp" />
|
||||
<ClCompile Include="localisation\FormatCodes.cpp" />
|
||||
<ClCompile Include="localisation\Formatter.cpp" />
|
||||
@@ -906,6 +904,7 @@
|
||||
<ClCompile Include="platform\Platform.Posix.cpp" />
|
||||
<ClCompile Include="platform\Platform.Win32.cpp" />
|
||||
<ClCompile Include="profiling\Profiling.cpp" />
|
||||
<ClCompile Include="rct12\CSStringConverter.cpp" />
|
||||
<ClCompile Include="rct12\RCT12.cpp" />
|
||||
<ClCompile Include="rct12\SawyerChunk.cpp" />
|
||||
<ClCompile Include="rct12\SawyerChunkReader.cpp" />
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../core/String.hpp"
|
||||
#include "ConversionTables.h"
|
||||
#include "Language.h"
|
||||
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
|
||||
/**
|
||||
* Decodes an RCT2 string to a wide char string still in the original code page.
|
||||
* An RCT2 string is a multi-byte string where every two-byte code point is preceded with a byte value of 255.
|
||||
*/
|
||||
static std::wstring DecodeToWideChar(std::string_view src)
|
||||
{
|
||||
std::wstring decoded;
|
||||
decoded.reserve(src.size());
|
||||
for (auto it = src.begin(); it != src.end();)
|
||||
{
|
||||
uint8_t c = *it++;
|
||||
if (c == 255)
|
||||
{
|
||||
// Push next two characters
|
||||
uint8_t a = 0;
|
||||
uint8_t b = 0;
|
||||
if (it != src.end())
|
||||
{
|
||||
a = *it++;
|
||||
if (it != src.end())
|
||||
{
|
||||
b = *it++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2nd byte for double byte character is missing
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1st byte for double byte character is missing
|
||||
break;
|
||||
}
|
||||
|
||||
wchar_t cp = (a << 8) | b;
|
||||
decoded.push_back(cp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Push character
|
||||
decoded.push_back(c);
|
||||
}
|
||||
}
|
||||
return decoded;
|
||||
}
|
||||
|
||||
static std::string DecodeToMultiByte(std::string_view src)
|
||||
{
|
||||
auto wide = DecodeToWideChar(src);
|
||||
std::string result;
|
||||
result.reserve(wide.size());
|
||||
for (auto cc : wide)
|
||||
{
|
||||
if (cc <= 255)
|
||||
{
|
||||
result.push_back(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.push_back((cc >> 8) & 0xFF);
|
||||
result.push_back(cc & 0xFF);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int32_t GetCodePageForRCT2Language(RCT2LanguageId languageId)
|
||||
{
|
||||
switch (languageId)
|
||||
{
|
||||
case RCT2LanguageId::Japanese:
|
||||
return OpenRCT2::CodePage::CP_932;
|
||||
case RCT2LanguageId::ChineseSimplified:
|
||||
return OpenRCT2::CodePage::CP_936;
|
||||
case RCT2LanguageId::Korean:
|
||||
return OpenRCT2::CodePage::CP_949;
|
||||
case RCT2LanguageId::ChineseTraditional:
|
||||
return OpenRCT2::CodePage::CP_950;
|
||||
default:
|
||||
return OpenRCT2::CodePage::CP_1252;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TConvertFunc> static std::string DecodeConvertWithTable(std::string_view src, TConvertFunc func)
|
||||
{
|
||||
auto decoded = DecodeToWideChar(src);
|
||||
std::wstring u16;
|
||||
u16.reserve(decoded.size());
|
||||
for (auto cc : decoded)
|
||||
{
|
||||
u16.push_back(func(cc));
|
||||
}
|
||||
return String::ToUtf8(u16);
|
||||
}
|
||||
|
||||
std::string RCT2StringToUTF8(std::string_view src, RCT2LanguageId languageId)
|
||||
{
|
||||
auto codePage = GetCodePageForRCT2Language(languageId);
|
||||
if (codePage == OpenRCT2::CodePage::CP_1252)
|
||||
{
|
||||
// The code page used by RCT2 was not quite 1252 as some codes were used for Polish characters.
|
||||
return DecodeConvertWithTable(src, EncodingConvertRCT2ToUnicode);
|
||||
}
|
||||
|
||||
auto decoded = DecodeToMultiByte(src);
|
||||
return String::ConvertToUtf8(decoded, codePage);
|
||||
}
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "../localisation/StringIdType.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -49,7 +48,7 @@ enum
|
||||
LANGUAGE_COUNT
|
||||
};
|
||||
|
||||
enum class RCT2LanguageId
|
||||
enum class RCT2LanguageId : uint8_t
|
||||
{
|
||||
EnglishUK,
|
||||
EnglishUS,
|
||||
@@ -89,7 +88,6 @@ uint8_t LanguageGetIDFromLocale(const char* locale);
|
||||
const char* LanguageGetString(StringId id);
|
||||
bool LanguageOpen(int32_t id);
|
||||
|
||||
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);
|
||||
|
||||
@@ -13,9 +13,8 @@
|
||||
#include "../core/IStream.hpp"
|
||||
#include "../core/Json.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../localisation/Language.h"
|
||||
#include "../localisation/LanguagePack.h"
|
||||
#include "../localisation/LocalisationService.h"
|
||||
#include "../rct12/CSStringConverter.h"
|
||||
#include "Object.h"
|
||||
|
||||
static constexpr uint8_t RCT2ToOpenRCT2LanguageId[] = {
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "../entity/Staff.h"
|
||||
#include "../interface/Window.h"
|
||||
#include "../localisation/Date.h"
|
||||
#include "../localisation/Localisation.h"
|
||||
#include "../management/Award.h"
|
||||
#include "../management/Finance.h"
|
||||
#include "../management/Marketing.h"
|
||||
@@ -49,6 +48,7 @@
|
||||
#include "../object/ObjectRepository.h"
|
||||
#include "../peep/PeepAnimationData.h"
|
||||
#include "../peep/RideUseSystem.h"
|
||||
#include "../rct12/CSStringConverter.h"
|
||||
#include "../rct12/EntryList.h"
|
||||
#include "../ride/RideData.h"
|
||||
#include "../ride/Station.h"
|
||||
|
||||
@@ -7,12 +7,16 @@
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "ConversionTables.h"
|
||||
#include "CSStringConverter.h"
|
||||
|
||||
#include "FormatCodes.h"
|
||||
#include "../core/String.hpp"
|
||||
#include "../localisation/FormatCodes.h"
|
||||
#include "../localisation/Language.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
|
||||
struct EncodingConvertEntry
|
||||
{
|
||||
@@ -124,3 +128,112 @@ wchar_t EncodingConvertRCT2ToUnicode(wchar_t rct2str)
|
||||
return rct2str;
|
||||
return entry->unicode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes an RCT2 string to a wide char string still in the original code page.
|
||||
* An RCT2 string is a multi-byte string where every two-byte code point is preceded with a byte value of 255.
|
||||
*/
|
||||
static std::wstring DecodeToWideChar(std::string_view src)
|
||||
{
|
||||
std::wstring decoded;
|
||||
decoded.reserve(src.size());
|
||||
for (auto it = src.begin(); it != src.end();)
|
||||
{
|
||||
uint8_t c = *it++;
|
||||
if (c == 255)
|
||||
{
|
||||
// Push next two characters
|
||||
uint8_t a = 0;
|
||||
uint8_t b = 0;
|
||||
if (it != src.end())
|
||||
{
|
||||
a = *it++;
|
||||
if (it != src.end())
|
||||
{
|
||||
b = *it++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2nd byte for double byte character is missing
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1st byte for double byte character is missing
|
||||
break;
|
||||
}
|
||||
|
||||
wchar_t cp = (a << 8) | b;
|
||||
decoded.push_back(cp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Push character
|
||||
decoded.push_back(c);
|
||||
}
|
||||
}
|
||||
return decoded;
|
||||
}
|
||||
|
||||
static std::string DecodeToMultiByte(std::string_view src)
|
||||
{
|
||||
auto wide = DecodeToWideChar(src);
|
||||
std::string result;
|
||||
result.reserve(wide.size());
|
||||
for (auto cc : wide)
|
||||
{
|
||||
if (cc <= 255)
|
||||
{
|
||||
result.push_back(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.push_back((cc >> 8) & 0xFF);
|
||||
result.push_back(cc & 0xFF);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int32_t GetCodePageForRCT2Language(RCT2LanguageId languageId)
|
||||
{
|
||||
switch (languageId)
|
||||
{
|
||||
case RCT2LanguageId::Japanese:
|
||||
return OpenRCT2::CodePage::CP_932;
|
||||
case RCT2LanguageId::ChineseSimplified:
|
||||
return OpenRCT2::CodePage::CP_936;
|
||||
case RCT2LanguageId::Korean:
|
||||
return OpenRCT2::CodePage::CP_949;
|
||||
case RCT2LanguageId::ChineseTraditional:
|
||||
return OpenRCT2::CodePage::CP_950;
|
||||
default:
|
||||
return OpenRCT2::CodePage::CP_1252;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TConvertFunc> static std::string DecodeConvertWithTable(std::string_view src, TConvertFunc func)
|
||||
{
|
||||
auto decoded = DecodeToWideChar(src);
|
||||
std::wstring u16;
|
||||
u16.reserve(decoded.size());
|
||||
for (auto cc : decoded)
|
||||
{
|
||||
u16.push_back(func(cc));
|
||||
}
|
||||
return String::ToUtf8(u16);
|
||||
}
|
||||
|
||||
std::string RCT2StringToUTF8(std::string_view src, RCT2LanguageId languageId)
|
||||
{
|
||||
auto codePage = GetCodePageForRCT2Language(languageId);
|
||||
if (codePage == OpenRCT2::CodePage::CP_1252)
|
||||
{
|
||||
// The code page used by RCT2 was not quite 1252 as some codes were used for Polish characters.
|
||||
return DecodeConvertWithTable(src, EncodingConvertRCT2ToUnicode);
|
||||
}
|
||||
|
||||
auto decoded = DecodeToMultiByte(src);
|
||||
return String::ConvertToUtf8(decoded, codePage);
|
||||
}
|
||||
@@ -9,4 +9,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
enum class RCT2LanguageId : uint8_t;
|
||||
|
||||
wchar_t EncodingConvertRCT2ToUnicode(wchar_t rct2str);
|
||||
|
||||
std::string RCT2StringToUTF8(std::string_view src, RCT2LanguageId languageId);
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
#include "../core/String.hpp"
|
||||
#include "../localisation/Formatting.h"
|
||||
#include "../localisation/Localisation.h"
|
||||
#include "../object/ObjectList.h"
|
||||
#include "../rct1/Tables.h"
|
||||
#include "../rct12/CSStringConverter.h"
|
||||
#include "../rct2/RCT2.h"
|
||||
#include "../ride/Ride.h"
|
||||
#include "../ride/Track.h"
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "../object/ObjectRepository.h"
|
||||
#include "../object/WallSceneryEntry.h"
|
||||
#include "../peep/RideUseSystem.h"
|
||||
#include "../rct12/CSStringConverter.h"
|
||||
#include "../rct12/EntryList.h"
|
||||
#include "../rct12/RCT12.h"
|
||||
#include "../rct12/SawyerChunkReader.h"
|
||||
|
||||
@@ -23,10 +23,9 @@
|
||||
#include "../core/Numerics.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../localisation/Language.h"
|
||||
#include "../localisation/Localisation.h"
|
||||
#include "../localisation/LocalisationService.h"
|
||||
#include "../platform/Platform.h"
|
||||
#include "../rct12/CSStringConverter.h"
|
||||
#include "../rct12/RCT12.h"
|
||||
#include "../rct12/SawyerChunkReader.h"
|
||||
#include "../rct2/RCT2.h"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "helpers/StringHelpers.hpp"
|
||||
#include "openrct2/localisation/Language.h"
|
||||
#include "openrct2/rct12/CSStringConverter.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user