Search code examples
c++cposixlocale

Is there narrow characters version of iswctype() function?


Is there any kind of narrow character function like there is iswctype() for wide characters?

UPDATE

I did not realize there was std::regex_traits::isctype(), otherwise I would have made the question explain the situation better:

I am actually implementing std::ctype<char> facet itself so I cannot use std::regex_traits::isctype() as itself depends on std::ctype<char>::is().

Please suggest POSIX or C99 function instead.


Solution

  • POSIX says, for the extended character classes,

    The charclass-name can be used as the property argument to the wctype() function, in regular expression and shell pattern-matching bracket expressions, and by the tr command.

    and the POSIX regex page, correspondingly, says

    In addition, character class expressions of the form:

    [:name:]

    are recognized in those locales where the name keyword has been given a charclass definition in the LC_CTYPE category.

    So, to reach an extended classification in a narrow-character locale, the only POSIX-compliant way appears to be the POSIX regex class, much like the only way to get to it in C++ is the already-mentioned std::regex_traits::isctype.

    Perhaps you're better off reaching into platform-specific APIs, in terms of which these functions are implemented (where accessible).

    PS: Perhaps the more practical approach is to just call btowc and iswctype. A locale that classifies a narrow char and its widened form differently is questionable to say the least.