エンコード文字列クラスを作成中

Unicode Support in the Standard Library

これをベースにして、エンコード文字列クラスを作っています。これの設計を丸々採用してるわけではないです。

まだUTF-8しか作ってないですが、こんな感じで使えます。

#include <iostream>
#include <shand/encoding_string.hpp>

int main()
{
    using namespace shand;
    encoding_string<encoding::utf8> s = u8"あいうえお";

    // 文字数を取得
    std::cout << s.codeunit_size() << std::endl; // 5

    // i番目の文字を取得
    std::cout << s.codeunit_at(2) << std::endl; // u8"う"

    // 1文字ずつ出力
    for (decltype(s)::value_type c : s) {
        std::cout << c << std::endl;
    }
    // あ
    // い
    // う
    // え
    // お
}

今のところは、内部実装の効率は度外視して、機能優先で作ってます。

ヘッダオンリーで使えるようにしてて、Boost以外には依存していません。(ICUは使ってない)