mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-23 02:41:58 -05:00
Implement ICU support for uppercasing, with tests.
This commit is contained in:
parent
f29b42cc26
commit
a91dd6a356
3 changed files with 31 additions and 6 deletions
|
@ -111,4 +111,9 @@ namespace String
|
||||||
* Converts a multi-byte string from one code page to another.
|
* Converts a multi-byte string from one code page to another.
|
||||||
*/
|
*/
|
||||||
std::string Convert(const std::string_view& src, sint32 srcCodePage, sint32 dstCodePage);
|
std::string Convert(const std::string_view& src, sint32 srcCodePage, sint32 dstCodePage);
|
||||||
} // namespace String
|
|
||||||
|
/**
|
||||||
|
* Returns an uppercased version of a UTF-8 string.
|
||||||
|
*/
|
||||||
|
std::string ToUpper(const utf8 * src);
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../config/Config.h"
|
#include "../config/Config.h"
|
||||||
#include "../core/Math.hpp"
|
#include "../core/Math.hpp"
|
||||||
|
#include "../core/String.hpp"
|
||||||
#include "../core/Util.hpp"
|
#include "../core/Util.hpp"
|
||||||
#include "Date.h"
|
#include "Date.h"
|
||||||
#include "../Game.h"
|
#include "../Game.h"
|
||||||
|
@ -1215,12 +1216,16 @@ void format_string_to_upper(utf8 *dest, size_t size, rct_string_id format, void
|
||||||
|
|
||||||
format_string(dest, size, format, args);
|
format_string(dest, size, format, args);
|
||||||
|
|
||||||
// Convert to upper case
|
std::string upperString = String::ToUpper(dest);
|
||||||
utf8 *ch = dest;
|
|
||||||
while (*ch != '\0') {
|
if (upperString.size() + 1 >= size) {
|
||||||
*ch = toupper(*ch);
|
upperString.resize(size - 1);
|
||||||
ch++;
|
dest[size - 1] = '\0';
|
||||||
|
log_warning("Truncating formatted string \"%s\" to %d bytes.", dest, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upperString.copy(dest, upperString.size());
|
||||||
|
dest[upperString.size()] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
money32 string_to_money(char * string_to_monetise)
|
money32 string_to_money(char * string_to_monetise)
|
||||||
|
|
|
@ -114,3 +114,18 @@ TEST_F(StringTest, Convert_Empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Tests for String::ToUpper
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
TEST_F(StringTest, ToUpper_Basic)
|
||||||
|
{
|
||||||
|
auto actual = String::ToUpper("test TEST tEsT 1234");
|
||||||
|
ASSERT_STREQ(actual.c_str(), "TEST TEST TEST 1234");
|
||||||
|
}
|
||||||
|
TEST_F(StringTest, ToUpper_Unicode)
|
||||||
|
{
|
||||||
|
auto actual = String::ToUpper("éœǘξдȿ𞥃ꜳᲁ ÉŒǗΞДⱾ𞤡ꜲД 語");
|
||||||
|
ASSERT_STREQ(actual.c_str(), "ÉŒǗΞДⱾ𞤡ꜲД ÉŒǗΞДⱾ𞤡ꜲД 語");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue