gpt4 book ai didi

c++ - ICU 探测所有货币符号

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

有没有办法探测ICU library对于所有 UChar's表示库支持的货币符号?

我当前的解决方案是遍历所有语言环境并针对每个语言环境,执行如下操作:

const DecimalFormatSymbols *formatSymbols = formatter->getDecimalFormatSymbols();
UnicodeString currencySymbol = formatSymbols->getSymbol(DecimalFormatSymbols::kCurrencySymbol);

然后将 currencySymbol 中的每个 UChar 保存到 map 中(因此没有重复项)。

最佳答案

所有货币符号都有类别 Sc(符号、货币),因此您可以枚举该类别中的所有字符。

#include <cstdio>
#include <icu/unicode/uchar.h>

UBool print_all_currency_symbols(const void* context, UChar32 start, UChar32 limit, UCharCategory type) {
if (type == U_CURRENCY_SYMBOL) {
for (UChar32 c = start; c < limit; ++ c)
printf("%04x\n", c);
}
return TRUE;
}

int main() {
u_enumCharTypes(print_all_currency_symbols, NULL);

return 0;
}

关于c++ - ICU 探测所有货币符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3916575/

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