#include "Node.h"
#include "WordMap.h"
#include <iostream>
#include<boost/algorithm/string.hpp>
#include <boost/regex.hpp>
using namespace boost;
using namespace std;
void MatchWords(wstring wsToMatch)
{
wregex wrg(L"([\u4e00-\u9fa5])");
wsmatch wsm;
vector<string>singleCharacter;
regex_search(wsToMatch, wsm, wrg );
std::wstring::const_iterator start = wsToMatch.begin();
std::wstring::const_iterator end = wsToMatch.end();
while ( boost::regex_search(start,end, wsm, wrg) )
{
std::wstring msg(wsm[0].first, wsm[0].second);
int iLen= wcstombs( NULL, wsm[1].str().c_str(), 0 );
char *lpsz= new char[iLen+1];
int i= wcstombs( lpsz, wsm[1].str().c_str(), iLen );
lpsz[iLen] = '\0';
string sToMatch(lpsz);
delete []lpsz;
singleCharacter.push_back(sToMatch);
start = wsm[0].second;
}
for (int i=0;i<singleCharacter.size();i++)
{
cout<<singleCharacter[i]<<endl;
}
}
int main(int argc, char *argv[])
{
std::string sToMatch = "我:是 :中国人:民";
setlocale( LC_CTYPE, "" );
int iWLen= mbstowcs( NULL, sToMatch.c_str(), sToMatch.length() );
wchar_t *lpwsz= new wchar_t[iWLen+1];
int i= mbstowcs( lpwsz, sToMatch.c_str(), sToMatch.length() );
wstring wsToMatch(lpwsz);
delete []lpwsz;
MatchWords( wsToMatch );
return 0;
}
如何利用boost_1_43_0正则识别汉字
最新推荐文章于 2023-05-26 00:10:00 发布