aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common/StringUtil.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-26 23:41:02 +0800
committercrupest <crupest@outlook.com>2020-12-26 23:41:02 +0800
commit6523ba8e0f2830f3cd4434d8331882077be3f82c (patch)
treea09c4344c69e9b44efa6698e79fa2d6723bd59cb /include/cru/common/StringUtil.hpp
parentacb7462be0b1d6b002a9e50a81b2b74fdc16a3b3 (diff)
downloadcru-6523ba8e0f2830f3cd4434d8331882077be3f82c.tar.gz
cru-6523ba8e0f2830f3cd4434d8331882077be3f82c.tar.bz2
cru-6523ba8e0f2830f3cd4434d8331882077be3f82c.zip
...
Diffstat (limited to 'include/cru/common/StringUtil.hpp')
-rw-r--r--include/cru/common/StringUtil.hpp19
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