tensorflow/core/kernels/string_util.cc
// Return the number of Unicode characters in a UTF-8 string.
// Result may be incorrect if the input string is not valid UTF-8.
Return the number of Unicode characters in a UTF-8 string.
Result may be incorrect if the input string is not valid UTF-8.
Return the number of Unicode characters in a UTF - 8 string . Result may be incorrect if the input string is not valid UTF - 8 .
int32 UTF8StrLen(const string& str) {
  const int32_t byte_size = str.size();
  const char* const end = str.data() + byte_size;
  const char* ptr = str.data();
  int32_t skipped_count = 0;
  while (ptr < end) {
    skipped_count += IsTrailByte(*ptr++) ? 1 : 0;
  }
  const int32_t result = byte_size - skipped_count;
  return result;
}
int32 UTF8StrLen ( const string & str ) { const int32_t byte_size = str . size ( ) ; const char * const end = str . data ( ) + byte_size ; const char * ptr = str . data ( ) ; int32_t skipped_count = 0 ; while ( ptr < end ) { skipped_count += IsTrailByte ( * ptr ++ ) ? 1 : 0 ; } const int32_t result = byte_size - skipped_count ; return result ; }
Return the number of Unicode characters in a UTF-8 string.
Return the number of Unicode characters in a UTF - 8 string .