summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util.cc21
-rw-r--r--src/util.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index 1984595d..61b9ba66 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -471,3 +471,24 @@ dcp::maybe_throw_from_asdcplib(Kumu::Result_t result, boost::filesystem::path pa
}
}
+
+size_t
+dcp::utf8_strlen(string s)
+{
+ size_t const len = s.length();
+ int N = 0;
+ for (size_t i = 0; i < len; ++i) {
+ unsigned char c = s[i];
+ if ((c & 0xe0) == 0xc0) {
+ ++i;
+ } else if ((c & 0xf0) == 0xe0) {
+ i += 2;
+ } else if ((c & 0xf8) == 0xf0) {
+ i += 3;
+ }
+ ++N;
+ }
+ return N;
+}
+
+
diff --git a/src/util.h b/src/util.h
index cfed9fcb..62c0e295 100644
--- a/src/util.h
+++ b/src/util.h
@@ -171,6 +171,8 @@ void throw_from_asdcplib(Kumu::Result_t result, boost::filesystem::path path, T
boost::throw_exception(general);
}
+extern size_t utf8_strlen(std::string s);
+
}