环境:boost1.53.0 c++11;
C++ 新手。
在boost语言环境边界分析中,规则类型是为单词指定的(例如:boundary::word_letter
, boundary::word_number
) 和句子 ,但字符没有边界规则类型。我想要的就是类似的东西isUpperCase(), isLowerCase(), isDigit(), isPunctuation()
.
尝试了 boost 字符串算法,但不起作用。
boost::locale::generator gen;
std::locale loc = gen("ru_RU.UTF-8");
std::string context = "ДВ";
std::cout << boost::algorithm::all(context, boost::algorithm::is_upper(loc));
为什么这些功能在 Java 或 Python 中可以轻松访问,但在 C++ 中却如此令人困惑?有什么方法可以实现这些吗?
这对我在 VS 2013 下有效。
locale::global(locale("ru-RU"));
std::string context = "ДВ";
std::cout << any_of(context.begin(), context.end(), boost::algorithm::is_upper());
Prints 1
如何初始化语言环境非常重要。
UPDATE:
这是在 Ubuntu 下工作的解决方案。
#include <iostream>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/locale.hpp>
using namespace std;
int main()
{
locale::global(locale("ru_RU"));
wstring context = L"ДВ";
wcout << boolalpha << any_of(context.begin(), context.end(), boost::algorithm::is_upper());
wcout<<endl;
wstring context1 = L"ПРИВЕТ, МИР"; //HELLO WORLD in russian
wcout << boolalpha << any_of(context1.begin(), context1.end(), boost::algorithm::is_upper());
wcout<<endl;
wstring context2 = L"привет мир"; //hello world in russian
wcout << boolalpha << any_of(context2.begin(), context2.end(), boost::algorithm::is_upper());
return 0;
}
Prints
true
true
false
这也适用于 boost::algorithm::all 。
wstring context = L"ДВ";
wcout << boolalpha << boost::algorithm::all(context, boost::algorithm::is_upper());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)