Question

In Java, I was able to determine if a particular 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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top