const char* _Locale_collate_default(char* buf) { char fullname[_Locale_MAX_COMPOSITE_NAME]; if (get_default_locale(fullname) == NULL) return NULL; else return _Locale_extract_collate_name(fullname, buf); }
LoggerWrapper::LoggerWrapper() : mWarningDegree(0) { initialize(); mStringTable = new StringTable(); mLogger = new Logger(); mLogger->setWrapper(this); mLogger->setLocale(get_default_locale()); mLogger->setStringTable(mStringTable); }
Dictionary dictionary_create_default_lang(void) { Dictionary dictionary; char * lang; lang = get_default_locale(); if (lang && *lang) { dictionary = dictionary_create_lang(lang); free(lang); } else { /* Default to en when locales are broken (e.g. WIN32) */ dictionary = dictionary_create_lang("en"); } return dictionary; }
/** * Use "string" as the input dictionary. All of the other parts, * including post-processing, affix table, etc, are NULL. * This routine is intended for unit-testing ONLY. */ Dictionary dictionary_create_from_utf8(const char * input) { Dictionary dictionary = NULL; char * lang; init_memusage(); lang = get_default_locale(); if (lang && *lang) { dictionary = dictionary_six_str(lang, input, "string", NULL, NULL, NULL, NULL); free(lang); } else { /* Default to en when locales are broken (e.g. WIN32) */ dictionary = dictionary_six_str("en", input, "string", NULL, NULL, NULL, NULL); } return dictionary; }
/* MAIN */ int main( int argc, char **argv ) { size_t results[] = {4255, 142803, 46838, 0}, i = 0, output = 0; const size_t b = 5; const char *count_bytes_files[] = { "/data/orig_breaks.txt", "/data/spawner_output.txt", "/data/zh_romance_of_three_kingdoms.txt", ""}, *source_dir = getenv("SOURCE"); char buffer[BUFSIZ], tinybuffer[b], *locale = "root", *encoding = "UTF-8"; OChar obuffer[BUFSIZ], otinybuffer[b]; struct stat sts; time_t now; FILE *f; init_oly(argv[0], TEST_PKGDATADIR, encoding, locale); if (source_dir == NULL) { fprintf(stderr, "requires SOURCE environment variable, supplied by runtest. Exiting...\n"); exit(EXIT_FAILURE); } plan(16); diag("----- Testing oly_timestamp function. -----"); time(&now); is_double(((double)( now*1000)), oly_timestamp(), 1000.0, "Two times should be close enough."); diag("----- Testing count_file_bytes function. -----"); for (i = 0; (results[i] != 0); i++) { strcpy(buffer, source_dir); strcat(buffer, count_bytes_files[i]); if (stat(buffer, &sts) == -1 && errno == ENOENT) { printf ("The file %s doesn't exist...\n", buffer); } f = fopen(buffer, "r"); assert( count_file_bytes( f, &output ) == OLY_OKAY ) ; is_int(results[i], output, "File: %s", count_bytes_files[i]); fclose(f); } diag("----- Testing get_default_locale and get_default_encoding function. -----"); is_unicode_string( u"root", get_default_locale(), "For this test, default locale should be root."); is_unicode_string( u"UTF-8", get_default_encoding(), "For this test, default encoding should be UTF-8."); diag("----- Testing char_default_locale and char_default_encoding function. -----"); is_string( "root", char_default_locale(), "For this test, default locale should be root."); is_string( "UTF-8", char_default_encoding(), "For this test, default encoding should be UTF-8."); diag("----- ostr_to_cstr and cstr_to_ostr -----"); is_unicode_string( u"Lorum ipsum etc...", cstr_to_ostr( obuffer, BUFSIZ, "Lorum ipsum etc..."), "Char to ochar with space, BUFSIZ = %i", BUFSIZ); is_unicode_string( u"Loru", cstr_to_ostr( otinybuffer, b, "Lorum ipsum etc..." ), "Char to ochar with tiny buffer of %i characters.", (int)b ); is_unicode_string( u"", cstr_to_ostr( otinybuffer, b, "" ), "Char to ochar With empty string" ); is_unicode_string( u"", cstr_to_ostr( otinybuffer, b, NULL ), "Char to ochar from null" ); is_string( "Back the other way!", ostr_to_cstr( buffer, BUFSIZ, u"Back the other way!" ), "OChar to char, BUFSIZ = %i", BUFSIZ ); is_string( "five", ostr_to_cstr( tinybuffer, b, u"five characters is all that fits." ), "OChar to char, buffer of %i OChars", (int)b ); is_string( "", ostr_to_cstr( tinybuffer, b, NULL ), "Char to ochar a NULL from string." ); is_string( "", ostr_to_cstr( tinybuffer, b, u"" ), "Char to ochar with an empty string." ); exit(EXIT_SUCCESS); }