1 /* 2 ** Copyright 2009 Adrien Destugues, pulkomandy@gmail.com. 3 ** Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <assert.h> 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <typeinfo> 11 #include <unistd.h> 12 13 #include <Application.h> 14 #include <StopWatch.h> 15 16 #include <unicode/locid.h> 17 #include <unicode/strenum.h> 18 19 20 void TestLocale(const Locale& loc) 21 { 22 printf("-- init\n"); 23 assert(!loc.isBogus()); 24 printf("-- basic info\n"); 25 printf("Default locale:\nLanguage: %s\nScript: %s\nVariant: %s\n" 26 "Country: %s\nName: %s\nBaseName: %s\n", loc.getLanguage(), 27 loc.getScript(), loc.getVariant(), 28 loc.getCountry(), loc.getName(), 29 loc.getBaseName()); 30 31 UErrorCode err = U_ZERO_ERROR; 32 printf("-- keywords\n"); 33 StringEnumeration* keywords = loc.createKeywords(err); 34 if (err != U_ZERO_ERROR) 35 printf("FAILED: getting keywords list\n"); 36 if (keywords == NULL) 37 printf("FAILED: getting keywords list returned NULL\n"); 38 else { 39 printf("Keywords: %d available\n",keywords->count(err)); 40 assert(err == U_ZERO_ERROR); 41 42 char keyvalue[256]; 43 while (const char* keyname = keywords->next(NULL,err)) { 44 loc.getKeywordValue(keyname,keyvalue,256,err); 45 printf("%s > %s\n",keyname,keyvalue); 46 } 47 48 delete keywords; 49 } 50 } 51 52 53 int 54 main(int argc, char **argv) 55 { 56 printf("--------\niDefault Locale\n--------\n"); 57 Locale defaultLocale; 58 TestLocale(defaultLocale); 59 printf("--------\nFrench Locale\n--------\n"); 60 Locale french = Locale::getFrench(); 61 TestLocale(french); 62 printf("--------\nCustom Locale\n--------\n"); 63 Locale custom("es"); 64 TestLocale(custom); 65 66 printf("--------\nLocale listing\n--------\n"); 67 int32_t count; 68 const Locale* localeList = Locale::getAvailableLocales(count); 69 printf("%d locales found\n",count); 70 71 for (int i=0; i<count; i++) { 72 printf("Locale number %d\n",i); 73 TestLocale(localeList[i]); 74 } 75 76 printf("--------\nLocale country codes\n--------\n"); 77 const char* const* countryTable = Locale::getISOCountries(); 78 79 for (int i=0; countryTable[i] != NULL; i++) 80 printf("%s\t",countryTable[i]); 81 82 printf("\n--------\nNumberFormat\n--------\n"); 83 printf("--------\nDateFormat\n--------\n"); 84 printf("--------\nCollator\n--------\n"); 85 86 return 0; 87 } 88