gpt4 book ai didi

c++ - boost::locale icu sortKey

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:21:07 25 4
gpt4 key购买 nike

我正在编写代码,在数据库中创建索引。使用 ICU 库,我的工作流程是:

  • 用户语言环境中的字符串 ->
    转换为 utf8 ->
    规范化 utf8 ->
    调用 ICU ucol_getSortKey 获取构建索引的排序键。

现在我切换到 Boost Locale。 Boost Locale 可以像 ICU 一样构建排序键吗?或者我应该以某种方式直接调用 ICU?

最佳答案

看起来这就是 Boost Locale 所知道的 collat​​e_impl::do_[basic_]transform():

std::vector<uint8_t> do_basic_transform(level_type level,CharType const *b,CharType const *e) const 
{
icu::UnicodeString str=cvt_.icu(b,e);
std::vector<uint8_t> tmp;
tmp.resize(str.length());
icu::Collator *collate = get_collator(level);
int len = collate->getSortKey(str,&tmp[0],tmp.size());
if(len > int(tmp.size())) {
tmp.resize(len);
collate->getSortKey(str,&tmp[0],tmp.size());
}
else
tmp.resize(len);
return tmp;
}

std::basic_string<CharType> do_transform(level_type level,CharType const *b,CharType const *e) const
{
std::vector<uint8_t> tmp = do_basic_transform(level,b,e);
return std::basic_string<CharType>(tmp.begin(),tmp.end());
}

为了性能,您似乎想要调用 do_basic_compare

关于c++ - boost::locale icu sortKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26205528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com