+
+ // invalid, skip u8_analyze
+ if (*s < 0xC2)
+ {
+ ++s;
+ continue;
+ }
+
+ if (!u8_analyze((const char*)s, &st, &ln, NULL, U8_ANALYZE_INFINITY))
+ {
+ // we CAN end up here, if an invalid char is between this one and the end of the string
+ if(valid)
+ *valid = TRUE;
+ return len;
+ }
+
+ if(end && s + st + ln > end)
+ {
+ // string length exceeded by new character
+ if(valid)
+ *valid = TRUE;
+ return len;
+ }
+
+ // valid character, skip after it
+ s += st + ln;
+ ++len;