小编Vap*_*por的帖子

如何使用Boost Spirit来解析中文(unicode utf-16)?

我的节目不承认中文.如何使用精神来认识中国人?我使用wstring并将其转换为utf-16.

这是我的头文件:

#pragma once

#define BOOST_SPIRIT_UNICODE 

#include <boost/spirit/include/qi.hpp>  
#include <string>
#include <vector>
#include <map>
using namespace std;



namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;


typedef pair<wstring,wstring> WordMeaningType;
typedef vector<WordMeaningType> WordMeaningsType;
typedef pair<wstring,WordMeaningsType> WordType;
typedef vector<WordType> WordListType;

struct WordPaser
    :qi::grammar<wstring::iterator,WordListType(),ascii::space_type > 
{
public:
    qi::rule<wstring::iterator, wstring(),ascii::space_type> mRuleWordPart;
    qi::rule<wstring::iterator, wstring(),ascii::space_type> mRuleWordMeaning;
    qi::rule<wstring::iterator, wstring(),ascii::space_type> mRuleWord;

    qi::rule<wstring::iterator, WordMeaningType(),ascii::space_type> mRulePM;
    qi::rule<wstring::iterator, WordMeaningsType(),ascii::space_type> mRulePMs;
    qi::rule<wstring::iterator, WordType(),ascii::space_type> mRuleCurWPM;

    qi::rule<wstring::iterator, WordListType(),ascii::space_type> mRuleEntrence;


    wstring mCurWord;
    wstring mCurWordPart;
    wstring mCurWordMeaning;
    WordMeaningType mCurPM;
    WordMeaningsType mCurPMs;
    WordType mCurWPM;

    WordPaser();


}; …
Run Code Online (Sandbox Code Playgroud)

unicode boost utf-16 cjk boost-spirit

3
推荐指数
1
解决办法
1410
查看次数

标签 统计

boost ×1

boost-spirit ×1

cjk ×1

unicode ×1

utf-16 ×1