]>
Commit | Line | Data |
---|---|---|
73c04bcf A |
1 | /* |
2 | ******************************************************************************** | |
3 | * Copyright (C) 2005-2006, 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 | #ifdef U_WINDOWS | |
15 | ||
16 | #if !UCONFIG_NO_FORMATTING | |
17 | ||
18 | #include "winutil.h" | |
19 | #include "locmap.h" | |
20 | ||
21 | # define WIN32_LEAN_AND_MEAN | |
22 | # define VC_EXTRALEAN | |
23 | # define NOUSER | |
24 | # define NOSERVICE | |
25 | # define NOIME | |
26 | # define NOMCX | |
27 | # include <windows.h> | |
28 | # include <stdio.h> | |
29 | ||
30 | static Win32Utilities::LCIDRecord *lcidRecords = NULL; | |
31 | static int32_t lcidCount = 0; | |
32 | static int32_t lcidMax = 0; | |
33 | ||
34 | BOOL CALLBACK EnumLocalesProc(LPSTR lpLocaleString) | |
35 | { | |
36 | UErrorCode status = U_ZERO_ERROR; | |
37 | ||
38 | if (lcidCount >= lcidMax) { | |
39 | Win32Utilities::LCIDRecord *newRecords = new Win32Utilities::LCIDRecord[lcidMax + 32]; | |
40 | ||
41 | for (int i = 0; i < lcidMax; i += 1) { | |
42 | newRecords[i] = lcidRecords[i]; | |
43 | } | |
44 | ||
45 | delete[] lcidRecords; | |
46 | lcidRecords = newRecords; | |
47 | lcidMax += 32; | |
48 | } | |
49 | ||
50 | sscanf(lpLocaleString, "%8x", &lcidRecords[lcidCount].lcid); | |
51 | ||
52 | lcidRecords[lcidCount].localeID = uprv_convertToPosix(lcidRecords[lcidCount].lcid, &status); | |
53 | ||
54 | lcidCount += 1; | |
55 | ||
56 | return TRUE; | |
57 | } | |
58 | ||
59 | Win32Utilities::LCIDRecord *Win32Utilities::getLocales(int32_t &localeCount) | |
60 | { | |
61 | LCIDRecord *result; | |
62 | ||
63 | EnumSystemLocalesA(EnumLocalesProc, LCID_INSTALLED); | |
64 | ||
65 | localeCount = lcidCount; | |
66 | result = lcidRecords; | |
67 | ||
68 | lcidCount = lcidMax = 0; | |
69 | lcidRecords = NULL; | |
70 | ||
71 | return result; | |
72 | } | |
73 | ||
74 | void Win32Utilities::freeLocales(LCIDRecord *records) | |
75 | { | |
76 | delete[] records; | |
77 | } | |
78 | ||
79 | #endif /* #if !UCONFIG_NO_FORMATTING */ | |
80 | ||
81 | #endif /* #ifdef U_WINDOWS */ |