タグ

ブックマーク / utahta.hatenablog.com (1)

  • UTF-8 + 文字数カウント - utahta blog

    C++UTF-8 の文字数を数えるコードを試しに書いてみたメモ。 バイト数ではなく、文字数。 #include #include int strlen_utf8( const char *buff ) { if( buff == NULL ) return 0; int count = 0; int pos = 0; int max_bytes = strlen( buff ); // BOM 読み飛ばし if( max_bytes >= 3 ) { if( static_cast( buff[0] ) == 0xEF && static_cast( buff[1] ) == 0xBB && static_cast( buff[2] ) == 0xBF ) { pos += 3; } } while( pos < max_bytes ) { ++count; // 文字数カウント i

    UTF-8 + 文字数カウント - utahta blog
  • 1