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