diff --git a/CHANGELOG.md b/CHANGELOG.md index 99ff59a0..dd5a382a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 9.0.0.1 - (In Progress) + +* Add `iswblank` compatibility. + ## 9.0.0 - 2016-12-28 * Update to Unicode Character Data 9.0.0. diff --git a/README.md b/README.md index 528d0ac8..ee0610f0 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ The following character classification functions are provided: |---------------|----------------| | `ucd_isalnum` | `ucd::isalnum` | | `ucd_isalpha` | `ucd::isalpha` | +| `ucd_isblank` | `ucd::isblank` | | `ucd_iscntrl` | `ucd::iscntrl` | | `ucd_isdigit` | `ucd::isdigit` | | `ucd_isgraph` | `ucd::isgraph` | @@ -105,7 +106,7 @@ The following character classification functions are provided: | `ucd_isspace` | `ucd::isspace` | | `ucd_isupper` | `ucd::isupper` | -__NOTE:__ Equivalents for `isblank` and `isxdigit` are not provided. +__NOTE:__ An equivalent for `isxdigit` is not provided. ## Build Dependencies diff --git a/src/ctype.c b/src/ctype.c index c4b63455..f1be7643 100644 --- a/src/ctype.c +++ b/src/ctype.c @@ -53,6 +53,19 @@ int ucd_isalpha(codepoint_t c) } } +int ucd_isblank(codepoint_t c) +{ + switch (ucd_lookup_category(c)) + { + case UCD_CATEGORY_Zs: + return 1; + case UCD_CATEGORY_Cc: + return c == 0x09; // U+0009 : CHARACTER TABULATION + default: + return 0; + } +} + int ucd_iscntrl(codepoint_t c) { return ucd_lookup_category(c) == UCD_CATEGORY_Cc; diff --git a/src/include/ucd/ucd.h b/src/include/ucd/ucd.h index cb87671b..ee415cc6 100644 --- a/src/include/ucd/ucd.h +++ b/src/include/ucd/ucd.h @@ -339,6 +339,13 @@ int ucd_isalnum(codepoint_t c); */ int ucd_isalpha(codepoint_t c); +/** @brief Is the codepoint a tab or Unicode whitespace character? + * + * @param c The Unicode codepoint to check. + * @return Non-zero if the codepoint is a whitespace character, zero otherwise. + */ +int ucd_isblank(codepoint_t c); + /** @brief Is the codepoint a control character? * * @param c The Unicode codepoint to check. @@ -776,6 +783,16 @@ namespace ucd return ucd_isalpha(c); } + /** @brief Is the codepoint a tab or Unicode whitespace character? + * + * @param c The Unicode codepoint to check. + * @return Non-zero if the codepoint is a whitespace character, zero otherwise. + */ + inline int isblank(codepoint_t c) + { + return ucd_isblank(c); + } + /** @brief Is the codepoint a control character? * * @param c The Unicode codepoint to check. diff --git a/tests/printcdata.c b/tests/printcdata.c index 4b3b9b58..8b19749a 100644 --- a/tests/printcdata.c +++ b/tests/printcdata.c @@ -114,6 +114,9 @@ void uprintf_is(FILE *out, codepoint_t c, char mode) case 'a': // alpha fputc(iswalpha(c) ? '1' : '0', out); break; + case 'b': // blank + fputc(iswblank(c) ? '1' : '0', out); + break; case 'c': // control fputc(iswcntrl(c) ? '1' : '0', out); break; diff --git a/tests/printucddata.c b/tests/printucddata.c index 557b756c..9400b547 100644 --- a/tests/printucddata.c +++ b/tests/printucddata.c @@ -111,6 +111,9 @@ void uprintf_is(FILE *out, codepoint_t c, char mode) case 'a': // alpha fputc(ucd_isalpha(c) ? '1' : '0', out); break; + case 'b': // blank + fputc(ucd_isblank(c) ? '1' : '0', out); + break; case 'c': // control fputc(ucd_iscntrl(c) ? '1' : '0', out); break; diff --git a/tests/printucddata_cpp.cpp b/tests/printucddata_cpp.cpp index 77dffa52..41e37605 100644 --- a/tests/printucddata_cpp.cpp +++ b/tests/printucddata_cpp.cpp @@ -111,6 +111,9 @@ void uprintf_is(FILE *out, ucd::codepoint_t c, char mode) case 'a': // alpha fputc(ucd::isalpha(c) ? '1' : '0', out); break; + case 'b': // blank + fputc(ucd::isblank(c) ? '1' : '0', out); + break; case 'c': // control fputc(ucd::iscntrl(c) ? '1' : '0', out); break;