是否可以让boost语言环境边界分析在撇号上进行拆分
Is it possible to get boost locale boundary analysis to split on apostrophes?
例如,考虑以下代码:
using namespace boost::locale::boundary;
boost::locale::generator gen;
std::string text = "L'homme qu'on aimait trop.";
ssegment_index map(word, text.begin(), text.end(), gen("fr_FR.UTF-8"));
for (ssegment_index::iterator it = map.begin(), e = map.end(); it != e; ++it)
std::cout << """ << *it << "", ";
std::cout << std::endl;
该输出:
"L'homme", " ", "qu'on", " ", "aimait", " ", "trop", ".",
是否可以自定义边界分析,从而输出:
"L", "'", "homme", " ", "qu", "'", "on", " ", "aimait", " ", "trop", ".",
我读过http://www.boost.org/doc/libs/1_56_0/libs/locale/doc/html/boundary_analysys.html并搜索了Stack Overflow和谷歌,但到目前为止还没有找到任何东西。
我还没有找到用boost::locale::boundary来实现这一点的方法,但可以直接用ICU来实现,方法是创建一个自定义的RuleBasedBreakIterator
,而不是使用createWordInstance
提供的。
Locale locale("fr_FR");
UErrorCode statusError = U_ZERO_ERROR;
UParseError parseError = { 0 };
// get rules from a default rbbi (these should be in a word.txt file somewhere)
RuleBasedBreakIterator *default_rbbi = dynamic_cast<RuleBasedBreakIterator *>(RuleBasedBreakIterator::createWordInstance(locale, statusError));
UnicodeString rules = default_rbbi->getRules();
delete default_rbbi;
// create custom rbbi with updated rules
rules.findAndReplace("[\p{Word_Break = MidNumLet}]", "[[\p{Word_Break = MidNumLet}] - [\u0027 \u2018 \u2019 \uff07]]");
RuleBasedBreakIterator custom_rbbi(rules, parseError, statusError);
// tokenize text
UnicodeString text = "L'homme qu'on aimait trop.";
custom_rbbi.setText(text);
int32_t e, p = custom_rbbi.first();
while ((e = custom_rbbi.next()) != BreakIterator::DONE) {
std::string substring;
text.tempSubStringBetween(p, e).toUTF8String(substring);
std::cout << """ << substring << "", ";
p = e;
}
std::cout << std::endl;
相关文章:
- 将 Boost.Spirit.X3 解析器拆分为多个 TU
- 如何使用 Boost C++ 打印第 n 个字符串拆分?
- 如何在拆分为多个文件的分层 SM 中退出子机器?(使用boost::MSM)
- 使用 boost::split 按分隔符的前 N 次匹配来拆分字符串
- 使用Boost或Regex拆分这条线
- boost spirit x3在拆分后的奇怪语义行为
- 如何使用 boost::split 拆分字符串并保留分隔符
- 使用 C++ boost::split 拆分字符串,而不在引号文本内拆分
- 分段错误(核心转储),使用 boost::拆分C++
- boost::algorithm - 拆分字符串会返回一个额外的标记
- 是否可以让boost语言环境边界分析在撇号上进行拆分
- 如何在单独的 Boost.Python 模块之间拆分继承关系
- 在 Boost Spirit 2.5.2 中按层次结构拆分语法
- 在使用boost拆分方法时,我可以使用字符串作为分隔符吗
- 使用boost::algorithm::Split_regex拆分字符串
- 如果有必要,删除边缘并拆分连接的组件(c++, Boost)
- Boost拆分递归并追加到set
- c++ /Boost将字符串拆分为多个字符
- 使用 boost::is_any_of 拆分混淆了分量计",,"和","
- 如何使用boost split拆分字符串并忽略空值