diff options
| author | Carl Hetherington <cth@carlh.net> | 2026-04-15 22:55:53 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2026-04-15 22:55:53 +0200 |
| commit | 61c6b8a23ef6381c2d1b1aaa5bfc1e31e35a7ec0 (patch) | |
| tree | 0c8273ee845b91fef85e89c746f81a88492188ef /src | |
| parent | 48711ae4e01f2ea43016d6e4b94bd15ad7b13f42 (diff) | |
Move utf8_strlen() in from DoM.
Diffstat (limited to 'src')
| -rw-r--r-- | src/util.cc | 21 | ||||
| -rw-r--r-- | src/util.h | 2 |
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; +} + + @@ -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); + } |
