文字列連結式を見つけるパーサーを作成します。主に関数呼び出しに由来する、括弧で囲まれた一連の文字列があります。
たとえば("one"+"two"+"three") -> ("one"|"two"|"three")
、簡単なケースで、私はそれを処理できます。
より難しいケースは(null, "one"+"two"+"three", null) -> (null, "one"|"two"|"three", null)
ですが、 で解析できますboost::tokenizer
。
(null, "one"+"two"+"three,four", 1 /* third parameter can be: 1, 2, 3 */)
、このような難しい例では、構文解析をお勧めしますがboost::spirit
、いくつかのルールを書くのに助けが必要です.
後で:
escaped_list_separator
からのようboost::tokenizer
です私が必要なものです。しかし、私はそれに1つの問題があります:
using namespace std;
using namespace boost;
string s = "Field 1,\"putting quotes around fields, allows commas\",Field 3";
tokenizer<escaped_list_separator<char> > tok(s,escaped_list_separator<char>("", ",", "\""));
for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end();++beg){
cout <<"~~~"<< *beg << "\n";
}
私のために削除"
します。このように出力に引用符を保持することは可能です
Field 1
"putting quotes around fields, allows commas"
Field 3