forked from unicode-org/icu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongname.cpp
50 lines (42 loc) · 1.39 KB
/
longname.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#include "unicode/unistr.h"
#include "unicode/locid.h"
#include "unicode/ucnv.h"
#include <stdio.h>
int main(int argc,
char* argv[])
{
UErrorCode status = U_ZERO_ERROR;
const char *loc = argv[1];
int32_t hasCountry;
UConverter *conv = ucnv_open("utf8", &status);
char16_t UBuffer[256];
int32_t uBufLen = 0;
char buffer[256];
int32_t bufLen = 0;
uBufLen = uloc_getDisplayLanguage(loc, "en", UBuffer, 256, &status);
bufLen = ucnv_fromUChars(conv, buffer, 256, UBuffer, uBufLen, &status);
//u_UCharsToChars(UBuffer, buffer, uBufLen);
buffer[bufLen] = 0;
printf("%s", buffer);
if(hasCountry = uloc_getCountry(loc, buffer, 256, &status)) {
uBufLen = uloc_getDisplayCountry(loc, "en", UBuffer, 256, &status);
bufLen = ucnv_fromUChars(conv, buffer, 256, UBuffer, uBufLen, &status);
//u_UCharsToChars(UBuffer, buffer, uBufLen);
buffer[bufLen] = 0;
printf("_%s", buffer);
}
if(uloc_getVariant(loc, buffer, 256, &status)) {
uBufLen = uloc_getDisplayVariant(loc, "en", UBuffer, 256, &status);
bufLen = ucnv_fromUChars(conv, buffer, 256, UBuffer, uBufLen, &status);
//u_UCharsToChars(UBuffer, buffer, uBufLen);
buffer[bufLen] = 0;
if(!hasCountry) {
printf("_");
}
printf("_%s", buffer);
}
printf("\n");
return 0;
}