gpt4 book ai didi

c++ - ICU 和字符串比较

转载 作者:行者123 更新时间:2023-11-30 04:34:26 25 4
gpt4 key购买 nike

谁能解释为什么下面的比较不相等?

void CompareTest()
{
UErrorCode status = U_ZERO_ERROR;
UChar ruleset[500]; *ruleset = 0;
int32_t rlen = 0;

UCollator *coll = ucol_open("de_DE", &status);


static const UChar rules[] = L"&\\u0000 = '' = '-'";
int32_t len=(int32_t)u_strlen(rules);

const UChar *defRules = ucol_getRules(coll, &rlen);
if(rlen > 0)
{
u_strcpy(ruleset, defRules);
}
u_strcat(ruleset, rules);

status = U_ZERO_ERROR;
UCollator *collRule = ucol_openRules(ruleset, u_strlen(ruleset), UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status);

ucol_setAttribute(collRule, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
ucol_setAttribute(collRule, UCOL_STRENGTH, UCOL_QUATERNARY, &status);


UCollationResult uResult = ucol_strcoll(collRule, L"post-war", -1, L"post war", -1);
uResult = ucol_strcoll(collRule, L"post-war", -1, L"postwar", -1);
uResult = ucol_strcoll(collRule, L"ÄÖÜ", -1, L"äöü", -1);
uResult = ucol_strcoll(collRule, L"ß", -1, L"ss", -1);


}

最佳答案

您不需要进行任何规则自定义。

  UCollator * collRule = coll;
ucol_setAttribute(collRule, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); // no effect for these samples.
ucol_setAttribute(collRule, UCOL_STRENGTH, UCOL_PRIMARY, &status);
ucol_setAttribute(collRule, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);

结果:

post-war -> [45 43 4B 4D 53 27 49 00]
post war -> [45 43 4B 4D 53 27 49 00]
(post-war === post war) -> 0
post-war -> [45 43 4B 4D 53 27 49 00]
postwar -> [45 43 4B 4D 53 27 49 00]
(post-war === postwar) -> 0
ÄÖÜ -> [27 43 4F 00]
äöü -> [27 43 4F 00]
(ÄÖÜ === äöü) -> 0
ß -> [4B 4B 00]
ss -> [4B 4B 00]
(ß === ss) -> 0

关于c++ - ICU 和字符串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6028339/

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