タグ

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

  • 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
    nilab
    nilab 2012/01/06
    UTF-8 文字数カウント | ninxit.blog : 「UTF-8 は1バイト目に後に続くバイト数が示されている為、簡単に実装できた」
  • valgrind を使ってみた - utahta blog

    valgrind とは? linux 環境で動く超強力なメモリデバッガー。 メモリリークや、セグメンテーション違反を起こしている正確な位置を教えてくれる。 以下、使い方メモ。 使用バージョンは、valgrind-3.2.1 メモリリーク検出など $ valgrind --leak-check=full ./program arg1 arg2 ヒーププロファイラ $ valgrind --tool=massif ./program arg1 arg2 メモリをデバッグしてみる 1. バッファオーバーランとメモリリークを行うソースコードを記述 $ vi main.cpp #include <stdio.h> int main() { int *a = new int[2]; a[2] = 0; // バッファオーバーラン return 0; // メモリリーク } 2. コンパイルする $ g

    valgrind を使ってみた - utahta blog
    nilab
    nilab 2010/06/11
    valgrind を使ってみた | NINXIT-BLOG
  • 1