int lines = text.string.size();
BOOST_FOREACH (StringText i, text.string) {
- if (i.text().length() > CLOSED_CAPTION_LENGTH) {
+ if (utf8_strlen(i.text()) > CLOSED_CAPTION_LENGTH) {
++lines;
if (!_long_ccap) {
_long_ccap = true;
}
}
+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 */
extern Eyes increment_eyes (Eyes e);
extern void checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path path);
extern void checked_fwrite (void const * ptr, size_t size, FILE* stream, boost::filesystem::path path);
+extern size_t utf8_strlen (std::string s);
#ifdef DCPOMATIC_VARIANT_SWAROOP
extern boost::shared_ptr<dcp::CertificateChain> read_swaroop_chain (boost::filesystem::path path);
extern void write_swaroop_chain (boost::shared_ptr<const dcp::CertificateChain> chain, boost::filesystem::path output);
BOOST_CHECK_EQUAL (tidy_for_filename ("abcdefghï"), "abcdefghï");
}
+BOOST_AUTO_TEST_CASE (utf8_strlen_test)
+{
+ BOOST_CHECK_EQUAL (utf8_strlen("hello world"), 11);
+ BOOST_CHECK_EQUAL (utf8_strlen("hëllo world"), 11);
+ BOOST_CHECK_EQUAL (utf8_strlen("hëłlo wørld"), 11);
+}
+
#ifdef DCPOMATIC_VARIANT_SWAROOP
BOOST_AUTO_TEST_CASE (swaroop_chain_test)
{
BOOST_CHECK (cc->root_to_leaf() == back->root_to_leaf());
}
-
#endif