diff --git a/CHANGELOG.md b/CHANGELOG.md index dd5a382a..26289ca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 9.0.0.1 - (In Progress) -* Add `iswblank` compatibility. +* Add `iswblank` and `iswxdigit` compatibility. ## 9.0.0 - 2016-12-28 diff --git a/README.md b/README.md index ee0610f0..36e06e80 100644 --- a/README.md +++ b/README.md @@ -92,21 +92,20 @@ C library provides a set of APIs that are compatible with `wctype.h`. The following character classification functions are provided: -| C API | C++ API | -|---------------|----------------| -| `ucd_isalnum` | `ucd::isalnum` | -| `ucd_isalpha` | `ucd::isalpha` | -| `ucd_isblank` | `ucd::isblank` | -| `ucd_iscntrl` | `ucd::iscntrl` | -| `ucd_isdigit` | `ucd::isdigit` | -| `ucd_isgraph` | `ucd::isgraph` | -| `ucd_islower` | `ucd::islower` | -| `ucd_isprint` | `ucd::isprint` | -| `ucd_ispunct` | `ucd::ispunct` | -| `ucd_isspace` | `ucd::isspace` | -| `ucd_isupper` | `ucd::isupper` | - -__NOTE:__ An equivalent for `isxdigit` is not provided. +| C API | C++ API | +|----------------|-----------------| +| `ucd_isalnum` | `ucd::isalnum` | +| `ucd_isalpha` | `ucd::isalpha` | +| `ucd_isblank` | `ucd::isblank` | +| `ucd_iscntrl` | `ucd::iscntrl` | +| `ucd_isdigit` | `ucd::isdigit` | +| `ucd_isgraph` | `ucd::isgraph` | +| `ucd_islower` | `ucd::islower` | +| `ucd_isprint` | `ucd::isprint` | +| `ucd_ispunct` | `ucd::ispunct` | +| `ucd_isspace` | `ucd::isspace` | +| `ucd_isupper` | `ucd::isupper` | +| `ucd_isxdigit` | `ucd::isxdigit` | ## Build Dependencies diff --git a/src/ctype.c b/src/ctype.c index f1be7643..30edfb93 100644 --- a/src/ctype.c +++ b/src/ctype.c @@ -169,3 +169,10 @@ int ucd_isupper(codepoint_t c) { return ucd_lookup_category(c) == UCD_CATEGORY_Lu; } + +int ucd_isxdigit(codepoint_t c) +{ + return (c >= 0x30 && c <= 0x39) // [0-9] + || (c >= 0x41 && c <= 0x46) // [A-Z] + || (c >= 0x61 && c <= 0x66); // [a-z] +} diff --git a/src/include/ucd/ucd.h b/src/include/ucd/ucd.h index 6693329c..b4bff02a 100644 --- a/src/include/ucd/ucd.h +++ b/src/include/ucd/ucd.h @@ -402,6 +402,13 @@ int ucd_isspace(codepoint_t c); */ int ucd_isupper(codepoint_t c); +/** @brief Is the codepoint in the 'xdigit' class? + * + * @param c The Unicode codepoint to check. + * @return Non-zero if the codepoint is in the 'xdigit' class, zero otherwise. + */ +int ucd_isxdigit(codepoint_t c); + /** @brief Convert the Unicode codepoint to upper-case. * * This function only uses the simple case mapping present in the @@ -873,6 +880,16 @@ namespace ucd return ucd_isupper(c); } + /** @brief Is the codepoint in the 'xdigit' class? + * + * @param c The Unicode codepoint to check. + * @return Non-zero if the codepoint is in the 'xdigit' class, zero otherwise. + */ + inline int isxdigit(codepoint_t c) + { + return ucd_isxdigit(c); + } + /** @brief Convert the Unicode codepoint to upper-case. * * This function only uses the simple case mapping present in the diff --git a/tests/printcdata.c b/tests/printcdata.c index 8b19749a..24d57c92 100644 --- a/tests/printcdata.c +++ b/tests/printcdata.c @@ -141,6 +141,9 @@ void uprintf_is(FILE *out, codepoint_t c, char mode) case 'u': // upper case fputc(iswupper(c) ? '1' : '0', out); break; + case 'x': // xdigit + fputc(iswxdigit(c) ? '1' : '0', out); + break; } } diff --git a/tests/printucddata.c b/tests/printucddata.c index 9400b547..e397f12e 100644 --- a/tests/printucddata.c +++ b/tests/printucddata.c @@ -138,6 +138,9 @@ void uprintf_is(FILE *out, codepoint_t c, char mode) case 'u': // upper case fputc(ucd_isupper(c) ? '1' : '0', out); break; + case 'x': // xdigit + fputc(ucd_isxdigit(c) ? '1' : '0', out); + break; } } diff --git a/tests/printucddata_cpp.cpp b/tests/printucddata_cpp.cpp index 41e37605..2318b09a 100644 --- a/tests/printucddata_cpp.cpp +++ b/tests/printucddata_cpp.cpp @@ -138,6 +138,9 @@ void uprintf_is(FILE *out, ucd::codepoint_t c, char mode) case 'u': // upper case fputc(ucd::isupper(c) ? '1' : '0', out); break; + case 'x': // xdigit + fputc(ucd::isxdigit(c) ? '1' : '0', out); + break; } }