X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..4f1e1a09ce4daed860e35d359ce2fceccb0764e8:/icuSources/test/intltest/winutil.cpp diff --git a/icuSources/test/intltest/winutil.cpp b/icuSources/test/intltest/winutil.cpp index 1963221e..87b2d402 100644 --- a/icuSources/test/intltest/winutil.cpp +++ b/icuSources/test/intltest/winutil.cpp @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************** -* Copyright (C) 2005-2006, International Business Machines +* Copyright (C) 2005-2016, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************** * @@ -11,12 +13,14 @@ #include "unicode/utypes.h" -#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API #if !UCONFIG_NO_FORMATTING +#include "cmemory.h" #include "winutil.h" #include "locmap.h" +#include "unicode/uloc.h" # define WIN32_LEAN_AND_MEAN # define VC_EXTRALEAN @@ -26,13 +30,17 @@ # define NOMCX # include # include +# include static Win32Utilities::LCIDRecord *lcidRecords = NULL; static int32_t lcidCount = 0; static int32_t lcidMax = 0; +// TODO: Note that this test will skip locale names and only hit locales with assigned LCIDs BOOL CALLBACK EnumLocalesProc(LPSTR lpLocaleString) { + char localeID[ULOC_FULLNAME_CAPACITY]; + int32_t localeIDLen; UErrorCode status = U_ZERO_ERROR; if (lcidCount >= lcidMax) { @@ -49,13 +57,21 @@ BOOL CALLBACK EnumLocalesProc(LPSTR lpLocaleString) sscanf(lpLocaleString, "%8x", &lcidRecords[lcidCount].lcid); - lcidRecords[lcidCount].localeID = uprv_convertToPosix(lcidRecords[lcidCount].lcid, &status); + localeIDLen = uprv_convertToPosix(lcidRecords[lcidCount].lcid, localeID, UPRV_LENGTHOF(localeID), &status); + if (U_SUCCESS(status)) { + lcidRecords[lcidCount].localeID = new char[localeIDLen + 1]; + memcpy(lcidRecords[lcidCount].localeID, localeID, localeIDLen); + lcidRecords[lcidCount].localeID[localeIDLen] = 0; + } else { + lcidRecords[lcidCount].localeID = NULL; + } lcidCount += 1; return TRUE; } +// TODO: Note that this test will skip locale names and only hit locales with assigned LCIDs Win32Utilities::LCIDRecord *Win32Utilities::getLocales(int32_t &localeCount) { LCIDRecord *result; @@ -73,9 +89,12 @@ Win32Utilities::LCIDRecord *Win32Utilities::getLocales(int32_t &localeCount) void Win32Utilities::freeLocales(LCIDRecord *records) { + for (int i = 0; i < lcidCount; i++) { + delete lcidRecords[i].localeID; + } delete[] records; } #endif /* #if !UCONFIG_NO_FORMATTING */ -#endif /* #ifdef U_WINDOWS */ +#endif /* U_PLATFORM_HAS_WIN32_API */