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?
Asked
Active
Viewed 874 times
2 Answers
4
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
-
1why not just "return c.unicode() >= b && c.unicode() <= e;"? Constant complexity vs. linear... – Frank Osterfeld Dec 12 '10 at 21:05
-
Yes, that would be indeed better :) Edited. – Palmik Dec 12 '10 at 21:06
0
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.

Laurence Gonsalves
- 137,896
- 35
- 246
- 299
-
I have mixed feelings about adding an extra library dependency to my application for something so simple. As I see it, it should be easy to retrieve some kind of character code of my character and then to test it against some range of codes as defined in the Unicode standard - am I wrong? – neuviemeporte Dec 12 '10 at 20:45