]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | ******************************************************************************** | |
3 | * Copyright (C) 2005-2016, International Business Machines | |
4 | * Corporation and others. All Rights Reserved. | |
5 | ******************************************************************************** | |
6 | * | |
7 | * File WINUTIL.CPP | |
8 | * | |
9 | ******************************************************************************** | |
10 | */ | |
11 | ||
12 | #include "unicode/utypes.h" | |
13 | ||
14 | #if U_PLATFORM_HAS_WIN32_API | |
15 | ||
16 | #if !UCONFIG_NO_FORMATTING | |
17 | ||
18 | #include "cmemory.h" | |
19 | #include "winutil.h" | |
20 | #include "locmap.h" | |
21 | #include "unicode/uloc.h" | |
22 | ||
23 | # define WIN32_LEAN_AND_MEAN | |
24 | # define VC_EXTRALEAN | |
25 | # define NOUSER | |
26 | # define NOSERVICE | |
27 | # define NOIME | |
28 | # define NOMCX | |
29 | # include <windows.h> | |
30 | # include <stdio.h> | |
31 | # include <string.h> | |
32 | ||
33 | static Win32Utilities::LCIDRecord *lcidRecords = NULL; | |
34 | static int32_t lcidCount = 0; | |
35 | static int32_t lcidMax = 0; | |
36 | ||
37 | BOOL CALLBACK EnumLocalesProc(LPSTR lpLocaleString) | |
38 | { | |
39 | char localeID[ULOC_FULLNAME_CAPACITY]; | |
40 | int32_t localeIDLen; | |
41 | UErrorCode status = U_ZERO_ERROR; | |
42 | ||
43 | if (lcidCount >= lcidMax) { | |
44 | Win32Utilities::LCIDRecord *newRecords = new Win32Utilities::LCIDRecord[lcidMax + 32]; | |
45 | ||
46 | for (int i = 0; i < lcidMax; i += 1) { | |
47 | newRecords[i] = lcidRecords[i]; | |
48 | } | |
49 | ||
50 | delete[] lcidRecords; | |
51 | lcidRecords = newRecords; | |
52 | lcidMax += 32; | |
53 | } | |
54 | ||
55 | sscanf(lpLocaleString, "%8x", &lcidRecords[lcidCount].lcid); | |
56 | ||
57 | localeIDLen = uprv_convertToPosix(lcidRecords[lcidCount].lcid, localeID, UPRV_LENGTHOF(localeID), &status); | |
58 | if (U_SUCCESS(status)) { | |
59 | lcidRecords[lcidCount].localeID = new char[localeIDLen + 1]; | |
60 | memcpy(lcidRecords[lcidCount].localeID, localeID, localeIDLen); | |
61 | lcidRecords[lcidCount].localeID[localeIDLen] = 0; | |
62 | } else { | |
63 | lcidRecords[lcidCount].localeID = NULL; | |
64 | } | |
65 | ||
66 | lcidCount += 1; | |
67 | ||
68 | return TRUE; | |
69 | } | |
70 | ||
71 | Win32Utilities::LCIDRecord *Win32Utilities::getLocales(int32_t &localeCount) | |
72 | { | |
73 | LCIDRecord *result; | |
74 | ||
75 | EnumSystemLocalesA(EnumLocalesProc, LCID_INSTALLED); | |
76 | ||
77 | localeCount = lcidCount; | |
78 | result = lcidRecords; | |
79 | ||
80 | lcidCount = lcidMax = 0; | |
81 | lcidRecords = NULL; | |
82 | ||
83 | return result; | |
84 | } | |
85 | ||
86 | void Win32Utilities::freeLocales(LCIDRecord *records) | |
87 | { | |
88 | for (int i = 0; i < lcidCount; i++) { | |
89 | delete lcidRecords[i].localeID; | |
90 | } | |
91 | delete[] records; | |
92 | } | |
93 | ||
94 | #endif /* #if !UCONFIG_NO_FORMATTING */ | |
95 | ||
96 | #endif /* U_PLATFORM_HAS_WIN32_API */ |