cocos2d/external/flatbuffers/util.h
inline int FromUTF8(const char **in) {
  int len = 0;
  // Count leading 1 bits.
  for (int mask = 0x80; mask >= 0x04; mask >>= 1) {
    if (**in & mask) {
      len++;
    } else {
      break;
    }
  }
  if ((**in << len) & 0x80) return -1;  // Bit after leading 1's must be 0.
  if (!len) return *(*in)++;
  // Grab initial bits of the code.
  int ucc = *(*in)++ & ((1 << (7 - len)) - 1);
  for (int i = 0; i < len - 1; i++) {
    if ((**in & 0xC0) != 0x80) return -1;  // Upper bits must 1 0.
    ucc <<= 6;
    ucc |= *(*in)++ & 0x3F;  // Grab 6 more bits of the code.
  }
  return ucc;
}
// Converts whatever prefix of the incoming string corresponds to a valid
// UTF-8 sequence into a unicode code. The incoming pointer will have been
// advanced past all bytes parsed.
// returns -1 upon corrupt UTF-8 encoding (ignore the incoming pointer in
// this case).
Converts whatever prefix of the incoming string corresponds to a valid
UTF-8 sequence into a unicode code. The incoming pointer will have been
advanced past all bytes parsed.
returns -1 upon corrupt UTF-8 encoding (ignore the incoming pointer in
this case).
Converts whatever prefix of the incoming string corresponds to a valid UTF - 8 sequence into a unicode code . The incoming pointer will have been advanced past all bytes parsed . returns - 1 upon corrupt UTF - 8 encoding ( ignore the incoming pointer in this case ) .
inline int FromUTF8(const char **in) {
  int len = 0;
  for (int mask = 0x80; mask >= 0x04; mask >>= 1) {
    if (**in & mask) {
      len++;
    } else {
      break;
    }
  }
  if ((**in << len) & 0x80) return -1;  
  if (!len) return *(*in)++;
  int ucc = *(*in)++ & ((1 << (7 - len)) - 1);
  for (int i = 0; i < len - 1; i++) {
    if ((**in & 0xC0) != 0x80) return -1;  
    ucc <<= 6;
    ucc |= *(*in)++ & 0x3F;  
  }
  return ucc;
}
inline int FromUTF8 ( const char * * in ) { int len = 0 ; for ( int mask = 0x80 ; mask >= 0x04 ; mask >>= 1 ) { if ( * * in & mask ) { len ++ ; } else { break ; } } if ( ( * * in << len ) & 0x80 ) return -1 ; if ( ! len ) return * ( * in ) ++ ; int ucc = * ( * in ) ++ & ( ( 1 << ( 7 - len ) ) - 1 ) ; for ( int i = 0 ; i < len - 1 ; i ++ ) { if ( ( * * in & 0xC0 ) != 0x80 ) return -1 ; ucc <<= 6 ; ucc |= * ( * in ) ++ & 0x3F ; } return ucc ; }
Converts whatever prefix of the incoming string corresponds to a valid
UTF-8 sequence into a unicode code.
Converts whatever prefix of the incoming string corresponds to a valid UTF - 8 sequence into a unicode code .
// Count leading 1 bits. // Bit after leading 1's must be 0. // Grab initial bits of the code. // Upper bits must 1 0. // Grab 6 more bits of the code.