ICU-2039 Export uprv_convertToLCID and uprv_convertToPosix so that MSVC and PureCoverage don't crash.

X-SVN-Rev: 11870
This commit is contained in:
George Rhoten 2003-05-09 20:46:41 +00:00
parent e063556b81
commit 4415b1122a
4 changed files with 99 additions and 103 deletions

View File

@ -577,6 +577,72 @@ static const ILcidPosixMap gPosixIDmap[] = {
static const uint32_t gLocaleCount = sizeof(gPosixIDmap)/sizeof(ILcidPosixMap);
static int32_t
idCmp(const char* id1, const char* id2)
{
int32_t diffIdx = 0;
while (*id1 == *id2 && *id1 != 0) {
diffIdx++;
id1++;
id2++;
}
return diffIdx;
}
/**
* Searches for a Windows LCID
*
* @param posixid the Posix style locale id.
* @param status gets set to U_ILLEGAL_ARGUMENT_ERROR when the Posix ID has
* no equivalent Windows LCID.
* @return the LCID
*/
static uint32_t
hostID(const ILcidPosixMap *this_0, const char* posixID, UErrorCode* status)
{
int32_t bestIdx = 0;
int32_t bestIdxDiff = 0;
int32_t posixIDlen = (int32_t)uprv_strlen(posixID) + 1;
uint32_t idx;
for (idx = 0; idx < this_0->numRegions; idx++ ) {
int32_t sameChars = idCmp(posixID, this_0->regionMaps[idx].posixID);
if (sameChars > bestIdxDiff && this_0->regionMaps[idx].posixID[sameChars] == 0) {
if (posixIDlen == sameChars) {
/* Exact match */
return this_0->regionMaps[idx].hostID;
}
bestIdxDiff = sameChars;
bestIdx = idx;
}
}
if (this_0->regionMaps[bestIdx].posixID[bestIdxDiff] == 0) {
*status = U_USING_FALLBACK_WARNING;
return this_0->regionMaps[bestIdx].hostID;
}
/*no match found */
*status = U_ILLEGAL_ARGUMENT_ERROR;
return this_0->regionMaps->hostID;
}
static const char*
posixID(const ILcidPosixMap *this_0, uint32_t hostID)
{
uint32_t i;
for (i = 0; i <= this_0->numRegions; i++)
{
if (this_0->regionMaps[i].hostID == hostID)
{
return this_0->regionMaps[i].posixID;
}
}
/* If you get here, then no matching region was found,
so return the language id with the wild card region. */
return this_0->regionMaps[0].posixID;
}
/*
//////////////////////////////////////
//
@ -585,8 +651,8 @@ static const uint32_t gLocaleCount = sizeof(gPosixIDmap)/sizeof(ILcidPosixMap);
/////////////////////////////////////
*/
U_CFUNC const char *
T_convertToPosix(uint32_t hostid, UErrorCode* status)
U_CAPI const char *
uprv_convertToPosix(uint32_t hostid, UErrorCode* status)
{
uint16_t langID = LANGUAGE_LCID(hostid);
uint32_t index;
@ -612,8 +678,8 @@ T_convertToPosix(uint32_t hostid, UErrorCode* status)
/////////////////////////////////////
*/
U_CFUNC uint32_t
T_convertToLCID(const char* posixID, UErrorCode* status)
U_CAPI uint32_t
uprv_convertToLCID(const char* posixID, UErrorCode* status)
{
uint32_t low = 0;
@ -678,71 +744,5 @@ T_convertToLCID(const char* posixID, UErrorCode* status)
return 0; /* return international (root) */
}
/**
* Searches for a Windows LCID
*
* @param posixid the Posix style locale id.
* @param status gets set to U_ILLEGAL_ARGUMENT_ERROR when the Posix ID has
* no equivalent Windows LCID.
* @return the LCID
*/
static uint32_t
hostID(const ILcidPosixMap *this_0, const char* posixID, UErrorCode* status)
{
int32_t bestIdx = 0;
int32_t bestIdxDiff = 0;
int32_t posixIDlen = (int32_t)uprv_strlen(posixID) + 1;
uint32_t idx;
for (idx = 0; idx < this_0->numRegions; idx++ ) {
int32_t sameChars = idCmp(posixID, this_0->regionMaps[idx].posixID);
if (sameChars > bestIdxDiff && this_0->regionMaps[idx].posixID[sameChars] == 0) {
if (posixIDlen == sameChars) {
/* Exact match */
return this_0->regionMaps[idx].hostID;
}
bestIdxDiff = sameChars;
bestIdx = idx;
}
}
if (this_0->regionMaps[bestIdx].posixID[bestIdxDiff] == 0) {
*status = U_USING_FALLBACK_WARNING;
return this_0->regionMaps[bestIdx].hostID;
}
/*no match found */
*status = U_ILLEGAL_ARGUMENT_ERROR;
return this_0->regionMaps->hostID;
}
static int32_t
idCmp(const char* id1, const char* id2)
{
int32_t diffIdx = 0;
while (*id1 == *id2 && *id1 != 0) {
diffIdx++;
id1++;
id2++;
}
return diffIdx;
}
static const char*
posixID(const ILcidPosixMap *this_0, uint32_t hostID)
{
uint32_t i;
for (i = 0; i <= this_0->numRegions; i++)
{
if (this_0->regionMaps[i].hostID == hostID)
{
return this_0->regionMaps[i].posixID;
}
}
/* If you get here, then no matching region was found,
so return the language id with the wild card region. */
return this_0->regionMaps[0].posixID;
}
#endif

View File

@ -37,9 +37,9 @@ uprv_defaultCodePageForLocale(const char *locale);
#ifdef WIN32
#define LANGUAGE_LCID(hostID) (uint16_t)(0x03FF & hostID)
U_CFUNC const char *T_convertToPosix(uint32_t hostid, UErrorCode* status);
U_CAPI const char *uprv_convertToPosix(uint32_t hostid, UErrorCode* status);
U_CFUNC uint32_t T_convertToLCID(const char* posixID, UErrorCode* status);
U_CAPI uint32_t uprv_convertToLCID(const char* posixID, UErrorCode* status);
#endif /* WIN32 */
#endif /* LOCMAP_H */

View File

@ -161,11 +161,6 @@ static double * const fgNan = &gNan;
static double * const fgInf = &gInf;
#endif
/* prototypes */
static char* u_topNBytesOfDouble(double* d, int n);
static char* u_bottomNBytesOfDouble(double* d, int n);
/*---------------------------------------------------------------------------
Platform utilities
Our general strategy is to assume we're on a POSIX platform. Platforms which
@ -190,6 +185,27 @@ static char* u_bottomNBytesOfDouble(double* d, int n);
#include <langinfo.h>
#endif
/* Utilities to get the bits from a double */
static char*
u_topNBytesOfDouble(double* d, int n)
{
#if U_IS_BIG_ENDIAN
return (char*)d;
#else
return (char*)(d + 1) - n;
#endif
}
static char*
u_bottomNBytesOfDouble(double* d, int n)
{
#if U_IS_BIG_ENDIAN
return (char*)(d + 1) - n;
#else
return (char*)d;
#endif
}
/*---------------------------------------------------------------------------
Universal Implementations
These are designed to work on all platforms. Try these, and if they don't
@ -631,25 +647,6 @@ uprv_digitsAfterDecimal(double x)
return numDigits;
}
static char*
u_topNBytesOfDouble(double* d, int n)
{
#if U_IS_BIG_ENDIAN
return (char*)d;
#else
return (char*)(d + 1) - n;
#endif
}
static char* u_bottomNBytesOfDouble(double* d, int n)
{
#if U_IS_BIG_ENDIAN
return (char*)(d + 1) - n;
#else
return (char*)d;
#endif
}
/*---------------------------------------------------------------------------
Platform-specific Implementations
Try these, and if they don't work on your platform, then special case your
@ -1630,7 +1627,7 @@ The leftmost codepage (.xxx) wins.
#elif defined(WIN32)
UErrorCode status = U_ZERO_ERROR;
LCID id = GetThreadLocale();
const char* locID = T_convertToPosix(id, &status);
const char* locID = uprv_convertToPosix(id, &status);
if (U_FAILURE(status)) {
locID = "en_US";

View File

@ -25,13 +25,12 @@
#include "unicode/uset.h"
#include "cintltst.h"
#include "cstring.h"
#include "unicode/ures.h"
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
#include "unicode/ures.h"
#ifdef WIN32
/* Get the private functions. This is a hack! [grhoten] */
#include "locmap.c"
#include "locmap.h"
#endif
static void TestNullDefault(void);
@ -1485,7 +1484,7 @@ testLCID(UResourceBundle *currentBundle,
return;
}
lcid = T_convertToLCID(localeName, &status);
lcid = uprv_convertToLCID(localeName, &status);
if (U_FAILURE(status)) {
if (expectedLCID == 0) {
log_verbose("INFO: %-5s does not have any LCID mapping\n",
@ -1499,7 +1498,7 @@ testLCID(UResourceBundle *currentBundle,
}
status = U_ZERO_ERROR;
uprv_strcpy(lcidStringC, T_convertToPosix(expectedLCID, &status));
uprv_strcpy(lcidStringC, uprv_convertToPosix(expectedLCID, &status));
if (U_FAILURE(status)) {
log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
expectedLCID, u_errorName(status));