Sprout.Weed で複数行のパース
[ソース]
#include <sprout/weed.hpp> int main(){ namespace w = sprout::weed; using sprout::make_common_array; using sprout::to_string; static constexpr auto width = 16; static constexpr auto height = 16; static constexpr auto string = *w::lim<width>(w::char_ - w::eol); static constexpr auto space = *w::omit[w::space]; static constexpr auto line = w::as_array[ space >> string >> w::eol ]; static constexpr auto multi_line = *w::lim<height>(line); static constexpr auto source = sprout::to_string(R"delimiter( homu mado saya an mami )delimiter"); static constexpr auto result = w::parse( sprout::begin(source), sprout::end(source), multi_line ); static_assert(result.success(), ""); static constexpr auto attr = result.attr(); static_assert(attr[0] == "homu", ""); static_assert(attr[1] == "mado", ""); static_assert(attr[2] == "saya", ""); static_assert(attr[3] == "an" , ""); static_assert(attr[4] == "mami", ""); static_assert(attr[5] == "", ""); return 0; }
まぁやっている事は split ですね。
先頭のスペースは無視しています。
Sprout に split algorithm とかあるのかしら…?(戻り値型が爆発しそうだけど。