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]);
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;
__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;
showTzdataVersion();
}
+ if (arguments.showUbidi) {
+ showUbidi(arguments.testTextArg);
+ }
+
return 0;
}
{"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 }
};
int testNumberSymbol;
int testString;
int testStringIter;
+ int showUbidi;
char *arg1; /* arg1 */
char **strings; /* [string…] */
char *testNumberFormatArg;
char *testStringArg;
char *testStringIterArg;
+ char *testTextArg;
char *setLocale;
};
}
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);