@@ -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 \ |
@@ -25,8 +25,6 @@ | |||
#include <stddef.h> | |||
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) |
@@ -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 | |||
@@ -58,8 +58,6 @@ if __name__ == '__main__': | |||
#include <stddef.h> | |||
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') |