string: add recoding from UTF-16 to UTF-32

I know there are system functions for this (and libiconv), but this is
so trivial and quick in our implementation.
This commit is contained in:
2024-09-27 14:11:11 +02:00
parent da11495282
commit 5675f8b139
5 changed files with 70 additions and 1 deletions

View File

@@ -54,6 +54,17 @@ namespace Assert
throw std::runtime_error("not equal");
}
inline void AreEqual(const char32_t* a, const char32_t* b)
{
#ifdef _WIN32
if (stdex::strcmp(a, b) != 0)
throw std::runtime_error("not equal");
#else
if (wcscmp(reinterpret_cast<const wchar_t*>(a), reinterpret_cast<const wchar_t*>(b)) != 0)
throw std::runtime_error("not equal");
#endif
}
template <class T>
void AreNotEqual(const T& a, const T& b)
{

View File

@@ -26,6 +26,7 @@ int main(int, const char *[])
UnitTests::stream::file_stat();
UnitTests::stream::open_close();
UnitTests::stream::replicator();
UnitTests::string::strncpy();
UnitTests::string::sprintf();
UnitTests::unicode::charset_encoder();
UnitTests::unicode::normalize();

View File

@@ -107,6 +107,7 @@ namespace UnitTests
TEST_CLASS(string)
{
public:
TEST_METHOD(strncpy);
TEST_METHOD(sprintf);
};

View File

@@ -12,6 +12,13 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTests
{
void string::strncpy()
{
stdex::utf32_t tmp[0x100];
stdex::strncpy(tmp, u"This is a 🐔Test🐮.");
Assert::AreEqual(reinterpret_cast<const stdex::utf32_t*>(U"This is a 🐔Test🐮."), tmp);
}
void string::sprintf()
{
stdex::locale locale(stdex::create_locale(LC_ALL, "en_US.UTF-8"));