さよならlocale

  • 世界で二人しか使っていないcpp_to_hatenaを更新しました
  • ついでに一年間のいろんなコードをまとめておきました
  • libs/biscuit/exampleフォルダにあります・・・ダウンロード
  • 使えるファイルをUTF8のみにしました (英語だけならそのままでOK)
    • MinGWでも日本語が使えます
    • MinGWではlocaleが知らない型を扱うとクラッシュするらしい
  • VC7.1, VC8, GCC3.4.4で動作確認
  • range adaptorでつないだrangeに複雑なアルゴリズムを走らせると劇的に遅くなります
  • 以下、自分自身で色づけされたサンプル


[]// cpp_to_hatena.cpp[]
[]//[]
[]// UTF8ファイル限定になりましたが、[]
[]// Mingwで日本語が扱えるようになりました。[]

[]#include[] []"stdafx.h"[]

[]#include[] []<fstream>[]
[]#include[] []<iterator>[]
[]#include[] []<vector>[]

[]#include[] []<boost/cstdint.hpp>[] []// for uintXXX_t[]
[]#include[] []<boost/mpl/int.hpp>[]
[]#include[] []<boost/mpl/void.hpp>[]

[]#include[] []<pstade/biscuit/algorithm/iterate.hpp>[]
[]#include[] []<pstade/oven.hpp>[]
[]#include[] []<pstade/stove.hpp>[]
[]#include[] []"./cpp_to_hatena/start.hpp"[]


[]//#define PSTADE_RANGE_ADAPTOR_DURABILITY_TEST[]


[]namespace[] []meta[][] {[]


[]////////////////////////////////////////////////////////////////////////////////[]
[]// tab-size をカスタマイズしてください (metafunctionなのはシャレです)[]
[]//[]
[]template[][]< [][]class[][] = [][]boost[][]::[][]mpl[][]::[][]void_[][] >[]
[]struct[] []tabsize[][] :[]
[]boost[][]::[][]mpl[][]::[][]int_[][]<[][]2[][]>[]
[]{ };[]


[]////////////////////////////////////////////////////////////////////////////////[]
[]// 回避策 for MinGW[]
[]//[]
[]template[][]< [][]class[] []CharT[][] >[]
[]struct[] []ofstream[]
[]{[]
[]#if[][] !defined(__MINGW32__)[]
[]typedef[] []std[][]::[][]basic_ofstream[][]<[][]CharT[][]> [][]type[][];[]
[]#else[]
[]typedef[] []std[][]::[][]ofstream[] []type[][];[]
[]#endif[]
[]};[]


[]} [][]// namespace meta[]


[]////////////////////////////////////////////////////////////////////////////////[]
[]// main[]
[]//[]
[]int[] []main[][]([][]int[] []argc[][], [][]char[][] *[][]argv[][][])[]
[]{[]
[]using[] []namespace[] []pstade[][];[]

[]for[][] ([][]int[] []i[][] = [][]0[][]; ++[][]i[][] < [][]argc[][];) {[]
[]std[][]::[][]string[] []ifile[][]([][]argv[][][[][]i[][]]);[]

[]typedef[] []std[][]::[][]vector[][]<[][]boost[][]::[][]uint32_t[][]> [][]string_t[][];[]

[]#if[][] !defined(PSTADE_RANGE_ADAPTOR_DURABILITY_TEST)[]
[]// itextをキャッシュしておくと速さがかなり違います[]
[]// キャッシュしないとプログラムサイズも大きくなるようです[]
[]string_t[] []itext[][]; {[]
[]oven[][]::[][]copy[][]([]
[]oven[][]::[][]file_range[][]<[][]boost[][]::[][]uint8_t[][]>([][]ifile[][]) |[]
[]oven[][]::[][]utf8_decoded[][]<[][]boost[][]::[][]uint32_t[][]>() |[]
[]oven[][]::[][]tab_expanded[][]([][]meta[][]::[][]tabsize[][]<>::[][]value[][]),[]
[]std[][]::[][]back_inserter[][]([][]itext[][])[]
[] );[]
[] }[]
[]#endif[]

[]string_t[] []otext[][]; {[]
[]std[][]::[][]back_insert_iterator[][]<[][]string_t[][]> [][]out[][]([][]otext[][]); [][]// biscuitのためのlvalue[]

[]oven[][]::[][]copy[][]([][]"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><pre class=\"cpp_source\">"[][], [][]out[][]);[]

[]biscuit[][]::[][]iterate[][]<[][]cpp_to_hatena[][]::[][]start[][]>([]
[]#if[][] !defined(PSTADE_RANGE_ADAPTOR_DURABILITY_TEST)[]
[]itext[][],[]
[]#else[]
[]oven[][]::[][]file_range[][]<[][]boost[][]::[][]uint8_t[][]>([][]ifile[][]) |[]
[]oven[][]::[][]utf8_decoded[][]<[][]boost[][]::[][]uint32_t[][]>() |[]
[]oven[][]::[][]tab_expanded[][]([][]meta[][]::[][]tabsize[][]<>::[][]value[][]),[]
[]#endif[]
[]out[][],[]
[]cpp_to_hatena[][]::[][]act_line_escape[][]()[]
[] );[]

[]oven[][]::[][]copy[][]([][]"</pre>"[][], [][]out[][]);[]
[] }[]

[]std[][]::[][]string[] []ofile[][] = [][]ifile[][] + [][]".xml"[][];[]
[]meta[][]::[][]ofstream[][]<[][]boost[][]::[][]uint8_t[][]>::[][]type[] []fout[][]([][]ofile[][].[][]c_str[][](), [][]std[][]::[][]ios[][]::[][]binary[][]);[]
[]oven[][]::[][]copy[][]([][]otext[][], [][]oven[][]::[][]utf8_encoder[][]([][]oven[][]::[][]outputter[][]([][]fout[][])));[]
[] }[]

[]return[] []0[][];[]
[]}[]