From 0afcb3f89f7c3ecd8fc7cbfbafc914fc27fbed86 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Mon, 30 May 2016 23:41:04 +0100 Subject: [PATCH] Convert case.cpp from C++ to C. --- Makefile.am | 4 ++-- src/{case.cpp => case.c} | 25 ++++--------------------- src/include/ucd/ucd.h | 15 ++++++++++++--- tools/case.py | 11 ++--------- 4 files changed, 20 insertions(+), 35 deletions(-) rename src/{case.cpp => case.c} (99%) diff --git a/Makefile.am b/Makefile.am index c178f727..b2a6e976 100644 --- a/Makefile.am +++ b/Makefile.am @@ -93,7 +93,7 @@ tools/scripts.py: tools/ucd.py \ data/ucd/Scripts.txt ucd-update: tools/case.py tools/categories.py tools/scripts.py - tools/case.py ${UCD_ROOTDIR} ${UCD_VERSION} ${UCD_FLAGS} > src/case.cpp + tools/case.py ${UCD_ROOTDIR} ${UCD_VERSION} ${UCD_FLAGS} > src/case.c tools/categories.py ${UCD_ROOTDIR} ${UCD_VERSION} ${UCD_FLAGS} > src/categories.cpp tools/scripts.py ${UCD_ROOTDIR} ${UCD_VERSION} ${UCD_FLAGS} > src/scripts.cpp @@ -104,7 +104,7 @@ libucd_include_HEADERS = \ lib_LTLIBRARIES += src/libucd.la src_libucd_la_LDFLAGS = -version-info $(LIBUCD_VERSION) src_libucd_la_SOURCES = \ - src/case.cpp \ + src/case.c \ src/categories.cpp \ src/ctype.c \ src/scripts.cpp \ diff --git a/src/case.cpp b/src/case.c similarity index 99% rename from src/case.cpp rename to src/case.c index 98c521cc..5d3370d0 100644 --- a/src/case.cpp +++ b/src/case.c @@ -25,8 +25,6 @@ #include -using namespace ucd; - // Unicode Character Data 8.0.0 struct case_conversion_entry @@ -37,7 +35,7 @@ struct case_conversion_entry codepoint_t titlecase; }; -static const case_conversion_entry case_conversion_data[] = +static const struct case_conversion_entry case_conversion_data[] = { { 0x000041, 0x000000, 0x000061, 0x000000 }, { 0x000042, 0x000000, 0x000062, 0x000000 }, @@ -2512,18 +2510,13 @@ static const case_conversion_entry case_conversion_data[] = }; codepoint_t ucd_toupper(codepoint_t c) -{ - return ucd::toupper(c); -} - -ucd::codepoint_t ucd::toupper(codepoint_t c) { int begin = 0; int end = sizeof(case_conversion_data)/sizeof(case_conversion_data[0]); while (begin <= end) { int pos = (begin + end) / 2; - const case_conversion_entry *item = (case_conversion_data + pos); + const struct case_conversion_entry *item = (case_conversion_data + pos); if (c == item->codepoint) return item->uppercase == 0 ? c : item->uppercase; else if (c > item->codepoint) @@ -2535,18 +2528,13 @@ ucd::codepoint_t ucd::toupper(codepoint_t c) } codepoint_t ucd_tolower(codepoint_t c) -{ - return ucd::tolower(c); -} - -ucd::codepoint_t ucd::tolower(codepoint_t c) { int begin = 0; int end = sizeof(case_conversion_data)/sizeof(case_conversion_data[0]); while (begin <= end) { int pos = (begin + end) / 2; - const case_conversion_entry *item = (case_conversion_data + pos); + const struct case_conversion_entry *item = (case_conversion_data + pos); if (c == item->codepoint) return item->lowercase == 0 ? c : item->lowercase; else if (c > item->codepoint) @@ -2558,18 +2546,13 @@ ucd::codepoint_t ucd::tolower(codepoint_t c) } codepoint_t ucd_totitle(codepoint_t c) -{ - return ucd::totitle(c); -} - -ucd::codepoint_t ucd::totitle(codepoint_t c) { int begin = 0; int end = sizeof(case_conversion_data)/sizeof(case_conversion_data[0]); while (begin <= end) { int pos = (begin + end) / 2; - const case_conversion_entry *item = (case_conversion_data + pos); + const struct case_conversion_entry *item = (case_conversion_data + pos); if (c == item->codepoint) return item->titlecase == 0 ? c : item->titlecase; else if (c > item->codepoint) diff --git a/src/include/ucd/ucd.h b/src/include/ucd/ucd.h index b2b9fe8e..61b38ce0 100644 --- a/src/include/ucd/ucd.h +++ b/src/include/ucd/ucd.h @@ -844,7 +844,10 @@ namespace ucd * @return The upper-case Unicode codepoint for this codepoint, or * this codepoint if there is no upper-case codepoint. */ - codepoint_t toupper(codepoint_t c); + inline codepoint_t toupper(codepoint_t c) + { + return ucd_toupper(c); + } /** @brief Convert the Unicode codepoint to lower-case. * @@ -856,7 +859,10 @@ namespace ucd * @return The lower-case Unicode codepoint for this codepoint, or * this codepoint if there is no upper-case codepoint. */ - codepoint_t tolower(codepoint_t c); + inline codepoint_t tolower(codepoint_t c) + { + return ucd_tolower(c); + } /** @brief Convert the Unicode codepoint to title-case. * @@ -868,7 +874,10 @@ namespace ucd * @return The title-case Unicode codepoint for this codepoint, or * this codepoint if there is no upper-case codepoint. */ - codepoint_t totitle(codepoint_t c); + inline codepoint_t totitle(codepoint_t c) + { + return ucd_totitle(c); + } } #endif diff --git a/tools/case.py b/tools/case.py index 345d643e..7af5d55c 100755 --- a/tools/case.py +++ b/tools/case.py @@ -58,8 +58,6 @@ if __name__ == '__main__': #include -using namespace ucd; - // Unicode Character Data %s struct case_conversion_entry @@ -72,7 +70,7 @@ struct case_conversion_entry """ % ucd_version) sys.stdout.write('\n') - sys.stdout.write('static const case_conversion_entry case_conversion_data[] =\n') + sys.stdout.write('static const struct case_conversion_entry case_conversion_data[] =\n') sys.stdout.write('{\n') for codepoint in sorted(unicode_chars.keys()): lower, upper, title = unicode_chars[codepoint] @@ -83,17 +81,12 @@ struct case_conversion_entry sys.stdout.write('\n') sys.stdout.write('codepoint_t ucd_to%s(codepoint_t c)\n' % case) sys.stdout.write('{\n') - sys.stdout.write('\treturn ucd::to%s(c);\n' % case) - sys.stdout.write('}\n') - sys.stdout.write('\n') - sys.stdout.write('ucd::codepoint_t ucd::to%s(codepoint_t c)\n' % case) - sys.stdout.write('{\n') sys.stdout.write('\tint begin = 0;\n') sys.stdout.write('\tint end = sizeof(case_conversion_data)/sizeof(case_conversion_data[0]);\n') sys.stdout.write('\twhile (begin <= end)\n') sys.stdout.write('\t{\n') sys.stdout.write('\t\tint pos = (begin + end) / 2;\n') - sys.stdout.write('\t\tconst case_conversion_entry *item = (case_conversion_data + pos);\n') + sys.stdout.write('\t\tconst struct case_conversion_entry *item = (case_conversion_data + pos);\n') sys.stdout.write('\t\tif (c == item->codepoint)\n') sys.stdout.write('\t\t\treturn item->%scase == 0 ? c : item->%scase;\n' % (case, case)) sys.stdout.write('\t\telse if (c > item->codepoint)\n')