diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/common/StringUtil.cpp | 27 |
2 files changed, 23 insertions, 13 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 73ad9456..cfd5be15 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,5 +1,5 @@ set(CRU_BASE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/common) -add_library(cru_base STATIC +add_library(cru_base SHARED Logger.cpp StringUtil.cpp ) @@ -15,6 +15,13 @@ target_sources(cru_base PUBLIC ) target_include_directories(cru_base PUBLIC ${CRU_INCLUDE_DIR}) target_compile_definitions(cru_base PUBLIC $<$<CONFIG:Debug>:CRU_DEBUG>) +target_compile_definitions(cru_base PRIVATE CRU_BASE_EXPORT_API) + +if (WIN32) + target_compile_definitions(cru_base PUBLIC CRU_PLATFORM_WINDOWS) +else() + target_compile_definitions(cru_base PUBLIC CRU_PLATFORM_UNIX) +endif() find_package(Microsoft.GSL CONFIG REQUIRED) find_package(fmt CONFIG REQUIRED) diff --git a/src/common/StringUtil.cpp b/src/common/StringUtil.cpp index bf95f88d..54adebd9 100644 --- a/src/common/StringUtil.cpp +++ b/src/common/StringUtil.cpp @@ -23,13 +23,13 @@ CodePoint Utf8NextCodePoint(std::string_view str, Index current, auto read_next_folowing_code = [&str, ¤t]() -> CodePoint { if (current == static_cast<Index>(str.length())) throw TextEncodeException( - "Unexpected end when read continuing byte of multi-byte code " + u"Unexpected end when read continuing byte of multi-byte code " "point."); const auto u = static_cast<std::uint8_t>(str[current]); if (!(u & (1u << 7)) || (u & (1u << 6))) { throw TextEncodeException( - "Unexpected bad-format (not 0b10xxxxxx) continuing byte of " + u"Unexpected bad-format (not 0b10xxxxxx) continuing byte of " "multi-byte code point."); } @@ -42,7 +42,7 @@ CodePoint Utf8NextCodePoint(std::string_view str, Index current, if ((1u << 4) & cu0) { // 4-length code point if (cu0 & (1u << 3)) { throw TextEncodeException( - "Unexpected bad-format begin byte (not 0b11110xxx) of 4-byte" + u"Unexpected bad-format begin byte (not 0b11110xxx) of 4-byte" "code point."); } @@ -67,7 +67,7 @@ CodePoint Utf8NextCodePoint(std::string_view str, Index current, } } else { throw TextEncodeException( - "Unexpected bad-format (0b10xxxxxx) begin byte of a code point."); + u"Unexpected bad-format (0b10xxxxxx) begin byte of a code point."); } } else { result = static_cast<CodePoint>(cu0); @@ -92,13 +92,13 @@ CodePoint Utf16NextCodePoint(std::u16string_view str, Index current, } else if (IsUtf16SurrogatePairLeading(cu0)) { // 2-length code point if (current >= static_cast<Index>(str.length())) { throw TextEncodeException( - "Unexpected end when reading second code unit of surrogate pair."); + u"Unexpected end when reading second code unit of surrogate pair."); } const auto cu1 = str[current++]; if (!IsUtf16SurrogatePairTrailing(cu1)) { throw TextEncodeException( - "Unexpected bad-range second code unit of surrogate pair."); + u"Unexpected bad-range second code unit of surrogate pair."); } const auto s0 = ExtractBits<std::uint16_t, 10, CodePoint>(cu0) << 10; @@ -108,7 +108,7 @@ CodePoint Utf16NextCodePoint(std::u16string_view str, Index current, } else { throw TextEncodeException( - "Unexpected bad-range first code unit of surrogate pair."); + u"Unexpected bad-range first code unit of surrogate pair."); } } @@ -129,13 +129,13 @@ CodePoint Utf16PreviousCodePoint(std::u16string_view str, Index current, } else if (IsUtf16SurrogatePairTrailing(cu0)) { // 2-length code point if (current <= 0) { throw TextEncodeException( - "Unexpected end when reading first code unit of surrogate pair."); + u"Unexpected end when reading first code unit of surrogate pair."); } const auto cu1 = str[--current]; if (!IsUtf16SurrogatePairLeading(cu1)) { throw TextEncodeException( - "Unexpected bad-range first code unit of surrogate pair."); + u"Unexpected bad-range first code unit of surrogate pair."); } const auto s0 = ExtractBits<std::uint16_t, 10, CodePoint>(cu1) << 10; @@ -145,7 +145,7 @@ CodePoint Utf16PreviousCodePoint(std::u16string_view str, Index current, } else { throw TextEncodeException( - "Unexpected bad-range second code unit of surrogate pair."); + u"Unexpected bad-range second code unit of surrogate pair."); } } @@ -153,6 +153,9 @@ CodePoint Utf16PreviousCodePoint(std::u16string_view str, Index current, return result; } +template class CodePointIterator<std::string_view, &Utf8NextCodePoint>; +template class CodePointIterator<std::u16string_view, &Utf16NextCodePoint>; + void Utf8EncodeCodePointAppend(CodePoint code_point, std::string& str) { auto write_continue_byte = [&str](std::uint8_t byte6) { str.push_back((1u << 7) + (((1u << 6) - 1) & byte6)); @@ -188,7 +191,7 @@ void Utf8EncodeCodePointAppend(CodePoint code_point, std::string& str) { write_continue_byte( ExtractBits<std::uint32_t, 6, std::uint8_t>(unsigned_code_point)); } else { - throw TextEncodeException("Code point out of range."); + throw TextEncodeException(u"Code point out of range."); } } @@ -203,7 +206,7 @@ void Utf16EncodeCodePointAppend(CodePoint code_point, std::u16string& str) { str.push_back(static_cast<char16_t>( ExtractBits<std::uint32_t, 10, std::uint32_t>(u) + 0xDC00u)); } else { - throw TextEncodeException("Code point out of range."); + throw TextEncodeException(u"Code point out of range."); } } |