ICU 和字符串比较
ICU and string compare
谁能解释为什么下面的比较不相等?
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++使用 map 来比较字符串中的每个单词
- 我正在尝试从输入文件中读取,然后使用它们的子字符串比较字符串的特定部分
- 比较字符串的 GetLine 工作一次,然后比较之后不起作用
- C++使用关系运算符比较字符串
- 通过默认复制构造函数比较 C++ 字符串是否会影响性能,原因为何?
- C++ TCP 服务器比较字符串失败
- 如何在不复制的情况下比较字符串的一部分?
- 比较 C++ 字符串打印中的两个整数数组
- 如何比较字符串形式的临时变量
- std::out_of_range 比较字符串中的符号时出错
- 比较字符串大小写不区分的简单方法是什么?
- 比较字符串忽略 NUL
- 比较字符串(arduino)时出现问题
- 如何在C++中比较字符串
- 比较字符串对象等于向量中的元素
- C 比较字符串操作速度
- 需要比较字符串的某些元素
- 比较字符串 .c_str() 和普通字符串的差异
- C 比较字符串的字符
- 通过使用两个不同的队列比较字符串