开发者

ICU Probe All Currency Symbols

Is there a way to probe the ICU library for all UChar's representing currency symbols supported by the library?

My current solution is iterating through all locales and for each locale, doing something like this:

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

The开发者_开发知识库n saving off each UChar in currencySymbol into a map (so no duplicates).


All currency symbols have the category Sc (Symbol, Currency), so you can just enumerate all characters from that category.

#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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜