ICU: replace windows related source files with those from mypal68 (ICU 64.2)

This commit is contained in:
roytam1 2022-07-26 23:55:00 +08:00
commit 3a65ef9ca8
10 changed files with 503 additions and 689 deletions

View file

@ -103,17 +103,6 @@
# include <windows.h>
# include "unicode/uloc.h"
# include "wintz.h"
#if U_PLATFORM_HAS_WINUWP_API
typedef PVOID LPMSG; // TODO: figure out how to get rid of this typedef
#include <Windows.Globalization.h>
#include <windows.system.userprofile.h>
#include <wrl/wrappers/corewrappers.h>
#include <wrl/client.h>
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
#endif
#elif U_PLATFORM == U_PF_OS400
# include <float.h>
# include <qusec.h> /* error code structure */
@ -252,7 +241,6 @@ u_signBit(double d) {
UDate fakeClock_t0 = 0; /** Time to start the clock from **/
UDate fakeClock_dt = 0; /** Offset (fake time - real time) **/
UBool fakeClock_set = FALSE; /** True if fake clock has spun up **/
static UMutex fakeClockMutex = U_MUTEX_INTIALIZER;
static UDate getUTCtime_real() {
struct timeval posixTime;
@ -261,6 +249,7 @@ static UDate getUTCtime_real() {
}
static UDate getUTCtime_fake() {
static UMutex fakeClockMutex = U_MUTEX_INTIALIZER;
umtx_lock(&fakeClockMutex);
if(!fakeClock_set) {
UDate real = getUTCtime_real();
@ -997,7 +986,8 @@ static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
/* Check each entry in the directory. */
while((dirEntry = readdir(dirp)) != NULL) {
const char* dirName = dirEntry->d_name;
if (uprv_strcmp(dirName, SKIP1) != 0 && uprv_strcmp(dirName, SKIP2) != 0) {
if (uprv_strcmp(dirName, SKIP1) != 0 && uprv_strcmp(dirName, SKIP2) != 0
&& uprv_strcmp(TZFILE_SKIP, dirName) != 0 && uprv_strcmp(TZFILE_SKIP2, dirName) != 0) {
/* Create a newpath with the new entry to test each entry in the directory. */
CharString newpath(curpath, status);
newpath.append(dirName, -1, status);
@ -1024,7 +1014,7 @@ static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
*/
if (result != NULL)
break;
} else if (uprv_strcmp(TZFILE_SKIP, dirName) != 0 && uprv_strcmp(TZFILE_SKIP2, dirName) != 0) {
} else {
if(compareBinaryFiles(TZDEFAULT, newpath.data(), tzInfo)) {
int32_t amountToSkip = sizeof(TZZONEINFO) - 1;
if (amountToSkip > newpath.length()) {
@ -1078,7 +1068,7 @@ uprv_tzname(int n)
// the other code path returns a pointer to a heap location.
// If we don't have a name already, then tzname wouldn't be any
// better, so just fall back.
return uprv_strdup("Etc/UTC");
return uprv_strdup("");
#endif // !U_TZNAME
#else
@ -1317,9 +1307,9 @@ uprv_pathIsAbsolute(const char *path)
return FALSE;
}
/* Temporary backup setting of ICU_DATA_DIR_PREFIX_ENV_VAR
until some client wrapper makefiles are updated */
#if U_PLATFORM_IS_DARWIN_BASED && TARGET_IPHONE_SIMULATOR
/* Backup setting of ICU_DATA_DIR_PREFIX_ENV_VAR
(needed for some Darwin ICU build environments) */
#if U_PLATFORM_IS_DARWIN_BASED && TARGET_OS_SIMULATOR
# if !defined(ICU_DATA_DIR_PREFIX_ENV_VAR)
# define ICU_DATA_DIR_PREFIX_ENV_VAR "IPHONE_SIMULATOR_ROOT"
# endif
@ -1430,12 +1420,7 @@ static void U_CALLCONV dataDirectoryInitFn() {
if(path==NULL) {
/* It looks really bad, set it to something. */
#if U_PLATFORM_HAS_WIN32_API
// Windows UWP will require icudtl.dat file in same directory as icuuc.dll
path = ".\\";
#else
path = "";
#endif
}
u_setDataDirectory(path);
@ -1633,11 +1618,7 @@ The variant cannot have dots in it.
The 'rightmost' variant (@xxx) wins.
The leftmost codepage (.xxx) wins.
*/
char *correctedPOSIXLocale = 0;
const char* posixID = uprv_getPOSIXIDForDefaultLocale();
const char *p;
const char *q;
int32_t len;
/* Format: (no spaces)
ll [ _CC ] [ . MM ] [ @ VV]
@ -1645,38 +1626,29 @@ The leftmost codepage (.xxx) wins.
l = lang, C = ctry, M = charmap, V = variant
*/
if (gCorrectedPOSIXLocale != NULL) {
if (gCorrectedPOSIXLocale != nullptr) {
return gCorrectedPOSIXLocale;
}
if ((p = uprv_strchr(posixID, '.')) != NULL) {
/* assume new locale can't be larger than old one? */
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID)+1));
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
}
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
correctedPOSIXLocale[p-posixID] = 0;
// Copy the ID into owned memory.
// Over-allocate in case we replace "@" with "__".
char *correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID) + 1 + 1));
if (correctedPOSIXLocale == nullptr) {
return nullptr;
}
uprv_strcpy(correctedPOSIXLocale, posixID);
/* do not copy after the @ */
if ((p = uprv_strchr(correctedPOSIXLocale, '@')) != NULL) {
correctedPOSIXLocale[p-correctedPOSIXLocale] = 0;
char *limit;
if ((limit = uprv_strchr(correctedPOSIXLocale, '.')) != nullptr) {
*limit = 0;
if ((limit = uprv_strchr(correctedPOSIXLocale, '@')) != nullptr) {
*limit = 0;
}
}
/* Note that we scan the *uncorrected* ID. */
if ((p = uprv_strrchr(posixID, '@')) != NULL) {
if (correctedPOSIXLocale == NULL) {
/* new locale can be 1 char longer than old one if @ -> __ */
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID)+2));
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
}
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
correctedPOSIXLocale[p-posixID] = 0;
}
const char *p;
if ((p = uprv_strrchr(posixID, '@')) != nullptr) {
p++;
/* Take care of any special cases here.. */
@ -1685,16 +1657,17 @@ The leftmost codepage (.xxx) wins.
/* Don't worry about no__NY. In practice, it won't appear. */
}
if (uprv_strchr(correctedPOSIXLocale,'_') == NULL) {
if (uprv_strchr(correctedPOSIXLocale,'_') == nullptr) {
uprv_strcat(correctedPOSIXLocale, "__"); /* aa@b -> aa__b (note this can make the new locale 1 char longer) */
}
else {
uprv_strcat(correctedPOSIXLocale, "_"); /* aa_CC@b -> aa_CC_b */
}
if ((q = uprv_strchr(p, '.')) != NULL) {
const char *q;
if ((q = uprv_strchr(p, '.')) != nullptr) {
/* How big will the resulting string be? */
len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p));
int32_t len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p));
uprv_strncat(correctedPOSIXLocale, p, q-p);
correctedPOSIXLocale[len] = 0;
}
@ -1710,28 +1683,15 @@ The leftmost codepage (.xxx) wins.
*/
}
/* Was a correction made? */
if (correctedPOSIXLocale != NULL) {
posixID = correctedPOSIXLocale;
}
else {
/* copy it, just in case the original pointer goes away. See j2395 */
correctedPOSIXLocale = (char *)uprv_malloc(uprv_strlen(posixID) + 1);
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
}
posixID = uprv_strcpy(correctedPOSIXLocale, posixID);
}
if (gCorrectedPOSIXLocale == NULL) {
if (gCorrectedPOSIXLocale == nullptr) {
gCorrectedPOSIXLocale = correctedPOSIXLocale;
gCorrectedPOSIXLocaleHeapAllocated = true;
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
correctedPOSIXLocale = NULL;
correctedPOSIXLocale = nullptr;
}
posixID = gCorrectedPOSIXLocale;
if (correctedPOSIXLocale != NULL) { /* Was already set - clean up. */
if (correctedPOSIXLocale != nullptr) { /* Was already set - clean up. */
uprv_free(correctedPOSIXLocale);
}
@ -1747,58 +1707,16 @@ The leftmost codepage (.xxx) wins.
return gCorrectedPOSIXLocale;
}
// No cached value, need to determine the current value
static WCHAR windowsLocale[LOCALE_NAME_MAX_LENGTH] = {};
int length = GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SNAME, windowsLocale, LOCALE_NAME_MAX_LENGTH);
// Now we should have a Windows locale name that needs converted to the POSIX style.
if (length > 0) // If length is 0, then the GetLocaleInfoEx failed.
{
// First we need to go from UTF-16 to char (and also convert from _ to - while we're at it.)
char modifiedWindowsLocale[LOCALE_NAME_MAX_LENGTH] = {};
int32_t i;
for (i = 0; i < UPRV_LENGTHOF(modifiedWindowsLocale); i++)
{
if (windowsLocale[i] == '_')
{
modifiedWindowsLocale[i] = '-';
}
else
{
modifiedWindowsLocale[i] = static_cast<char>(windowsLocale[i]);
}
if (modifiedWindowsLocale[i] == '\0')
{
break;
}
}
if (i >= UPRV_LENGTHOF(modifiedWindowsLocale))
{
// Ran out of room, can't really happen, maybe we'll be lucky about a matching
// locale when tags are dropped
modifiedWindowsLocale[UPRV_LENGTHOF(modifiedWindowsLocale) - 1] = '\0';
}
// Now normalize the resulting name
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(POSIX_LOCALE_CAPACITY + 1));
/* TODO: Should we just exit on memory allocation failure? */
if (correctedPOSIXLocale)
{
int32_t posixLen = uloc_canonicalize(modifiedWindowsLocale, correctedPOSIXLocale, POSIX_LOCALE_CAPACITY, &status);
if (U_SUCCESS(status))
{
*(correctedPOSIXLocale + posixLen) = 0;
gCorrectedPOSIXLocale = correctedPOSIXLocale;
gCorrectedPOSIXLocaleHeapAllocated = true;
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
}
else
{
uprv_free(correctedPOSIXLocale);
}
LCID id = GetThreadLocale();
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(POSIX_LOCALE_CAPACITY + 1));
if (correctedPOSIXLocale) {
int32_t posixLen = uprv_convertToPosix(id, correctedPOSIXLocale, POSIX_LOCALE_CAPACITY, &status);
if (U_SUCCESS(status)) {
*(correctedPOSIXLocale + posixLen) = 0;
gCorrectedPOSIXLocale = correctedPOSIXLocale;
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
} else {
uprv_free(correctedPOSIXLocale);
}
}