]>
Commit | Line | Data |
---|---|---|
73c04bcf A |
1 | /* |
2 | ******************************************************************************** | |
2ca993e8 | 3 | * Copyright (C) 2005-2016, International Business Machines |
73c04bcf A |
4 | * Corporation and others. All Rights Reserved. |
5 | ******************************************************************************** | |
6 | * | |
7 | * File WINUTIL.CPP | |
8 | * | |
9 | ******************************************************************************** | |
10 | */ | |
11 | ||
12 | #include "unicode/utypes.h" | |
13 | ||
4388f060 | 14 | #if U_PLATFORM_HAS_WIN32_API |
73c04bcf A |
15 | |
16 | #if !UCONFIG_NO_FORMATTING | |
17 | ||
2ca993e8 | 18 | #include "cmemory.h" |
73c04bcf A |
19 | #include "winutil.h" |
20 | #include "locmap.h" | |
729e4ab9 | 21 | #include "unicode/uloc.h" |
73c04bcf A |
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> | |
729e4ab9 | 31 | # include <string.h> |
73c04bcf A |
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 | { | |
57a6839d A |
39 | char localeID[ULOC_FULLNAME_CAPACITY]; |
40 | int32_t localeIDLen; | |
73c04bcf A |
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 | ||
2ca993e8 | 57 | localeIDLen = uprv_convertToPosix(lcidRecords[lcidCount].lcid, localeID, UPRV_LENGTHOF(localeID), &status); |
57a6839d A |
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 | } | |
73c04bcf A |
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 | { | |
729e4ab9 A |
88 | for (int i = 0; i < lcidCount; i++) { |
89 | delete lcidRecords[i].localeID; | |
90 | } | |
73c04bcf A |
91 | delete[] records; |
92 | } | |
93 | ||
94 | #endif /* #if !UCONFIG_NO_FORMATTING */ | |
95 | ||
4388f060 | 96 | #endif /* U_PLATFORM_HAS_WIN32_API */ |