五流!!日曜プログラマーのつどい - boost/algorithm

boost/algorithm

使用したバージョンはboost_1.42


split

include <boost/algorithm/string.hpp>

機能

文字分割関数.任意の指定した文字で文字列を分割する.
// boost::algorithm::split(result, str, pred, token_compress)
 
 std::vector<std::string> result;
 std::string input;
 boost::algorithm::split( reult,
                          input,
                          boost::algorithm::is_any_of("./"),//'.','/'で分割する.
                          boost::algorithm::token_compress_on);
これで[/]で[input]を分割した結果が[result]に格納される.
boost::algorithm::is_any_of("/")の部分は分割する文字の指定(他にも関数がある).
boost::algorithm::token_compress_on は分割結果の格納方法(token_compress_offもある).

引数

result
実行結果(std::vector<std::string>)
str
入力文字列(std::string)
pred
[参照] http://d.hatena.ne.jp/scior/20100811/1281537296
述部判別する文字
is_any_of任意の文字
is_digit数字(0-9)
is_alpha英字(a-z,A-Z)
is_lower小文字(a-z)
is_upper大文字(A-Z)
is_alnum英数字(0-9,a-z,A-Z)
is_graph記号文字(0x21-0x7e)
is_cntrl制御文字(0x00-0x1f,0x7f)
is_space空白(0x20,\t,\n,\f,\r,\v)
is_punct句読点等(記号文字∩英数字以外)
is_xdigit16進表記に使える文字(0-9,a-f,A-F)
is_from_range範囲指定
token_compress
以下の入力文字に対する処理結果を示す.
    • 入力文字:"hoge./hoge/hoge"
mode区切り文字結果
token_compress_on./"hoge","hoge","hoge"連続した区切りをまとめる
token_compress_off./"hoge","","hoge","hoge"連続した区切りをまとめない