diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-01-17 22:33:55 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-01-17 22:33:55 +0000 |
| commit | 95f4db0a8bb5bbf742a0195fbbe17d304fb99507 (patch) | |
| tree | 6b6cd352a739fb14ba57f81eeef6bb345c3bd045 /src/lib/util.cc | |
| parent | 1b5168ff5e624b1617059e529f30da460d81246c (diff) | |
Read UTF8 string lengths correctly when checking closed captions (part of #1446).
Diffstat (limited to 'src/lib/util.cc')
| -rw-r--r-- | src/lib/util.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc index 7472047e8..cd2d2e753 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -815,6 +815,25 @@ checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path pat } } +size_t +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; +} + #ifdef DCPOMATIC_VARIANT_SWAROOP /* Make up a key from the machine UUID */ |
