--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <assert.h>
+#include "i18ninfo_argp.h"
+
+#include <utils_i18n.h>
+
+#define DEBUG_FLAG 0
+
+#define BUF_SIZE 64
+#define MS_TO_MIN 60000
+#define MS_TO_HOUR 3600000
+
+#define PRINT_ERROR_LOG(func_name, error_code) if (DEBUG_FLAG) { \
+ fprintf(stderr, "\033[0;31m%s failed! Error: %s [code: %d] \033[0m\n",\
+ func_name, get_error_message(error_code), error_code); \
+ }
+
+#define PRINT_DEBUG_LOG(fmt, arg...) if (DEBUG_FLAG) { do {\
+ fprintf(stdout, "\033[0;32m" fmt "\033[1;32m \033[0m", ##arg); } while (0); \
+ }
+
+#define CHECK_ERROR(fun_name, error_code) if (error_code != 0) { \
+ PRINT_ERROR_LOG(fun_name, error_code); \
+ }
+
+
+char *default_locale = I18N_ULOCALE_UK;
+i18n_uchar default_timezone_id[BUF_SIZE] = {0,};
+
+i18n_udate_format_style_e eTimeFormatStyle[] = {
+ I18N_UDATE_FULL,
+ I18N_UDATE_LONG,
+ I18N_UDATE_MEDIUM,
+ I18N_UDATE_SHORT,
+ I18N_UDATE_NONE
+};
+
+i18n_udate_format_style_e eDateFormatStyle[] = {
+ I18N_UDATE_FULL,
+ I18N_UDATE_LONG,
+ I18N_UDATE_MEDIUM,
+ I18N_UDATE_SHORT,
+ I18N_UDATE_RELATIVE,
+ I18N_UDATE_LONG_RELATIVE,
+ I18N_UDATE_MEDIUM_RELATIVE,
+ I18N_UDATE_SHORT_RELATIVE,
+ I18N_UDATE_NONE
+};
+
+int n_date_enum_size = sizeof(eDateFormatStyle) / sizeof(eDateFormatStyle[0]);
+int n_time_enum_size = sizeof(eTimeFormatStyle) / sizeof(eTimeFormatStyle[0]);
+
+int n_enum_time_counter, n_enum_date_counter, error_code;
+
+
+static void __get_available_locales();
+static int __get_date_and_time();
+static int __get_number_format(char *input_number);
+static int __get_symbol();
+static int __get_language_info();
+static int __manage_string_iteration(char *custom_type);
+static int __analyze_string(char *custom_string);
+static int __get_timezone_info();
+
+char *__print_i18n_type_string(char *type, int num);
+
+static void __get_available_locales()
+{
+ const char *loc_list;
+ int32_t loc_count, i;
+
+ loc_count = i18n_ulocale_count_available();
+ if (loc_count == 0)
+ printf("empty\n");
+ else if (loc_count < 0)
+ printf("wrong\n");
+ else {
+ PRINT_DEBUG_LOG("locale count : %d\n", loc_count);
+ for (i = 0; i < loc_count; i++) {
+ loc_list = i18n_ulocale_get_available(i);
+ printf("%s\n", loc_list);
+ }
+ }
+}
+
+char *__print_i18n_type_string(char *type, int num)
+{
+ char *str = calloc(300, sizeof(char));
+ PRINT_DEBUG_LOG("input type: %s, num: %d\n", type, num);
+ if (type == "time") {
+ switch (num) {
+ case 0:
+ strcpy(str, "I18N_UDATE_FULL");
+ break;
+ case 1:
+ strcpy(str, "I18N_UDATE_LONG");
+ break;
+ case 2:
+ strcpy(str, "I18N_UDATE_MEDIUM");
+ break;
+ case 3:
+ strcpy(str, "I18N_UDATE_SHORT");
+ break;
+ case 4:
+ strcpy(str, "I18N_UDATE_NONE");
+ break;
+ default:
+ strcpy(str, "err");
+ break;
+ }
+ } else if (type == "date") {
+ switch (num) {
+ case 0:
+ strcpy(str, "I18N_UDATE_FULL");
+ break;
+ case 1:
+ strcpy(str, "I18N_UDATE_LONG");
+ break;
+ case 2:
+ strcpy(str, "I18N_UDATE_MEDIUM");
+ break;
+ case 3:
+ strcpy(str, "I18N_UDATE_SHORT");
+ break;
+ case 4:
+ strcpy(str, "I18N_UDATE_RELATIVE");
+ break;
+ case 5:
+ strcpy(str, "I18N_UDATE_LONG_RELATIVE");
+ break;
+ case 6:
+ strcpy(str, "I18N_UDATE_MEDIUM_RELATIVE");
+ break;
+ case 7:
+ strcpy(str, "I18N_UDATE_SHORT_RELATIVE");
+ break;
+ case 8:
+ strcpy(str, "I18N_UDATE_NONE");
+ break;
+ default:
+ strcpy(str, "err");
+ break;
+ }
+ } else if (type == "number_format") {
+ switch (num) {
+ case 1:
+ strcpy(str, "I18N_UNUMBER_DECIMAL");
+ break;
+ case 2:
+ strcpy(str, "I18N_UNUMBER_CURRENCY");
+ break;
+ case 3:
+ strcpy(str, "I18N_UNUMBER_PERCENT");
+ break;
+ case 4:
+ strcpy(str, "I18N_UNUMBER_SCIENTIFIC");
+ break;
+ case 5:
+ strcpy(str, "I18N_UNUMBER_SPELLOUT");
+ break;
+ case 6:
+ strcpy(str, "I18N_UNUMBER_ORDINAL");
+ break;
+ case 7:
+ strcpy(str, "I18N_UNUMBER_DURATION");
+ break;
+ case 8:
+ strcpy(str, "I18N_UNUMBER_NUMBERING_SYSTEM");
+ break;
+ case 9:
+ strcpy(str, "I18N_UNUMBER_PATTERN_RULEBASED");
+ break;
+ case 10:
+ strcpy(str, "I18N_UNUMBER_CURRENCY_ISO");
+ break;
+ case 11:
+ strcpy(str, "I18N_UNUMBER_CURRENCY_PLURAL");
+ break;
+ case 12:
+ strcpy(str, "I18N_UNUMBER_FORMAT_STYLE_COUNT");
+ break;
+ default:
+ strcpy(str, "err");
+ break;
+ }
+ } else if (type == "symbol") {
+ switch (num) {
+ case 1:
+ strcpy(str, "I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL");
+ break;
+ case 2:
+ strcpy(str, "I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL");
+ break;
+ case 3:
+ strcpy(str, "I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL");
+ break;
+ case 4:
+ strcpy(str, "I18N_UNUMBER_PERCENT_SYMBOL");
+ break;
+ case 5:
+ strcpy(str, "I18N_UNUMBER_ZERO_DIGIT_SYMBOL");
+ break;
+ case 6:
+ strcpy(str, "I18N_UNUMBER_DIGIT_SYMBOL");
+ break;
+ case 7:
+ strcpy(str, "I18N_UNUMBER_MINUS_SIGN_SYMBOL");
+ break;
+ case 8:
+ strcpy(str, "I18N_UNUMBER_PLUS_SIGN_SYMBOL");
+ break;
+ case 9:
+ strcpy(str, "I18N_UNUMBER_CURRENCY_SYMBOL");
+ break;
+ case 10:
+ strcpy(str, "I18N_UNUMBER_INTL_CURRENCY_SYMBOL");
+ break;
+ case 11:
+ strcpy(str, "I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL");
+ break;
+ case 12:
+ strcpy(str, "I18N_UNUMBER_EXPONENTIAL_SYMBOL");
+ break;
+ case 13:
+ strcpy(str, "I18N_UNUMBER_PERMILL_SYMBOL");
+ break;
+ case 14:
+ strcpy(str, "I18N_UNUMBER_PAD_ESCAPE_SYMBOL");
+ break;
+ case 15:
+ strcpy(str, "I18N_UNUMBER_INFINITY_SYMBOL");
+ break;
+ case 16:
+ strcpy(str, "I18N_UNUMBER_NAN_SYMBOL");
+ break;
+ case 17:
+ strcpy(str, "I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL");
+ break;
+ case 18:
+ strcpy(str, "I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL");
+ break;
+ case 19:
+ strcpy(str, "I18N_UNUMBER_ONE_DIGIT_SYMBOL");
+ break;
+ case 20:
+ strcpy(str, "I18N_UNUMBER_TWO_DIGIT_SYMBOL");
+ break;
+ case 21:
+ strcpy(str, "I18N_UNUMBER_THREE_DIGIT_SYMBOL");
+ break;
+ case 22:
+ strcpy(str, "I18N_UNUMBER_FOUR_DIGIT_SYMBOL");
+ break;
+ case 23:
+ strcpy(str, "I18N_UNUMBER_FIVE_DIGIT_SYMBOL");
+ break;
+ case 24:
+ strcpy(str, "I18N_UNUMBER_SIX_DIGIT_SYMBOL");
+ break;
+ case 25:
+ strcpy(str, "I18N_UNUMBER_SEVEN_DIGIT_SYMBOL");
+ break;
+ case 26:
+ strcpy(str, "I18N_UNUMBER_EIGHT_DIGIT_SYMBOL");
+ break;
+ case 27:
+ strcpy(str, "I18N_UNUMBER_NINE_DIGIT_SYMBOL");
+ break;
+ default:
+ strcpy(str, "err");
+ break;
+ }
+ } else if (type == "iter_type") {
+ switch (num) {
+ case 0:
+ strcpy(str, "I18N_UBRK_CHARACTER");
+ break;
+ case 1:
+ strcpy(str, "I18N_UBRK_WORD");
+ break;
+ case 2:
+ strcpy(str, "I18N_UBRK_LINE");
+ break;
+ case 3:
+ strcpy(str, "I18N_UBRK_SENTENCE");
+ break;
+ default:
+ strcpy(str, "err");
+ break;
+ }
+ }
+ PRINT_DEBUG_LOG("return string: %s\n", str);
+ return str;
+}
+
+static int __get_date_and_time()
+{
+ printf(" * To get various date and time format\n");
+
+ i18n_udate date_now;
+ i18n_udate_format_h format_h = NULL;
+ int error_code = i18n_ucalendar_get_now(&date_now);
+ PRINT_DEBUG_LOG("i18n_ucalendar_get_now = %lf\n", date_now);
+
+ i18n_udatepg_h udatepg;
+ error_code = i18n_udatepg_create(default_locale, &udatepg);
+ CHECK_ERROR("i18n_udatepg_create", error_code);
+
+ i18n_uchar format[BUF_SIZE];
+ i18n_ustring_copy_ua_n(format, "ddMMMyyyyHHmmssz", BUF_SIZE);
+
+ int pattern_len;
+ i18n_uchar pattern[BUF_SIZE];
+ error_code = i18n_udatepg_get_best_pattern(udatepg, I18N_UDATE_MONTH_DAY, BUF_SIZE, pattern, BUF_SIZE,
+ &pattern_len);
+ CHECK_ERROR("i18n_udatepg_get_best_pattern", error_code);
+
+ printf(" * TIME TYPE X DATE TYPE : OUTPUT\n");
+ for (n_enum_date_counter = 0; n_enum_date_counter < n_date_enum_size; n_enum_date_counter++) {
+ for (n_enum_time_counter = 0; n_enum_time_counter < n_time_enum_size; n_enum_time_counter++) {
+ i18n_ustring_copy_ua_n(default_timezone_id, default_locale, BUF_SIZE);
+ error_code = i18n_udate_create(eTimeFormatStyle[n_enum_time_counter],
+ eDateFormatStyle[n_enum_date_counter],
+ default_locale, default_timezone_id, -1, pattern, -1, &format_h);
+ CHECK_ERROR("i18n_udate_create", error_code);
+
+ i18n_uchar *result = (i18n_uchar *) malloc(BUF_SIZE * sizeof(i18n_uchar));
+ int date_len;
+ error_code = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len);
+ CHECK_ERROR("i18n_udate_format_date", error_code);
+
+ char s[BUF_SIZE];
+ i18n_ustring_copy_au(s, result);
+ printf("TIME[%-17.17s] DATE[%-26.26s] : %s\n", __print_i18n_type_string("time", n_enum_time_counter), __print_i18n_type_string("date", n_enum_date_counter), s);
+ }
+ }
+ return 0;
+}
+
+static int __get_number_format(char *input_number)
+{
+ printf(" * To get various number format\n");
+ double my_number = atof(input_number);
+ PRINT_DEBUG_LOG("Input number = %f\n", my_number);
+
+ i18n_unumber_format_h num_format = NULL;
+ i18n_uchar formatted_number[BUF_SIZE];
+
+ int i;
+ for (i = I18N_UNUMBER_DECIMAL; i <= I18N_UNUMBER_FORMAT_STYLE_COUNT; ++i) {
+ /* Create a number formatter. */
+ int error_code = i18n_unumber_create(i, NULL, -1, default_locale, NULL, &num_format);
+ CHECK_ERROR("i18n_unumber_create", error_code);
+
+ /* Format the given number according to the given locale. */
+ memset(formatted_number, 0, BUF_SIZE);
+ i18n_unumber_format_double(num_format, my_number, formatted_number, BUF_SIZE, NULL);
+
+ /* Display the formatting result. */
+ char string[BUF_SIZE];
+ i18n_ustring_copy_au(string, formatted_number);
+
+ printf("NUMBER_FORMAT[%-30.30s] : %s\n", __print_i18n_type_string("number_format", i), string);
+ }
+
+ /* Release the decimal number formatter. */
+ error_code = i18n_unumber_destroy(num_format);
+ CHECK_ERROR("i18n_unumber_destroy", error_code);
+}
+
+static int __get_symbol()
+{
+ printf(" * To get various number symbol\n");
+
+ /* Create a default number formatter. */
+ i18n_unumber_format_h num_format = NULL;
+ int error_code = i18n_unumber_create(I18N_UNUMBER_DEFAULT, NULL, -1, default_locale, NULL, &num_format);
+ CHECK_ERROR("18n_unumber_create", error_code);
+
+ int i;
+ for (i = 0; i < I18N_UNUMBER_FORMAT_SYMBOL_COUNT; ++i) {
+ /* Format the selected symbol according to the chosen locale. */
+ int buf_len;
+ i18n_uchar u_buffer[BUF_SIZE];
+ error_code = i18n_unumber_get_symbol(num_format, i, u_buffer, BUF_SIZE, &buf_len);
+ CHECK_ERROR("18n_unumber_get_symbol", error_code);
+
+ /* Display the formatted symbol. */
+ char string[BUF_SIZE];
+ i18n_ustring_copy_au(string, u_buffer);
+ printf("SYMBOL[%-47.47s] : %s\n", __print_i18n_type_string("symbol", i+1), string);
+ }
+
+ /* Release the default number formatter object. */
+ error_code = i18n_unumber_destroy(num_format);
+ CHECK_ERROR("i18n_unumber_destroy", error_code);
+}
+
+static const char *layout_orientation_converter(i18n_ulocale_layout_type_e type)
+{
+ switch (type) {
+ case I18N_ULOCALE_LAYOUT_LTR:
+ return "LTR";
+
+ case I18N_ULOCALE_LAYOUT_RTL:
+ return "RTL";
+
+ case I18N_ULOCALE_LAYOUT_TTB:
+ return "TTB";
+
+ case I18N_ULOCALE_LAYOUT_BTT:
+ return "BTT";
+
+ default:
+ return "UNKNOWN";
+ }
+}
+
+
+static int __get_language_info()
+{
+ printf(" * To get language information\n");
+
+ i18n_uchar lang[BUF_SIZE];
+
+ /* Get the default locale code */
+ printf("Default locale code : %s\n", default_locale);
+
+ /* Get the display name of the selected locale. */
+ i18n_uchar name[BUF_SIZE];
+ int name_len;
+
+ int error_code =
+ i18n_ulocale_get_display_name(default_locale, default_locale, name, BUF_SIZE, &name_len);
+ CHECK_ERROR("i18n_ulocale_get_display_name", error_code);
+ char name_ch[BUF_SIZE];
+ i18n_ustring_copy_au(name_ch, name);
+ printf("Language display name : %s\n", name_ch);
+
+
+ /* Get the language related to the selected locale. */
+ i18n_ulocale_get_display_language(default_locale, default_locale, lang, BUF_SIZE);
+
+ /* Get the string representation of the obtained language. */
+ char language[BUF_SIZE];
+ i18n_ustring_copy_au(language, lang);
+ printf("Full name : %s\n", language);
+
+ /* Get the obtained language code. */
+ int32_t lang_len;
+ error_code = i18n_ulocale_get_language(default_locale, language, BUF_SIZE, &lang_len);
+ CHECK_ERROR("i18n_ulocale_get_language", error_code);
+ printf("language code : %s\n", language);
+
+ /* Get the ISO code of the selected locale. */
+ const char *language_iso = i18n_ulocale_get_iso3_language(default_locale);
+ printf("ISO code : %s\n", language_iso);
+
+ /* Get the type of the line orientation related to the selected locale. */
+ i18n_ulocale_layout_type_e type;
+ error_code = i18n_ulocale_get_line_orientation(default_locale, &type);
+ CHECK_ERROR("i18n_ulocale_get_line_orientation", error_code);
+ const char *orientation = layout_orientation_converter(type);
+ printf("Line orientation : %s\n", orientation);
+
+ /* Get the characters orientation related to the selected locale. */
+ error_code = i18n_ulocale_get_character_orientation(default_locale, &type);
+ CHECK_ERROR("i18n_ulocale_get_character_orientation", error_code);
+ orientation = layout_orientation_converter(type);
+ printf("Characters orientation : %s\n", orientation);
+
+ /* Get the variant code related to the selected locale. */
+ char variant[BUF_SIZE];
+ error_code = i18n_ulocale_get_variant(default_locale, variant, BUF_SIZE);
+ CHECK_ERROR("i18n_ulocale_get_variant", error_code);
+ printf("variant code: %s\n", variant);
+}
+
+static int __manage_string_iteration(char *input_string)
+{
+ printf(" * To manage the string iteration\n");
+
+ PRINT_DEBUG_LOG("Input string : %s\n", input_string);
+ i18n_uchar *string_to_examine;
+ i18n_ubreak_iterator_h boundary;
+
+ if (!input_string) {
+ char *input_text = "Twinkle, twinkle, little star.\ How I wonder what you are";
+ printf("Input string : %s\n", input_text);
+ string_to_examine =
+ (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
+ i18n_ustring_copy_ua(string_to_examine, input_text);
+ } else {
+ char input_text[1000] = {0,};
+ strncpy(input_text, input_string, 999);
+ printf("Input string : %s\n", input_text);
+ string_to_examine =
+ (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
+ i18n_ustring_copy_ua(string_to_examine, input_text);
+ }
+
+ int i;
+
+ /* Displays the first element in the given text */
+ for (i = 0; i <= I18N_UBRK_SENTENCE; i++) {
+ error_code = i18n_ubrk_create(i, default_locale, string_to_examine, -1, &boundary);
+ CHECK_ERROR("i18n_ubrk_create", error_code);
+ int32_t start = i18n_ubrk_first(boundary);
+ int32_t end = i18n_ubrk_next(boundary);
+ i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1));
+ result[end - start] = '\0';
+ i18n_ustring_copy_n(result, &string_to_examine[start], end-start);
+ char str[BUF_SIZE];
+ i18n_ustring_copy_au(str, result);
+ printf("ITER First element[%-19.19s] : %s\n", __print_i18n_type_string("iter_type", i), str);
+ }
+
+ /* Displays the last element in the given text */
+ for (i = 0; i <= I18N_UBRK_SENTENCE; i++) {
+ error_code = i18n_ubrk_create(i, default_locale, string_to_examine, -1, &boundary);
+ CHECK_ERROR("i18n_ubrk_create", error_code);
+ int32_t end = i18n_ubrk_last(boundary);
+ int32_t start = i18n_ubrk_previous(boundary);
+ i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1));
+ result[end - start] = '\0';
+ i18n_ustring_copy_n(result, &string_to_examine[start], end-start);
+ char str[BUF_SIZE];
+ i18n_ustring_copy_au(str, result);
+ printf("ITER Last element[%-19.19s] : %s\n", __print_i18n_type_string("iter_type", i), str);
+ }
+
+ free(string_to_examine);
+ error_code = i18n_ubrk_destroy(boundary);
+ CHECK_ERROR("i18n_ubrk_destroy", error_code);
+}
+
+static int __analyze_string(char *custom_string)
+{
+ printf(" * To manage the string\n");
+
+ i18n_uchar *string_to_examine;
+
+ if (!custom_string) {
+ char *input_text = "String";
+ printf("Input string : %s\n", input_text);
+ string_to_examine =
+ (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
+ i18n_ustring_copy_ua(string_to_examine, input_text);
+ } else {
+ char *input_text = custom_string;
+ printf("Input string : %s\n", input_text);
+ string_to_examine =
+ (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
+ i18n_ustring_copy_ua(string_to_examine, input_text);
+ }
+
+ int i;
+
+ /* Get length */
+ int32_t len = i18n_ustring_get_length(string_to_examine);
+ printf("Length : %d\n", len);
+
+ /* To upper */
+ i18n_uchar dest[BUF_SIZE + 1];
+ i18n_ustring_to_upper(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
+ CHECK_ERROR("i18n_ustring_to_upper", error_code);
+
+ char s[BUF_SIZE];
+ i18n_ustring_copy_au(s, dest);
+ printf("TO UPPER : %s\n", s);
+
+ /* To lower */
+ i18n_ustring_to_lower(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
+ CHECK_ERROR("i18n_ustring_to_lower", error_code);
+ i18n_ustring_copy_au(s, dest);
+ printf("to lower : %s\n", s);
+
+ /* To title */
+ i18n_ustring_to_title_new(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
+ CHECK_ERROR("i18n_ustring_to_title_new", error_code);
+ i18n_ustring_copy_au(s, dest);
+ printf("To Title : %s\n", s);
+
+}
+
+static int __get_timezone_info()
+{
+ printf(" * To get time zone information\n");
+
+ static i18n_timezone_h tmz;
+
+ /* Get the default timezone. */
+ error_code = i18n_timezone_create_default(&tmz);
+ CHECK_ERROR("18n_timezone_create_default", error_code);
+
+ /* Get the display name of the default timezone. */
+ char *display_name;
+ error_code = i18n_timezone_get_display_name(tmz, &display_name);
+ CHECK_ERROR("i18n_timezone_get_display_name", error_code);
+ printf("Current timezone : %s\n", display_name);
+
+ /* Get the selected timezone ID. */
+ char *timezone_id;
+ error_code = i18n_timezone_get_id(tmz, &timezone_id);
+ CHECK_ERROR("i18n_timezone_get_id", error_code);
+ printf("Timezone ID : %s\n", timezone_id);
+
+ /* Check whether the selected time zone uses daylight savings time or not. */
+ i18n_ubool daylight_time;
+ error_code = i18n_timezone_use_daylight_time(tmz, &daylight_time);
+ CHECK_ERROR("i18n_timezone_use_daylight_time", error_code);
+ printf("Uses DST : %s\n", daylight_time ? "yes" : "no");
+
+ /*
+ * Get the amount of time that need to be added to the
+ * local standard time to get the local wall clock time.
+ */
+ int32_t dst_savings;
+ char ms[BUF_SIZE];
+ error_code = i18n_timezone_get_dst_savings(tmz, &dst_savings);
+ CHECK_ERROR("i18n_timezone_get_dst_savings", error_code);
+ printf("DST savings in [min] : %d\n", dst_savings / MS_TO_MIN);
+
+ /* Get the selected time zone raw GMT offset. */
+ int32_t offset_milliseconds;
+ error_code = i18n_timezone_get_raw_offset(tmz, &offset_milliseconds);
+ CHECK_ERROR("i18n_timezone_get_raw_offset", error_code);
+ if (offset_milliseconds / MS_TO_HOUR > 0)
+ printf("Raw GMT offset : GMT +%d\n", offset_milliseconds / MS_TO_HOUR);
+ else
+ printf("Raw GMT offset : GMT %d\n", offset_milliseconds / MS_TO_HOUR);
+
+ /* Get the region code associated with the selected time zone. */
+ char region[BUF_SIZE];
+ int32_t region_len = -1;
+ error_code = i18n_timezone_get_region(timezone_id, region, ®ion_len, BUF_SIZE);
+ CHECK_ERROR("i18n_timezone_get_region", error_code);
+ printf("Associated region code : %s\n", region);
+
+ /* Release the time zone object. */
+ error_code = i18n_timezone_destroy(tmz);
+ CHECK_ERROR("i18n_timezone_destroy", error_code);
+}
+
+static int __get_tzdata_version()
+{
+ const char *ver = i18n_timezone_get_tzdata_version();
+ printf("tzdata version : %s\n", ver);
+}
+
+void allTest()
+{
+ int ret, i = 0;
+ int loc_count;
+
+ loc_count = i18n_ulocale_count_available();
+ for (i = 0; i < loc_count; i++) {
+ default_locale = i18n_ulocale_get_available(i);
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_date_and_time();
+ printf("\n");
+ ret = __get_number_format("3.5");
+ printf("\n");
+ ret = __get_symbol();
+ printf("\n");
+ ret = __get_language_info();
+ printf("\n");
+ }
+ ret = __manage_string_iteration(NULL);
+ printf("\n");
+ ret = __analyze_string(NULL);
+ printf("\n");
+ ret = __get_timezone_info();
+ ret = __get_tzdata_version();
+ if (ret == -1) {
+ printf("get i18n time zone info list failed\n");
+ }
+}
+
+void showAllLocale()
+{
+ __get_available_locales();
+}
+
+void showLangInfo(char *locale)
+{
+ int ret, i = 0;
+ int loc_count;
+
+ if (!locale) {
+ loc_count = i18n_ulocale_count_available();
+ for (i = 0; i < loc_count; i++) {
+ default_locale = i18n_ulocale_get_available(i);
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_language_info();
+ }
+ if (ret == -1) {
+ printf("get i18n language info list failed\n");
+ }
+ } else {
+ default_locale = locale;
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_language_info();
+ if (ret == -1) {
+ printf("get i18n language info list failed\n");
+ }
+ }
+}
+
+void showTimezone()
+{
+ int ret = 0;
+ ret = __get_timezone_info();
+ if (ret == -1) {
+ printf("get i18n time zone info list failed\n");
+ }
+}
+
+void showTzdataVersion()
+{
+ __get_tzdata_version();
+}
+
+void testDatentime(char *locale)
+{
+ int ret, i = 0;
+ int loc_count;
+
+ if (!locale) {
+ loc_count = i18n_ulocale_count_available();
+ for (i = 0; i < loc_count; i++) {
+ default_locale = i18n_ulocale_get_available(i);
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_date_and_time();
+ }
+ if (ret == -1) {
+ printf("get i18n date and time list failed\n");
+ }
+ } else {
+ default_locale = locale;
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_date_and_time();
+ if (ret == -1) {
+ printf("get i18n date and time list failed\n");
+ }
+
+ }
+}
+
+void testNumberFormat(char *input, char *locale)
+{
+ int ret, i = 0;
+ int loc_count;
+
+ if (!input) {
+
+ } else {
+ if (!locale) {
+ loc_count = i18n_ulocale_count_available();
+ for (i = 0; i < loc_count; i++) {
+ default_locale = i18n_ulocale_get_available(i);
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_number_format(input);
+ }
+ if (ret == -1) {
+ printf("get number format list failed\n");
+ }
+ } else {
+ default_locale = locale;
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_number_format(input);
+ if (ret == -1) {
+ printf("get number format list failed\n");
+ }
+ }
+ }
+}
+
+void testNumberSymbol(char *locale)
+{
+ int ret, i = 0;
+ int loc_count;
+
+ if (!locale) {
+ loc_count = i18n_ulocale_count_available();
+ for (i = 0; i < loc_count; i++) {
+ default_locale = i18n_ulocale_get_available(i);
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_symbol();
+ }
+ if (ret == -1) {
+ printf("get i18n symbol list failed\n");
+ }
+ } else {
+ default_locale = locale;
+ printf("\n * locales : %s\n", default_locale);
+ ret = __get_symbol();
+ if (ret == -1) {
+ printf("get i18n symbol list failed\n");
+ }
+ }
+}
+
+void testString(char *input)
+{
+ int ret = 0;
+
+ ret = __analyze_string(input);
+ if (ret == -1) {
+ printf("get i18n string list failed\n");
+ }
+}
+
+void testStringIter(char *input)
+{
+ int ret = 0;
+
+ ret = __manage_string_iteration(input);
+ if (ret == -1) {
+ printf("get i18n string iteration list failed\n");
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0, i = 0;
+
+ struct arguments arguments = {0,};
+
+ argp_parse(&argp, argc, argv, 0, 0, &arguments);
+
+ if (arguments.all) {
+ memset(&arguments, 0x00, sizeof(arguments));
+
+ allTest();
+ }
+
+ if (arguments.showAllLocale) {
+ showAllLocale();
+ }
+
+ if (arguments.showLangInfo) {
+ showLangInfo(arguments.setLocale);
+ }
+
+ if (arguments.testDatentime) {
+ testDatentime(arguments.setLocale);
+ }
+
+ if (arguments.testNumberFormat) {
+ testNumberFormat(arguments.testNumberFormatArg, arguments.setLocale);
+ }
+
+ if (arguments.testNumberSymbol) {
+ testNumberSymbol(arguments.setLocale);
+ }
+
+ if (arguments.testString) {
+ testString(arguments.testStringArg);
+ }
+
+ if (arguments.testStringIter) {
+ testStringIter(arguments.testStringIterArg);
+ }
+
+ if (arguments.showTimezone) {
+ showTimezone();
+ }
+
+ if (arguments.showTzdataVersion) {
+ showTzdataVersion();
+ }
+
+ return 0;
+}