From 63b08a352b9ca8e0a59f72f44d4c5cf7d548515d Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Mon, 30 May 2016 23:28:28 +0100 Subject: [PATCH] Convert ctype.cpp from C++ to C. --- Makefile.am | 2 +- src/{ctype.cpp => ctype.c} | 124 ++++++++++++++++--------------------- src/include/ucd/ucd.h | 50 ++++++++++++--- 3 files changed, 93 insertions(+), 83 deletions(-) rename src/{ctype.cpp => ctype.c} (56%) diff --git a/Makefile.am b/Makefile.am index 64dbc31e..c178f727 100644 --- a/Makefile.am +++ b/Makefile.am @@ -106,7 +106,7 @@ src_libucd_la_LDFLAGS = -version-info $(LIBUCD_VERSION) src_libucd_la_SOURCES = \ src/case.cpp \ src/categories.cpp \ - src/ctype.cpp \ + src/ctype.c \ src/scripts.cpp \ src/tostring.c diff --git a/src/ctype.cpp b/src/ctype.c similarity index 56% rename from src/ctype.cpp rename to src/ctype.c index f7e410dd..c4b63455 100644 --- a/src/ctype.cpp +++ b/src/ctype.c @@ -22,15 +22,16 @@ int ucd_isalnum(codepoint_t c) { - return ucd::isalnum(c); -} - -int ucd::isalnum(codepoint_t c) -{ - switch (lookup_category(c)) + switch (ucd_lookup_category(c)) { - case Ll: case Lm: case Lo: case Lt: case Lu: - case Nd: case Nl: case No: + case UCD_CATEGORY_Ll: + case UCD_CATEGORY_Lm: + case UCD_CATEGORY_Lo: + case UCD_CATEGORY_Lt: + case UCD_CATEGORY_Lu: + case UCD_CATEGORY_Nd: + case UCD_CATEGORY_Nl: + case UCD_CATEGORY_No: return 1; default: return 0; @@ -39,14 +40,13 @@ int ucd::isalnum(codepoint_t c) int ucd_isalpha(codepoint_t c) { - return ucd::isalpha(c); -} - -int ucd::isalpha(codepoint_t c) -{ - switch (lookup_category(c)) + switch (ucd_lookup_category(c)) { - case Ll: case Lm: case Lo: case Lt: case Lu: + case UCD_CATEGORY_Ll: + case UCD_CATEGORY_Lm: + case UCD_CATEGORY_Lo: + case UCD_CATEGORY_Lt: + case UCD_CATEGORY_Lu: return 1; default: return 0; @@ -55,24 +55,16 @@ int ucd::isalpha(codepoint_t c) int ucd_iscntrl(codepoint_t c) { - return ucd::iscntrl(c); -} - -int ucd::iscntrl(codepoint_t c) -{ - return lookup_category(c) == Cc; + return ucd_lookup_category(c) == UCD_CATEGORY_Cc; } int ucd_isdigit(codepoint_t c) { - return ucd::isdigit(c); -} - -int ucd::isdigit(codepoint_t c) -{ - switch (lookup_category(c)) + switch (ucd_lookup_category(c)) { - case Nd: case Nl: case No: + case UCD_CATEGORY_Nd: + case UCD_CATEGORY_Nl: + case UCD_CATEGORY_No: return 1; default: return 0; @@ -81,16 +73,17 @@ int ucd::isdigit(codepoint_t c) int ucd_isgraph(codepoint_t c) { - return ucd::isgraph(c); -} - -int ucd::isgraph(codepoint_t c) -{ - switch (lookup_category(c)) + switch (ucd_lookup_category(c)) { - case Cc: case Cf: case Cn: case Co: case Cs: - case Zl: case Zp: case Zs: - case Ii: + case UCD_CATEGORY_Cc: + case UCD_CATEGORY_Cf: + case UCD_CATEGORY_Cn: + case UCD_CATEGORY_Co: + case UCD_CATEGORY_Cs: + case UCD_CATEGORY_Zl: + case UCD_CATEGORY_Zp: + case UCD_CATEGORY_Zs: + case UCD_CATEGORY_Ii: return 0; default: return 1; @@ -99,25 +92,19 @@ int ucd::isgraph(codepoint_t c) int ucd_islower(codepoint_t c) { - return ucd::islower(c); -} - -int ucd::islower(codepoint_t c) -{ - return lookup_category(c) == Ll; + return ucd_lookup_category(c) == UCD_CATEGORY_Ll; } int ucd_isprint(codepoint_t c) { - return ucd::isprint(c); -} - -int ucd::isprint(codepoint_t c) -{ - switch (lookup_category(c)) + switch (ucd_lookup_category(c)) { - case Cc: case Cf: case Cn: case Co: case Cs: - case Ii: + case UCD_CATEGORY_Cc: + case UCD_CATEGORY_Cf: + case UCD_CATEGORY_Cn: + case UCD_CATEGORY_Co: + case UCD_CATEGORY_Cs: + case UCD_CATEGORY_Ii: return 0; default: return 1; @@ -126,14 +113,15 @@ int ucd::isprint(codepoint_t c) int ucd_ispunct(codepoint_t c) { - return ucd::ispunct(c); -} - -int ucd::ispunct(codepoint_t c) -{ - switch (lookup_category(c)) + switch (ucd_lookup_category(c)) { - case Pc: case Pd: case Pe: case Pf: case Pi: case Po: case Ps: + case UCD_CATEGORY_Pc: + case UCD_CATEGORY_Pd: + case UCD_CATEGORY_Pe: + case UCD_CATEGORY_Pf: + case UCD_CATEGORY_Pi: + case UCD_CATEGORY_Po: + case UCD_CATEGORY_Ps: return 1; default: return 0; @@ -142,16 +130,13 @@ int ucd::ispunct(codepoint_t c) int ucd_isspace(codepoint_t c) { - return ucd::isspace(c); -} - -int ucd::isspace(codepoint_t c) -{ - switch (lookup_category(c)) + switch (ucd_lookup_category(c)) { - case Zl: case Zp: case Zs: + case UCD_CATEGORY_Zl: + case UCD_CATEGORY_Zp: + case UCD_CATEGORY_Zs: return 1; - case Cc: + case UCD_CATEGORY_Cc: switch (c) // Some control characters are also whitespace characters: { case 0x09: // U+0009 : CHARACTER TABULATION @@ -169,10 +154,5 @@ int ucd::isspace(codepoint_t c) int ucd_isupper(codepoint_t c) { - return ucd::isupper(c); -} - -int ucd::isupper(codepoint_t c) -{ - return lookup_category(c) == Lu; + return ucd_lookup_category(c) == UCD_CATEGORY_Lu; } diff --git a/src/include/ucd/ucd.h b/src/include/ucd/ucd.h index 04702b74..b2b9fe8e 100644 --- a/src/include/ucd/ucd.h +++ b/src/include/ucd/ucd.h @@ -739,70 +739,100 @@ namespace ucd * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is a letter or number, zero otherwise. */ - int isalnum(codepoint_t c); + inline int isalnum(codepoint_t c) + { + return ucd_isalnum(c); + } /** @brief Is the codepoint a letter? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is a letter, zero otherwise. */ - int isalpha(codepoint_t c); + inline int isalpha(codepoint_t c) + { + return ucd_isalpha(c); + } /** @brief Is the codepoint a control character? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is a control character, zero otherwise. */ - int iscntrl(codepoint_t c); + inline int iscntrl(codepoint_t c) + { + return ucd_iscntrl(c); + } /** @brief Is the codepoint a numeric character? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is a number, zero otherwise. */ - int isdigit(codepoint_t c); + inline int isdigit(codepoint_t c) + { + return ucd_isdigit(c); + } /** @brief Does the codepoint have a displayable glyph? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint has a displayable glyph, zero otherwise. */ - int isgraph(codepoint_t c); + inline int isgraph(codepoint_t c) + { + return ucd_isgraph(c); + } /** @brief Is the codepoint a lower-case letter? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is a lower-case letter, zero otherwise. */ - int islower(codepoint_t c); + inline int islower(codepoint_t c) + { + return ucd_islower(c); + } /** @brief Is the codepoint a printable character? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is a printable character, zero otherwise. */ - int isprint(codepoint_t c); + inline int isprint(codepoint_t c) + { + return ucd_isprint(c); + } /** @brief Is the codepoint a punctuation character? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is a punctuation character, zero otherwise. */ - int ispunct(codepoint_t c); + inline int ispunct(codepoint_t c) + { + return ucd_ispunct(c); + } /** @brief Is the codepoint a whitespace character? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is a whitespace character, zero otherwise. */ - int isspace(codepoint_t c); + inline int isspace(codepoint_t c) + { + return ucd_isspace(c); + } /** @brief Is the codepoint an upper-case letter? * * @param c The Unicode codepoint to check. * @return Non-zero if the codepoint is an upper-case letter, zero otherwise. */ - int isupper(codepoint_t c); + inline int isupper(codepoint_t c) + { + return ucd_isupper(c); + } /** @brief Convert the Unicode codepoint to upper-case. *