字句解析・小物集
小文字にそろえる。
string st; string::iterator it = st.begin(); while( it != st.end() ){ if( 65 <= *it && *it <= 90 ){ *it += 32; } it++; }
スペース・タブ・改行を削除。
string st; string::iterator it = st.begin(); while( it != st.end() ){ if( *it == 20 || *it == '\t' || *it == '\n' ){ it = st.clear( it ); }else{ it++; } }
16進数の一文字を数値に変換。
変換できない場合は0に。
char c; int nc = static_cast< int >( c ); if( 48 <= nc && nc < 58 ){ ncc -= 48; }else if( 97 <= nc && nc < 103 ){ nc -= 87; }else{ nc = 0; }
なお、普通の数字→数値変換はboost::lexical_castで一発終了である。
string num; int nc = boost::lexial_cast< int >( num );