]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/winutil.cpp
ICU-511.25.tar.gz
[apple/icu.git] / icuSources / test / intltest / winutil.cpp
1 /*
2 ********************************************************************************
3 * Copyright (C) 2005-2011, 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 "winutil.h"
19 #include "locmap.h"
20 #include "unicode/uloc.h"
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>
30 # include <string.h>
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 {
38 const char* localeID = NULL;
39 UErrorCode status = U_ZERO_ERROR;
40
41 if (lcidCount >= lcidMax) {
42 Win32Utilities::LCIDRecord *newRecords = new Win32Utilities::LCIDRecord[lcidMax + 32];
43
44 for (int i = 0; i < lcidMax; i += 1) {
45 newRecords[i] = lcidRecords[i];
46 }
47
48 delete[] lcidRecords;
49 lcidRecords = newRecords;
50 lcidMax += 32;
51 }
52
53 sscanf(lpLocaleString, "%8x", &lcidRecords[lcidCount].lcid);
54
55 localeID = uprv_convertToPosix(lcidRecords[lcidCount].lcid, &status);
56
57 lcidRecords[lcidCount].localeID = new char[strlen(localeID)];
58
59 strcpy(lcidRecords[lcidCount].localeID, localeID);
60
61 lcidCount += 1;
62
63 return TRUE;
64 }
65
66 Win32Utilities::LCIDRecord *Win32Utilities::getLocales(int32_t &localeCount)
67 {
68 LCIDRecord *result;
69
70 EnumSystemLocalesA(EnumLocalesProc, LCID_INSTALLED);
71
72 localeCount = lcidCount;
73 result = lcidRecords;
74
75 lcidCount = lcidMax = 0;
76 lcidRecords = NULL;
77
78 return result;
79 }
80
81 void Win32Utilities::freeLocales(LCIDRecord *records)
82 {
83 for (int i = 0; i < lcidCount; i++) {
84 delete lcidRecords[i].localeID;
85 }
86 delete[] records;
87 }
88
89 #endif /* #if !UCONFIG_NO_FORMATTING */
90
91 #endif /* U_PLATFORM_HAS_WIN32_API */