5
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define BOOST_SPIRIT_UNICODE // We'll use unicode (UTF8) all throughout

#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_parse.hpp>
#include <boost/spirit/include/support_standard_wide.hpp>

void parse_simple_string()
{
    namespace qi = boost::spirit::qi;    
    namespace encoding  = boost::spirit::unicode;
    //namespace stw = boost::spirit::standard_wide;

    typedef std::wstring::const_iterator iterator_type;

    std::vector<std::wstring> result;
    std::wstring const input = LR"(12,3","ab,cd","G,G\"GG","kkk","10,\"0","99987","PPP","你好)";

    qi::rule<iterator_type, std::wstring()> key = +(qi::unicode::char_ - qi::lit(L"\",\""));
    qi::phrase_parse(input.begin(), input.end(),
                     key % qi::lit(L"\",\""),
                     encoding::space,
                     result);

    //std::copy(result.rbegin(), result.rend(), std::ostream_iterator<std::wstring, wchar_t>  (std::wcout, L"\n"));
    for(auto const &data : result) std::wcout<<data<<std::endl;
}

私はこの投稿を研究しました Boost Spiritを使用してChinese(unicode utf-16)を解析する方法? ガイドに従いますが、「你好」という言葉を解析できません

期待される結果は

12,3 ab,cd G,G\"GG kkk 10,\"0 99987 PPP你好

しかし、実際の結果は 12,3 ab,cd G,G\"GG kkk 10,\"0 99987 PPP です。

中国語の単語「你好」の解析に失敗しました

OS は win7 64bit です。エディタは単語を UTF-8 として保存します。

4

2 に答える 2