diff options
author | crupest <crupest@outlook.com> | 2021-08-10 01:00:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-08-10 01:00:33 +0800 |
commit | d2448884500811bf1cd1eba89e7a4193a76c4d6b (patch) | |
tree | 2c9117f3e91128c3f08639283281c1898e01b063 /include/cru/common/StringUtil.hpp | |
parent | 9c32e6d705b23cf0f5d7c0909271640401f9785f (diff) | |
download | cru-d2448884500811bf1cd1eba89e7a4193a76c4d6b.tar.gz cru-d2448884500811bf1cd1eba89e7a4193a76c4d6b.tar.bz2 cru-d2448884500811bf1cd1eba89e7a4193a76c4d6b.zip |
...
Diffstat (limited to 'include/cru/common/StringUtil.hpp')
-rw-r--r-- | include/cru/common/StringUtil.hpp | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/include/cru/common/StringUtil.hpp b/include/cru/common/StringUtil.hpp index 912106c3..0ea842c2 100644 --- a/include/cru/common/StringUtil.hpp +++ b/include/cru/common/StringUtil.hpp @@ -9,9 +9,9 @@ namespace cru { using CodePoint = std::int32_t; constexpr CodePoint k_invalid_code_point = -1; -class TextEncodeException : public std::runtime_error { +class CRU_BASE_API TextEncodeException : public Exception { public: - using runtime_error::runtime_error; + using Exception::Exception; }; inline bool IsUtf16SurrogatePairCodeUnit(char16_t c) { @@ -26,13 +26,14 @@ inline bool IsUtf16SurrogatePairTrailing(char16_t c) { return c >= 0xDC00 && c <= 0xDFFF; } -CodePoint Utf8NextCodePoint(std::string_view str, Index current, - Index* next_position); +CodePoint CRU_BASE_API Utf8NextCodePoint(std::string_view str, Index current, + Index* next_position); -CodePoint Utf16NextCodePoint(std::u16string_view str, Index current, - Index* next_position); -CodePoint Utf16PreviousCodePoint(std::u16string_view str, Index current, - Index* previous_position); +CodePoint CRU_BASE_API Utf16NextCodePoint(std::u16string_view str, + Index current, Index* next_position); +CodePoint CRU_BASE_API Utf16PreviousCodePoint(std::u16string_view str, + Index current, + Index* previous_position); template <typename StringType> using NextCodePointFunctionType = CodePoint (*)(StringType, Index, Index*); @@ -117,37 +118,49 @@ class CodePointIterator { mutable Index next_position_cache_; }; +extern template CRU_BASE_API class CodePointIterator<std::string_view, + &Utf8NextCodePoint>; +extern template CRU_BASE_API class CodePointIterator<std::u16string_view, + &Utf16NextCodePoint>; + using Utf8CodePointIterator = CodePointIterator<std::string_view, &Utf8NextCodePoint>; using Utf16CodePointIterator = CodePointIterator<std::u16string_view, &Utf16NextCodePoint>; -void Utf8EncodeCodePointAppend(CodePoint code_point, std::string& str); -void Utf16EncodeCodePointAppend(CodePoint code_point, std::u16string& str); +void CRU_BASE_API Utf8EncodeCodePointAppend(CodePoint code_point, + std::string& str); +void CRU_BASE_API Utf16EncodeCodePointAppend(CodePoint code_point, + std::u16string& str); -std::string ToUtf8(std::u16string_view s); -std::u16string ToUtf16(std::string_view s); +std::string CRU_BASE_API ToUtf8(std::u16string_view s); +std::u16string CRU_BASE_API ToUtf16(std::string_view s); // If given s is not a valid utf16 string, return value is UD. -bool Utf16IsValidInsertPosition(std::u16string_view s, gsl::index position); +bool CRU_BASE_API Utf16IsValidInsertPosition(std::u16string_view s, + gsl::index position); // Return position after the character making predicate returns true or 0 if no // character doing so. -gsl::index Utf16BackwardUntil(std::u16string_view str, gsl::index position, - const std::function<bool(CodePoint)>& predicate); +gsl::index CRU_BASE_API +Utf16BackwardUntil(std::u16string_view str, gsl::index position, + const std::function<bool(CodePoint)>& predicate); // Return position before the character making predicate returns true or // str.size() if no character doing so. -gsl::index Utf16ForwardUntil(std::u16string_view str, gsl::index position, - const std::function<bool(CodePoint)>& predicate); - -gsl::index Utf16PreviousWord(std::u16string_view str, gsl::index position, - bool* is_space = nullptr); -gsl::index Utf16NextWord(std::u16string_view str, gsl::index position, - bool* is_space = nullptr); - -char16_t ToLower(char16_t c); -char16_t ToUpper(char16_t c); -std::u16string ToLower(std::u16string_view s); -std::u16string ToUpper(std::u16string_view s); +gsl::index CRU_BASE_API +Utf16ForwardUntil(std::u16string_view str, gsl::index position, + const std::function<bool(CodePoint)>& predicate); + +gsl::index CRU_BASE_API Utf16PreviousWord(std::u16string_view str, + gsl::index position, + bool* is_space = nullptr); +gsl::index CRU_BASE_API Utf16NextWord(std::u16string_view str, + gsl::index position, + bool* is_space = nullptr); + +char16_t CRU_BASE_API ToLower(char16_t c); +char16_t CRU_BASE_API ToUpper(char16_t c); +std::u16string CRU_BASE_API ToLower(std::u16string_view s); +std::u16string CRU_BASE_API ToUpper(std::u16string_view s); } // namespace cru |