Create a C-based API in addition to the C++-based API in <ucd/ucd.h>.

This commit is contained in:
Reece H. Dunn
2016-05-30 22:29:04 +01:00
parent bddb25bdc7
commit 454038dbfa
9 changed files with 754 additions and 220 deletions
+7 -2
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
# Copyright (C) 2012 Reece H. Dunn
# Copyright (C) 2012-2016 Reece H. Dunn
#
# This file is part of ucd-tools.
#
@@ -33,7 +33,7 @@ for data in ucd.parse_ucd_data(ucd_rootdir, 'UnicodeData'):
if __name__ == '__main__':
sys.stdout.write("""/* Unicode Case Conversion
*
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2012-2016 Reece H. Dunn
*
* This file is part of ucd-tools.
*
@@ -80,6 +80,11 @@ struct case_conversion_entry
sys.stdout.write('};\n')
for case in ['upper', 'lower', 'title']:
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')
+18 -2
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
# Copyright (C) 2012, 2014 Reece H. Dunn
# Copyright (C) 2012-2016 Reece H. Dunn
#
# This file is part of ucd-tools.
#
@@ -92,7 +92,7 @@ for codepoints, category, comment in category_sets:
if __name__ == '__main__':
sys.stdout.write("""/* Unicode General Categories
*
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2012-2016 Reece H. Dunn
*
* This file is part of ucd-tools.
*
@@ -162,6 +162,12 @@ using namespace ucd;
sys.stdout.write('\tcategories_%s,\n' % codepoint)
sys.stdout.write('};\n')
sys.stdout.write("""
ucd_category ucd_lookup_category(codepoint_t c)
{
return (ucd_category)ucd::lookup_category((ucd::category)c);
}
""")
sys.stdout.write('\n')
sys.stdout.write('ucd::category ucd::lookup_category(codepoint_t c)\n')
sys.stdout.write('{\n')
@@ -178,6 +184,11 @@ using namespace ucd;
sys.stdout.write('}\n')
sys.stdout.write("""
ucd_category_group ucd_get_category_group_for_category(ucd_category c)
{
return (ucd_category_group)ucd::lookup_category_group((ucd::category)c);
}
ucd::category_group ucd::lookup_category_group(category c)
{
switch (c)
@@ -201,6 +212,11 @@ ucd::category_group ucd::lookup_category_group(category c)
}
}
ucd_category_group ucd_lookup_category_group(codepoint_t c)
{
return (ucd_category_group)ucd::lookup_category_group(ucd::lookup_category(c));
}
ucd::category_group ucd::lookup_category_group(codepoint_t c)
{
return lookup_category_group(lookup_category(c));
+8 -2
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
# Copyright (C) 2012, 2014 Reece H. Dunn
# Copyright (C) 2012-2016 Reece H. Dunn
#
# This file is part of ucd-tools.
#
@@ -86,7 +86,7 @@ for codepoints, script, comment in script_sets:
if __name__ == '__main__':
sys.stdout.write("""/* Unicode Scripts
*
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2012-2016 Reece H. Dunn
*
* This file is part of ucd-tools.
*
@@ -156,6 +156,12 @@ using namespace ucd;
sys.stdout.write('\tscripts_%s,\n' % codepoint)
sys.stdout.write('};\n')
sys.stdout.write("""
ucd_script ucd_lookup_script(codepoint_t c)
{
return (ucd_script)ucd::lookup_script(c);
}
""")
sys.stdout.write('\n')
sys.stdout.write('ucd::script ucd::lookup_script(codepoint_t c)\n')
sys.stdout.write('{\n')