diff options
Diffstat (limited to 'include/cru/common/StringUtil.hpp')
-rw-r--r-- | include/cru/common/StringUtil.hpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/include/cru/common/StringUtil.hpp b/include/cru/common/StringUtil.hpp index 276048f5..62999d53 100644 --- a/include/cru/common/StringUtil.hpp +++ b/include/cru/common/StringUtil.hpp @@ -1,7 +1,10 @@ #pragma once -#include <string> #include "Base.hpp" +#include <functional> +#include <string> +#include <string_view> + namespace cru { using CodePoint = std::int32_t; constexpr CodePoint k_invalid_code_point = -1; @@ -128,4 +131,18 @@ std::u16string 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); + +// 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); +// 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); } // namespace cru |