From 9f7478610f304dbb6d0d740191210b41ca22f346 Mon Sep 17 00:00:00 2001 From: Hyunjee Kim Date: Fri, 21 Apr 2017 14:59:23 +0900 Subject: [PATCH] [i18ninfo] Add Show Ubidi menu - Examples of the Unicode Bidirectional Algorithm - Usage: ./i18ninfo -b [input text] Change-Id: I1156b2a6d4ea7766edde71fefdbedca570cebde4 Signed-off-by: Hyunjee Kim Signed-off-by: MyoungJune Park --- i18ninfo/geni18n/i18n_str.sh | 8 +++ i18ninfo/geni18n/input.txt | 8 +++ i18ninfo/geni18n/run.sh | 6 +++ i18ninfo/i18ninfo.c | 111 +++++++++++++++++++++++++++++++++++++++++ i18ninfo/i18ninfo_argp.h | 13 +++++ packaging/capi-base-utils.spec | 2 +- 6 files changed, 147 insertions(+), 1 deletion(-) create mode 100755 i18ninfo/geni18n/i18n_str.sh create mode 100644 i18ninfo/geni18n/input.txt create mode 100755 i18ninfo/geni18n/run.sh diff --git a/i18ninfo/geni18n/i18n_str.sh b/i18ninfo/geni18n/i18n_str.sh new file mode 100755 index 0000000..d0491f4 --- /dev/null +++ b/i18ninfo/geni18n/i18n_str.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +while read str +do +# echo "Processing ($str)" + LANG=en_US.utf8 ASCIIDOC_FLAG=true i18ninfo -b "$str" +done < ./input.txt + diff --git a/i18ninfo/geni18n/input.txt b/i18ninfo/geni18n/input.txt new file mode 100644 index 0000000..1591210 --- /dev/null +++ b/i18ninfo/geni18n/input.txt @@ -0,0 +1,8 @@ +Tizen, خوش آمديد +(;0*1#2+3, +apps.samsung.com/gear. ++082-3004 +سيتم حذف MAN UTD MASTERCARD TITANIUM (1943). +010 3004 5417 +(אהבה (שירלי ++179 65 714 2499 diff --git a/i18ninfo/geni18n/run.sh b/i18ninfo/geni18n/run.sh new file mode 100755 index 0000000..b35aae9 --- /dev/null +++ b/i18ninfo/geni18n/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +sdb push input.txt /opt +sdb push i18n_str.sh /opt +sdb pull /opt/output.txt +asciidoc --backend=xhtml11 output.txt diff --git a/i18ninfo/i18ninfo.c b/i18ninfo/i18ninfo.c index b9cd2c1..d185361 100644 --- a/i18ninfo/i18ninfo.c +++ b/i18ninfo/i18ninfo.c @@ -59,6 +59,38 @@ i18n_udate_format_style_e eDateFormatStyle[] = { I18N_UDATE_NONE }; +typedef struct { + const char *display_name; + uint16_t option; +} reordering_option; + +#define N_OPTIONS 5 + +static reordering_option reordering_options[N_OPTIONS] = { + {"I18N_UBIDI_KEEP_BASE_COMBINING", I18N_UBIDI_KEEP_BASE_COMBINING}, + {"I18N_UBIDI_DO_MIRRORING", I18N_UBIDI_DO_MIRRORING}, + {"I18N_UBIDI_INSERT_LRM_FOR_NUMERIC", I18N_UBIDI_INSERT_LRM_FOR_NUMERIC}, + {"I18N_UBIDI_REMOVE_BIDI_CONTROLS", I18N_UBIDI_REMOVE_BIDI_CONTROLS}, + {"I18N_UBIDI_OUTPUT_REVERSE", I18N_UBIDI_OUTPUT_REVERSE}, +}; + +typedef struct { + const char *display_name; + i18n_ubidi_reordering_mode_e mode; +} reordering_mode; + +#define N_MODES I18N_UBIDI_REORDER_COUNT + +static reordering_mode reordering_modes[N_MODES] = { + {"I18N_UBIDI_REORDER_DEFAULT", I18N_UBIDI_REORDER_DEFAULT}, + {"I18N_UBIDI_REORDER_NUMBERS_SPECIAL", I18N_UBIDI_REORDER_NUMBERS_SPECIAL}, + {"I18N_UBIDI_REORDER_GROUP_NUMBERS_WITH_R", I18N_UBIDI_REORDER_GROUP_NUMBERS_WITH_R}, + {"I18N_UBIDI_REORDER_RUNS_ONLY", I18N_UBIDI_REORDER_RUNS_ONLY}, + {"I18N_UBIDI_REORDER_INVERSE_NUMBERS_AS_L", I18N_UBIDI_REORDER_INVERSE_NUMBERS_AS_L}, + {"I18N_UBIDI_REORDER_INVERSE_LIKE_DIRECT", I18N_UBIDI_REORDER_INVERSE_LIKE_DIRECT}, + {"I18N_UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL", I18N_UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL} +}; + int n_date_enum_size = sizeof(eDateFormatStyle) / sizeof(eDateFormatStyle[0]); int n_time_enum_size = sizeof(eTimeFormatStyle) / sizeof(eTimeFormatStyle[0]); @@ -905,6 +937,74 @@ static int __get_tzdata_version() return 0; } +static int32_t _get_uchar_length(const char *arr) +{ + int32_t ulen = strlen(arr); + i18n_uchar _text[ulen + 1]; + i18n_ustring_copy_ua(_text, arr); + + return i18n_ustring_get_length(_text); +} + +static int __show_ubidi(char *input_text) +{ + printf(" - Examples of the Unicode Bidirectional Algorithm\n"); + printf(" - input text : %s\n", input_text ? input_text : "Samsung is ﺱﺎﻤﺳﻮﻨﺟ in Arabic."); + printf("****************************************\n"); + + int i, j; + const char* text; + static i18n_ubidi_h ubidi; + i18n_ubidi_create(&ubidi); + + if (!input_text) { + text = "Samsung is سامسونج in Arabic"; + } else { + text = input_text; + } + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| %-46.46s | %-34.34s | %s \n", "MODES", "OPTIONS", "OUTPUT"); + + for (i = 0; i < N_MODES; i++) { + /* Sets ubidi reordering mode */ + int error_code = i18n_ubidi_set_reordering_mode(ubidi, reordering_modes[i].mode); + CHECK_ERROR("i18n_ubidi_set_reordering_mode", error_code); + + /* Sets ubidi paragraphs and perform the Unicode bidi algorithm */ + int src_length = _get_uchar_length(text); + PRINT_DEBUG_LOG("src_length: %d\n", src_length); + + i18n_uchar *src = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (src_length + 1)); + i18n_ustring_copy_ua(src, text); + error_code = i18n_ubidi_set_para(ubidi, src, src_length, I18N_UBIDI_DEFAULT_LTR, NULL); + + /* Writes ubidi reordered text to the entry with write_options */ + i18n_uchar dst[BUF_SIZE]; + int output_length = 0; + + for (j = 0; j < N_OPTIONS; j++) { + error_code = i18n_ubidi_write_reordered(ubidi, reordering_options[j].option, BUF_SIZE, + dst, &output_length); + CHECK_ERROR("i18n_ubidi_write_reordered", error_code); + + char buffer[BUF_SIZE]; + i18n_ustring_copy_au(buffer, dst); + printf("| %-46.46s | %-34.34s | %s \n", reordering_modes[i].display_name, reordering_options[j].display_name, buffer); + } + free(src); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + if (ubidi != NULL) { + i18n_ubidi_destroy(ubidi); + ubidi = NULL; + } + + return 0; +} + void allTest() { int ret = 0, i = 0; @@ -1009,6 +1109,13 @@ void showTzdataVersion() __get_tzdata_version(); } +void showUbidi(char *input) +{ + printf("\n== Show Ubidi"); + printf("\n****************************************\n"); + __show_ubidi(input); +} + void showDatentimeFormat(char *locale) { int ret = 0, i = 0; @@ -1207,5 +1314,9 @@ int main(int argc, char *argv[]) showTzdataVersion(); } + if (arguments.showUbidi) { + showUbidi(arguments.testTextArg); + } + return 0; } diff --git a/i18ninfo/i18ninfo_argp.h b/i18ninfo/i18ninfo_argp.h index 2025d39..0ea3062 100644 --- a/i18ninfo/i18ninfo_argp.h +++ b/i18ninfo/i18ninfo_argp.h @@ -25,6 +25,7 @@ static struct argp_option options[] = { {"test-string", 's', "Word", OPTION_ARG_OPTIONAL, "String test", 0 }, {"test-string-iter", 'S', "Type", OPTION_ARG_OPTIONAL, "String iteration test", 0 }, {"set-locale", 'l', "locale", 0, "Set specific locale", 0 }, + {"show-ubidi", 'b', 0, OPTION_ARG_OPTIONAL, "Show examples of the Unicode Bidirectional Algorithm", 0 }, { 0 } }; @@ -41,6 +42,7 @@ struct arguments { int testNumberSymbol; int testString; int testStringIter; + int showUbidi; char *arg1; /* arg1 */ char **strings; /* [string…] */ @@ -49,6 +51,7 @@ struct arguments { char *testNumberFormatArg; char *testStringArg; char *testStringIterArg; + char *testTextArg; char *setLocale; }; @@ -129,9 +132,19 @@ parse_opt(int key, char *arg, struct argp_state *state) } break; case 'l': + arguments->arg_flag = 12; arguments->setLocale = arg; break; + case 'b': + arguments->arg_flag = 13; + arguments->showUbidi = 1; + nextArg = state->argv[state->next]; + if (nextArg && *nextArg != '-') { + arguments->testTextArg = nextArg; + state->next++; + } + break; case ARGP_KEY_NO_ARGS: if (arguments->arg_flag == 0) { argp_usage(state); diff --git a/packaging/capi-base-utils.spec b/packaging/capi-base-utils.spec index f4a242f..dd0333e 100755 --- a/packaging/capi-base-utils.spec +++ b/packaging/capi-base-utils.spec @@ -28,7 +28,7 @@ The base utils library for internationalization and localization (Development) %package -n i18ninfo License: Apache-2.0 Summary: The Base Utils Tool -Version: 1.0.0 +Version: 1.0.1 Group: Base Requires: capi-base-utils -- 2.7.4