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