diff options
author | crupest <crupest@outlook.com> | 2021-08-12 21:44:32 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-08-12 21:44:32 +0800 |
commit | 2e379441f69c4fd3049d186f76b25457e6250282 (patch) | |
tree | 893771e5103ca9f3a34bb622251aaacb024cf1c2 /include/cru/common/String.hpp | |
parent | d718b0f576aeae1fa853124caefc8b0078f1deed (diff) | |
download | cru-2e379441f69c4fd3049d186f76b25457e6250282.tar.gz cru-2e379441f69c4fd3049d186f76b25457e6250282.tar.bz2 cru-2e379441f69c4fd3049d186f76b25457e6250282.zip |
...
Diffstat (limited to 'include/cru/common/String.hpp')
-rw-r--r-- | include/cru/common/String.hpp | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp index ea9480f0..e779e3a6 100644 --- a/include/cru/common/String.hpp +++ b/include/cru/common/String.hpp @@ -9,21 +9,24 @@ namespace cru { class CRU_BASE_API String { public: - static String fromUtf8(const char* str, Index size); + static String FromUtf8(std::string_view str) { + return FromUtf8(str.data(), str.size()); + } + static String FromUtf8(const char* str, Index size); - static String fromUtf16(const std::uint16_t* str) { return String(str); } - static String fromUtf16(const std::uint16_t* str, Index size) { + static String FromUtf16(const std::uint16_t* str) { return String(str); } + static String FromUtf16(const std::uint16_t* str, Index size) { return String(str, size); } - static String fromUtf16(const char16_t* str) { return String(str); } - static String fromUtf16(const char16_t* str, Index size) { + static String FromUtf16(const char16_t* str) { return String(str); } + static String FromUtf16(const char16_t* str, Index size) { return String(str, size); } #ifdef CRU_PLATFORM_WINDOWS - static String fromUtf16(wchar_t* str) { return String(str); } - static String fromUtf16(wchar_t* str, Index size) { + static String FromUtf16(wchar_t* str) { return String(str); } + static String FromUtf16(wchar_t* str, Index size) { return String(str, size); } #endif @@ -49,10 +52,12 @@ class CRU_BASE_API String { String(const char16_t* str); String(const char16_t* str, Index size); + String(const std::u16string& str) : String(str.data(), str.size()) {} #ifdef CRU_PLATFORM_WINDOWS String(const wchar_t* str); String(const wchar_t* str, Index size); + String(const std::wstring& str) : String(str.data(), str.size()) {} #endif String(const String& other); @@ -121,6 +126,19 @@ class CRU_BASE_API String { this->insert(cend(), str, size); } + public: + const char16_t* Char16CStr() const { + return reinterpret_cast<const char16_t*>(c_str()); + } + +#ifdef CRU_PLATFORM_WINDOWS + const wchar_t* WinCStr() const { + return reinterpret_cast<const wchar_t*>(c_str()); + } +#endif + + std::string ToUtf8() const; + private: static std::uint16_t kEmptyBuffer[1]; |