c++qt

What is the difference between QChar::isDigit() and QChar::isNumber()?


I read the documentation, it says for QChar::isNumber() that

Returns true if the character is a number (Number_* categories, not just 0-9);

However, when I click on the Number_*, it sends me to a http://qt-project.org/doc/qt-5/stylesheet-reference.html#number, which is about Style Sheets, and it doesn't make sense - what do Style Sheets have to do with QChar?

So to know the difference, I need to know what those Number_* categories really are, and I think the link in the documentation doesn't explain it, instead it points me to documentation about Style Sheets.


Solution

  • The (correct) hint is hidden in the documentation isDigit():

    Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false.

    Here, the Number_* link is correct:

    QChar::Number_DecimalDigit    3   Unicode class name Nd
    QChar::Number_Letter          4   Unicode class name Nl
    QChar::Number_Other           5   Unicode class name No
    

    So isNumber() will check if the given QChar is part of the unicode classes Nd, Nl or No. For example, is classified as "Number, other", whereas (Roman numeral two) is classified as "Number, letter".