c++qtunicodeqchar

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


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?


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