开发者

How can I determine the Unicode block of a character, specifically a Qt QChar?

In Java, I was able to determine if a particula开发者_JS百科r character was for example, a Japanese Kanji using Unicode.blockOf(Character). I'm trying to do the same for a QChar, but couldn't find a relevant function to do this. I'm wondering if I just missed it, or will I have to roll my own, and if so - how?


There is QChar::Category however it does not provide everything you need.

For checking whether a char is in certain range, you could write a function like this:

bool inRange(QChar c, ushort b, ushort e) {
    return (c.unicode() >= b) && (c.unicode() <= e);
}

You could then use it like this:

inRange(c, 0x3040, 0x309F); // Hiragana?

Of course you could go further and make it more abstract and enumerate the ranges:

inRange(c, Range::Hiragana);

And here is the list of the Unicode Blocks


I don't know if there's a better Qt specific approach. If there isn't you could try using ICU rather than rolling your own solution.

ICU has both a "C/C++" version and a Java version. The Java version of ICU actually shares a common ancestor with some of the Java standard libraries for i18n/l10n, so the C/C++ version will hopefully be easy for you to figure out.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜