• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 #include "unicode/unistr.h"
4 #include "unicode/locid.h"
5 #include "unicode/ucnv.h"
6 #include <stdio.h>
7 
main(int argc,char * argv[])8 int main(int argc,
9      char* argv[])
10 {
11   UErrorCode status = U_ZERO_ERROR;
12   const char *loc = argv[1];
13   int32_t hasCountry;
14   UConverter *conv = ucnv_open("utf8", &status);
15 
16 
17   UChar UBuffer[256];
18   int32_t uBufLen = 0;
19   char buffer[256];
20   int32_t bufLen = 0;
21 
22   uBufLen = uloc_getDisplayLanguage(loc, "en", UBuffer, 256, &status);
23   bufLen = ucnv_fromUChars(conv, buffer, 256, UBuffer, uBufLen, &status);
24   //u_UCharsToChars(UBuffer,  buffer, uBufLen);
25   buffer[bufLen] = 0;
26   printf("%s", buffer);
27 
28   if(hasCountry = uloc_getCountry(loc, buffer, 256, &status)) {
29     uBufLen = uloc_getDisplayCountry(loc, "en", UBuffer, 256, &status);
30     bufLen = ucnv_fromUChars(conv, buffer, 256, UBuffer, uBufLen, &status);
31     //u_UCharsToChars(UBuffer,  buffer, uBufLen);
32     buffer[bufLen] = 0;
33     printf("_%s", buffer);
34   }
35 
36   if(uloc_getVariant(loc, buffer, 256, &status)) {
37     uBufLen = uloc_getDisplayVariant(loc, "en", UBuffer, 256, &status);
38     bufLen = ucnv_fromUChars(conv, buffer, 256, UBuffer, uBufLen, &status);
39     //u_UCharsToChars(UBuffer,  buffer, uBufLen);
40     buffer[bufLen] = 0;
41     if(!hasCountry) {
42       printf("_");
43     }
44     printf("_%s", buffer);
45   }
46   printf("\n");
47 
48 
49   return 0;
50 }
51