1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Introduce std::string_view into wider use (#14368)

This commit is contained in:
sfan5 2024-02-17 15:35:33 +01:00 committed by GitHub
parent fa47af737f
commit 6ca214fefc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
74 changed files with 501 additions and 456 deletions

View file

@ -57,7 +57,7 @@ void TestCompression::runTests(IGameDef *gamedef)
void TestCompression::testRLECompression()
{
SharedBuffer<u8> fromdata(4);
Buffer<u8> fromdata(4);
fromdata[0]=1;
fromdata[1]=5;
fromdata[2]=5;
@ -106,7 +106,7 @@ void TestCompression::testRLECompression()
void TestCompression::testZlibCompression()
{
SharedBuffer<u8> fromdata(4);
Buffer<u8> fromdata(4);
fromdata[0]=1;
fromdata[1]=5;
fromdata[2]=5;

View file

@ -189,10 +189,9 @@ void TestMapSettingsManager::testMapSettingsManager()
SHA1 ctx;
std::string metafile_contents;
UASSERT(fs::ReadFile(test_mapmeta_path, metafile_contents));
ctx.addBytes(&metafile_contents[0], metafile_contents.size());
unsigned char *sha1_result = ctx.getDigest();
int resultdiff = memcmp(sha1_result, expected_contents_hash, 20);
free(sha1_result);
ctx.addBytes(metafile_contents);
std::string sha1_result = ctx.getDigest();
int resultdiff = memcmp(sha1_result.data(), expected_contents_hash, 20);
UASSERT(!resultdiff);
#endif

View file

@ -240,20 +240,26 @@ void TestUtilities::testPadString()
void TestUtilities::testStartsWith()
{
UASSERT(str_starts_with(std::string(), std::string()) == true);
std::string the("the");
UASSERT(str_starts_with(std::string(), "") == true);
UASSERT(str_starts_with(std::string("the sharp pickaxe"),
std::string()) == true);
UASSERT(str_starts_with(std::string("the sharp pickaxe"),
std::string("the")) == true);
std::string_view(the)) == true);
UASSERT(str_starts_with(std::string("the sharp pickaxe"),
std::string("The")) == false);
UASSERT(str_starts_with(std::string("the sharp pickaxe"),
std::string("The"), true) == true);
UASSERT(str_starts_with(std::string("T"), std::string("The")) == false);
UASSERT(str_starts_with(std::string("T"), "The") == false);
}
void TestUtilities::testStrEqual()
{
std::string foo("foo");
UASSERT(str_equal(foo, std::string_view(foo)));
UASSERT(!str_equal(foo, std::string("bar")));
UASSERT(str_equal(std::string_view(foo), std::string_view(foo)));
UASSERT(str_equal(std::wstring(L"FOO"), std::wstring(L"foo"), true));
UASSERT(str_equal(utf8_to_wide("abc"), utf8_to_wide("abc")));
UASSERT(str_equal(utf8_to_wide("ABC"), utf8_to_wide("abc"), true));
}
@ -629,14 +635,14 @@ void TestUtilities::testBase64()
void TestUtilities::testSanitizeDirName()
{
UASSERT(sanitizeDirName("a", "~") == "a");
UASSERT(sanitizeDirName(" ", "~") == "__");
UASSERT(sanitizeDirName(" a ", "~") == "_a_");
UASSERT(sanitizeDirName("COM1", "~") == "~COM1");
UASSERT(sanitizeDirName("COM1", ":") == "_COM1");
UASSERT(sanitizeDirName("cOm\u00B2", "~") == "~cOm\u00B2");
UASSERT(sanitizeDirName("cOnIn$", "~") == "~cOnIn$");
UASSERT(sanitizeDirName(" cOnIn$ ", "~") == "_cOnIn$_");
UASSERTEQ(auto, sanitizeDirName("a", "~"), "a");
UASSERTEQ(auto, sanitizeDirName(" ", "~"), "__");
UASSERTEQ(auto, sanitizeDirName(" a ", "~"), "_a_");
UASSERTEQ(auto, sanitizeDirName("COM1", "~"), "~COM1");
UASSERTEQ(auto, sanitizeDirName("COM1", ":"), "_COM1");
UASSERTEQ(auto, sanitizeDirName("cOm\u00B2", "~"), "~cOm\u00B2");
UASSERTEQ(auto, sanitizeDirName("cOnIn$", "~"), "~cOnIn$");
UASSERTEQ(auto, sanitizeDirName(" cOnIn$ ", "~"), "_cOnIn$_");
}
template <typename F, typename C>