ICU-1733 Integrate some of the easier (and non-redundent) changes from Lotus.
X-SVN-Rev: 7802
This commit is contained in:
parent
13e01fb91d
commit
41ffc2ef36
@ -35,7 +35,7 @@ UBool UnicodeConverter_cleanup()
|
||||
{
|
||||
if (availableConverterNames)
|
||||
{
|
||||
delete []availableConverterNames;
|
||||
uprv_free(availableConverterNames);
|
||||
availableConverterNames = NULL;
|
||||
}
|
||||
availableConverterNamesCount = 0;
|
||||
@ -429,7 +429,7 @@ UnicodeConverter::getAvailableNames(int32_t& num, UErrorCode& err)
|
||||
if (availableConverterNames==NULL) {
|
||||
int32_t count = ucnv_io_countAvailableConverters(&err);
|
||||
if (count > 0) {
|
||||
const char **names = new const char *[count];
|
||||
const char **names = (const char **) uprv_malloc( sizeof(const char*) * count );
|
||||
if (names != NULL) {
|
||||
ucnv_io_fillAvailableConverters(names, &err);
|
||||
|
||||
@ -444,7 +444,7 @@ UnicodeConverter::getAvailableNames(int32_t& num, UErrorCode& err)
|
||||
|
||||
/* if a different thread set it first, then delete the extra data */
|
||||
if (names != 0) {
|
||||
delete [] names;
|
||||
uprv_free(names);
|
||||
}
|
||||
} else {
|
||||
num = 0;
|
||||
|
@ -178,7 +178,7 @@ T_CString_strnicmp(const char *str1, const char *str2, uint32_t n) {
|
||||
U_CAPI char* U_EXPORT2
|
||||
uprv_strdup(const char *src) {
|
||||
size_t len = strlen(src) + 1;
|
||||
char *dup = (char *) malloc(len);
|
||||
char *dup = (char *) uprv_malloc(len);
|
||||
|
||||
if (dup) {
|
||||
uprv_memcpy(dup, src, len);
|
||||
|
@ -206,10 +206,10 @@ Locale::LocaleProxy::operator const Locale&(void) const
|
||||
|
||||
Locale::~Locale()
|
||||
{
|
||||
/*if fullName is on the heap, we delete it*/
|
||||
/*if fullName is on the heap, we free it*/
|
||||
if (fullName != fullNameBuffer)
|
||||
{
|
||||
delete []fullName;
|
||||
uprv_free(fullName);
|
||||
fullName = NULL;
|
||||
}
|
||||
}
|
||||
@ -294,7 +294,7 @@ Locale::Locale( const char * newLanguage,
|
||||
to go to the heap for temporary buffers*/
|
||||
if (size > ULOC_FULLNAME_CAPACITY)
|
||||
{
|
||||
togo_heap = new char[size+1];
|
||||
togo_heap = (char *)uprv_malloc(sizeof(char)*(size+1));
|
||||
togo = togo_heap;
|
||||
}
|
||||
else
|
||||
@ -336,7 +336,9 @@ Locale::Locale( const char * newLanguage,
|
||||
// string.
|
||||
init(togo);
|
||||
|
||||
delete [] togo_heap; /* If it was needed */
|
||||
if (togo_heap) {
|
||||
uprv_free(togo_heap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,13 +352,13 @@ Locale &Locale::operator=(const Locale &other)
|
||||
{
|
||||
/* Free our current storage */
|
||||
if(fullName != fullNameBuffer) {
|
||||
delete [] fullName;
|
||||
uprv_free(fullName);
|
||||
fullName = fullNameBuffer;
|
||||
}
|
||||
|
||||
/* Allocate the full name if necessary */
|
||||
if(other.fullName != other.fullNameBuffer) {
|
||||
fullName = new char[(uprv_strlen(other.fullName)+1)];
|
||||
fullName = (char *)uprv_malloc(sizeof(char)*(uprv_strlen(other.fullName)+1));
|
||||
}
|
||||
|
||||
/* Copy the full name */
|
||||
@ -382,7 +384,7 @@ Locale& Locale::init(const char* localeID)
|
||||
{
|
||||
/* Free our current storage */
|
||||
if(fullName != fullNameBuffer) {
|
||||
delete [] fullName;
|
||||
uprv_free(fullName);
|
||||
fullName = fullNameBuffer;
|
||||
}
|
||||
|
||||
@ -404,7 +406,7 @@ Locale& Locale::init(const char* localeID)
|
||||
length = uloc_getName(localeID, fullName, sizeof(fullNameBuffer), &err);
|
||||
if(U_FAILURE(err) || err == U_STRING_NOT_TERMINATED_WARNING) {
|
||||
/*Go to heap for the fullName if necessary*/
|
||||
fullName = new char[length + 1];
|
||||
fullName = (char *)uprv_malloc(sizeof(char)*(length + 1));
|
||||
if(fullName == 0) {
|
||||
fullName = fullNameBuffer;
|
||||
break;
|
||||
@ -974,7 +976,7 @@ Locale::initLocaleCache(void)
|
||||
//
|
||||
// This can be a memory leak for an extra long default locale,
|
||||
// but this code shouldn't normally get executed.
|
||||
localeCache[idx].fullName = new char[uprv_strlen(localeCache[idx].fullNameBuffer) + 1];
|
||||
localeCache[idx].fullName = (char *)uprv_malloc(sizeof(char)*(uprv_strlen(localeCache[idx].fullNameBuffer) + 1));
|
||||
uprv_strcpy(localeCache[idx].fullName, localeCache[idx].fullNameBuffer);
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@
|
||||
#define UNICODE_HASH_CODEPOINT 0x0023
|
||||
#define UNICODE_SEMICOLON_CODEPOINT 0x003B
|
||||
#define UNICODE_PLUS_CODEPOINT 0x002B
|
||||
#define UNICODE_LEFT_CURLY_CODEPOINT 0x007B
|
||||
#define UNICODE_RIGHT_CURLY_CODEPOINT 0x007D
|
||||
#define UNICODE_LEFT_CURLY_CODEPOINT 0x007B
|
||||
#define UNICODE_RIGHT_CURLY_CODEPOINT 0x007D
|
||||
#define UCNV_PRV_ESCAPE_ICU 0
|
||||
#define UCNV_PRV_ESCAPE_C 'C'
|
||||
#define UCNV_PRV_ESCAPE_XML_DEC 'D'
|
||||
|
@ -26,9 +26,9 @@ struct UDataMemory {
|
||||
const commonDataFuncs *vFuncs; /* Function Pointers for accessing TOC */
|
||||
|
||||
const DataHeader *pHeader; /* Header of the memory being described by this */
|
||||
/* UDataMemory object. */
|
||||
/* UDataMemory object. */
|
||||
const void *toc; /* For common memory, table of contents for */
|
||||
/* the pieces within. */
|
||||
/* the pieces within. */
|
||||
UBool heapAllocated; /* True if this UDataMemory Object is on the */
|
||||
/* heap and thus needs to be deleted when closed. */
|
||||
|
||||
@ -38,7 +38,7 @@ struct UDataMemory {
|
||||
void *map; /* Handle, or other data, OS dependent. */
|
||||
/* Only non-null if a close operation should unmap */
|
||||
/* the associated data, and additional info */
|
||||
/* beyond the mapAddr is needed to do that. */
|
||||
/* beyond the mapAddr is needed to do that. */
|
||||
};
|
||||
|
||||
UDataMemory *UDataMemory_createNewInstance(UErrorCode *pErr);
|
||||
|
@ -372,7 +372,7 @@ uhash_find(const UHashtable *hash, const void* key) {
|
||||
UHashTok keyholder;
|
||||
const UHashElement *e;
|
||||
keyholder.pointer = (void*) key;
|
||||
e = _uhash_find(hash, keyholder, hash->keyHasher(keyholder));
|
||||
e = _uhash_find(hash, keyholder, hash->keyHasher(keyholder));
|
||||
return IS_EMPTY_OR_DELETED(e->hashcode) ? NULL : e;
|
||||
}
|
||||
|
||||
|
@ -196,13 +196,13 @@ u_charName(UChar32 code, UCharNameChoice nameChoice,
|
||||
}
|
||||
|
||||
if(i==0) {
|
||||
if (nameChoice == U_EXTENDED_CHAR_NAME) {
|
||||
/* extended character name */
|
||||
if (nameChoice == U_EXTENDED_CHAR_NAME) {
|
||||
/* extended character name */
|
||||
length = getExtName((uint32_t) code, buffer, (uint16_t) bufferLength);
|
||||
} else {
|
||||
/* normal character name */
|
||||
length=getName(uCharNames, (uint32_t)code, nameChoice, buffer, (uint16_t)bufferLength);
|
||||
}
|
||||
} else {
|
||||
/* normal character name */
|
||||
length=getName(uCharNames, (uint32_t)code, nameChoice, buffer, (uint16_t)bufferLength);
|
||||
}
|
||||
}
|
||||
|
||||
return u_terminateChars(buffer, bufferLength, length, pErrorCode);
|
||||
|
@ -2825,7 +2825,7 @@ private:
|
||||
UBool allocate(int32_t capacity);
|
||||
|
||||
// release the array if owned
|
||||
inline void releaseArray();
|
||||
void releaseArray(void);
|
||||
|
||||
// Pin start and limit to acceptable values.
|
||||
inline void pinIndices(UTextOffset& start,
|
||||
@ -3813,13 +3813,6 @@ inline int32_t
|
||||
UnicodeString::getCapacity() const
|
||||
{ return fCapacity; }
|
||||
|
||||
inline void
|
||||
UnicodeString::releaseArray() {
|
||||
if((fFlags & kRefCounted) && removeRef() == 0) {
|
||||
delete [] ((int32_t *)fArray - 1);
|
||||
}
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
UnicodeString::addRef()
|
||||
{ return ++*((int32_t *)fArray - 1); }
|
||||
|
@ -304,7 +304,7 @@ UnicodeString::allocate(int32_t capacity) {
|
||||
// round up to a multiple of 16; then divide by 4 and allocate int32_t's
|
||||
// to be safely aligned for the refCount
|
||||
int32_t words = (int32_t)(((sizeof(int32_t) + capacity * U_SIZEOF_UCHAR + 15) & ~15) >> 2);
|
||||
int32_t *array = new int32_t[words];
|
||||
int32_t *array = (int32_t*) uprv_malloc( sizeof(int32_t) * words );
|
||||
if(array != 0) {
|
||||
// set initial refCount and point behind the refCount
|
||||
*array++ = 1;
|
||||
@ -331,6 +331,14 @@ UnicodeString::~UnicodeString()
|
||||
releaseArray();
|
||||
}
|
||||
|
||||
void
|
||||
UnicodeString::releaseArray() {
|
||||
if((fFlags & kRefCounted) && removeRef() == 0) {
|
||||
uprv_free((int32_t *)fArray - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================
|
||||
// Assignment
|
||||
//========================================
|
||||
@ -1221,7 +1229,7 @@ UnicodeString::caseMap(BreakIterator *titleIter,
|
||||
ubrk_close(cTitleIter);
|
||||
}
|
||||
|
||||
delete [] bufferToDelete;
|
||||
uprv_free(bufferToDelete);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
setToBogus();
|
||||
}
|
||||
@ -1312,7 +1320,7 @@ UnicodeString::doReplace(UTextOffset start,
|
||||
|
||||
// delayed delete in case srcChars == fArray when we started, and
|
||||
// to keep oldArray alive for the above operations
|
||||
delete [] bufferToDelete;
|
||||
uprv_free(bufferToDelete);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -1332,10 +1340,10 @@ UnicodeString::handleReplaceBetween(UTextOffset start,
|
||||
*/
|
||||
void
|
||||
UnicodeString::copy(int32_t start, int32_t limit, int32_t dest) {
|
||||
UChar* text = new UChar[limit - start];
|
||||
UChar* text = (UChar*) uprv_malloc( sizeof(UChar) * (limit - start) );
|
||||
extractBetween(start, limit, text, 0);
|
||||
insert(dest, text, 0, limit - start);
|
||||
delete[] text;
|
||||
uprv_free(text);
|
||||
}
|
||||
|
||||
UnicodeString&
|
||||
@ -1847,7 +1855,7 @@ UnicodeString::cloneArrayIfNeeded(int32_t newCapacity,
|
||||
int32_t *pRefCount = ((int32_t *)array - 1);
|
||||
if(--*pRefCount == 0) {
|
||||
if(pBufferToDelete == 0) {
|
||||
delete [] pRefCount;
|
||||
uprv_free(pRefCount);
|
||||
} else {
|
||||
// the caller requested to delete it himself
|
||||
*pBufferToDelete = pRefCount;
|
||||
|
@ -56,7 +56,7 @@ UVector::UVector(UObjectDeleter d, UKeyComparator c, int32_t initialCapacity, UE
|
||||
}
|
||||
|
||||
void UVector::_init(int32_t initialCapacity, UErrorCode &status) {
|
||||
elements = new UHashTok[initialCapacity];
|
||||
elements = (UHashTok *)uprv_malloc(sizeof(UHashTok)*initialCapacity);
|
||||
if (elements == 0) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
} else {
|
||||
@ -66,7 +66,7 @@ void UVector::_init(int32_t initialCapacity, UErrorCode &status) {
|
||||
|
||||
UVector::~UVector() {
|
||||
removeAllElements();
|
||||
delete[] elements;
|
||||
uprv_free(elements);
|
||||
elements = 0;
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ void UVector::insertElementAt(void* obj, int32_t index, UErrorCode &status) {
|
||||
elements[i] = elements[i-1];
|
||||
}
|
||||
elements[index].pointer = obj;
|
||||
++count;
|
||||
++count;
|
||||
}
|
||||
/* else index out of range */
|
||||
}
|
||||
@ -170,7 +170,7 @@ UBool UVector::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) {
|
||||
if (newCap < minimumCapacity) {
|
||||
newCap = minimumCapacity;
|
||||
}
|
||||
UHashTok* newElems = new UHashTok[newCap];
|
||||
UHashTok* newElems = (UHashTok *)uprv_malloc(sizeof(UHashTok)*newCap);
|
||||
if (newElems == 0) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
return FALSE;
|
||||
|
@ -19,23 +19,23 @@
|
||||
#include <stdlib.h>
|
||||
#include "locbund.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "cmemory.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "unicode/uloc.h"
|
||||
|
||||
ULocaleBundle*
|
||||
u_locbund_new(const char *loc)
|
||||
{
|
||||
ULocaleBundle *result = (ULocaleBundle*) malloc(sizeof(ULocaleBundle));
|
||||
ULocaleBundle *result = (ULocaleBundle*) uprv_malloc(sizeof(ULocaleBundle));
|
||||
int32_t len;
|
||||
|
||||
if(result == 0)
|
||||
return 0;
|
||||
|
||||
len = (loc == 0 ? strlen(uloc_getDefault()) : strlen(loc));
|
||||
result->fLocale = (char*) malloc(len + 1);
|
||||
result->fLocale = (char*) uprv_malloc(len + 1);
|
||||
if(result->fLocale == 0) {
|
||||
free(result);
|
||||
uprv_free(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -55,15 +55,15 @@ u_locbund_new(const char *loc)
|
||||
ULocaleBundle*
|
||||
u_locbund_clone(const ULocaleBundle *bundle)
|
||||
{
|
||||
ULocaleBundle *result = (ULocaleBundle*)malloc(sizeof(ULocaleBundle));
|
||||
ULocaleBundle *result = (ULocaleBundle*)uprv_malloc(sizeof(ULocaleBundle));
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
if(result == 0)
|
||||
return 0;
|
||||
|
||||
result->fLocale = (char*) malloc(strlen(bundle->fLocale) + 1);
|
||||
result->fLocale = (char*) uprv_malloc(strlen(bundle->fLocale) + 1);
|
||||
if(result->fLocale == 0) {
|
||||
free(result);
|
||||
uprv_free(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ u_locbund_clone(const ULocaleBundle *bundle)
|
||||
void
|
||||
u_locbund_delete(ULocaleBundle *bundle)
|
||||
{
|
||||
free(bundle->fLocale);
|
||||
uprv_free(bundle->fLocale);
|
||||
|
||||
if(bundle->fNumberFormat != 0)
|
||||
unum_close(bundle->fNumberFormat);
|
||||
@ -111,7 +111,7 @@ u_locbund_delete(ULocaleBundle *bundle)
|
||||
if(bundle->fTimeFormat != 0)
|
||||
udat_close(bundle->fTimeFormat);
|
||||
|
||||
free(bundle);
|
||||
uprv_free(bundle);
|
||||
}
|
||||
|
||||
UNumberFormat*
|
||||
|
@ -26,9 +26,8 @@
|
||||
#include "unicode/udat.h"
|
||||
#include "unicode/uloc.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "cmemory.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/* --- Prototypes ---------------------------- */
|
||||
@ -330,7 +329,7 @@ u_vsnprintf(UChar *buffer,
|
||||
written = u_vsnprintf_u(buffer, count, locale, pattern, ap);
|
||||
|
||||
/* clean up */
|
||||
free(pattern);
|
||||
uprv_free(pattern);
|
||||
|
||||
return written;
|
||||
}
|
||||
@ -442,7 +441,7 @@ u_sprintf_string_handler(u_localized_string *output,
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
free(s);
|
||||
uprv_free(s);
|
||||
|
||||
return written;
|
||||
}
|
||||
@ -703,7 +702,7 @@ u_sprintf_char_handler(u_localized_string *output,
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
free(s);
|
||||
uprv_free(s);
|
||||
|
||||
return written;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,6 +26,7 @@
|
||||
#include "unicode/ures.h"
|
||||
#include "unicode/ucnv.h"
|
||||
#include "cstring.h"
|
||||
#include "cmemory.h"
|
||||
|
||||
|
||||
static UBool hasICUData(const char *cp) {
|
||||
@ -33,7 +34,7 @@ static UBool hasICUData(const char *cp) {
|
||||
UConverter *cnv = NULL;
|
||||
#if 0
|
||||
UResourceBundle *r = NULL;
|
||||
|
||||
|
||||
r = ures_open(NULL, NULL, &status);
|
||||
if(U_FAILURE(status)) {
|
||||
return FALSE;
|
||||
@ -55,203 +56,202 @@ static UBool hasICUData(const char *cp) {
|
||||
|
||||
U_CAPI UFILE* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fopen(const char *filename,
|
||||
const char *perm,
|
||||
const char *locale,
|
||||
const char *codepage)
|
||||
const char *perm,
|
||||
const char *locale,
|
||||
const char *codepage)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBool useSysCP = (UBool)(locale == 0 && codepage == 0);
|
||||
UFILE *result = (UFILE*) malloc(sizeof(UFILE));
|
||||
if(result == 0)
|
||||
return 0;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBool useSysCP = (UBool)(locale == 0 && codepage == 0);
|
||||
UFILE *result = (UFILE*) uprv_malloc(sizeof(UFILE));
|
||||
if(result == 0)
|
||||
return 0;
|
||||
|
||||
result->fFile = fopen(filename, perm);
|
||||
if(result->fFile == 0) {
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
result->fFile = fopen(filename, perm);
|
||||
if(result->fFile == 0) {
|
||||
uprv_free(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
result->fOwnFile = TRUE;
|
||||
result->fOwnFile = TRUE;
|
||||
|
||||
/* if locale is 0, use the default */
|
||||
if(locale == 0)
|
||||
locale = uloc_getDefault();
|
||||
/* if locale is 0, use the default */
|
||||
if(locale == 0)
|
||||
locale = uloc_getDefault();
|
||||
|
||||
result->fBundle = u_loccache_get(locale);
|
||||
if(result->fBundle == 0) {
|
||||
fclose(result->fFile);
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
result->fBundle = u_loccache_get(locale);
|
||||
if(result->fBundle == 0) {
|
||||
fclose(result->fFile);
|
||||
uprv_free(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
result->fOwnBundle = FALSE;
|
||||
result->fUCPos = result->fUCBuffer;
|
||||
result->fUCLimit = result->fUCBuffer;
|
||||
result->fOwnBundle = FALSE;
|
||||
result->fUCPos = result->fUCBuffer;
|
||||
result->fUCLimit = result->fUCBuffer;
|
||||
|
||||
/* if the codepage is 0, use the default for the locale */
|
||||
if(codepage == 0) {
|
||||
codepage = uprv_defaultCodePageForLocale(locale);
|
||||
|
||||
/* if the codepage is still 0, the default codepage will be used */
|
||||
}
|
||||
|
||||
/* if both locale and codepage are 0, use the system default codepage */
|
||||
else if(useSysCP)
|
||||
codepage = 0;
|
||||
/* if the codepage is 0, use the default for the locale */
|
||||
if(codepage == 0) {
|
||||
codepage = uprv_defaultCodePageForLocale(locale);
|
||||
|
||||
result->fConverter = ucnv_open(codepage, &status);
|
||||
if(U_FAILURE(status) || result->fConverter == 0) {
|
||||
fclose(result->fFile);
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
/* if the codepage is still 0, the default codepage will be used */
|
||||
}
|
||||
/* if both locale and codepage are 0, use the system default codepage */
|
||||
else if(useSysCP) {
|
||||
codepage = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
result->fConverter = ucnv_open(codepage, &status);
|
||||
if(U_FAILURE(status) || result->fConverter == 0) {
|
||||
fclose(result->fFile);
|
||||
uprv_free(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
U_CAPI UFILE* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_finit(FILE *f,
|
||||
const char *locale,
|
||||
const char *codepage)
|
||||
const char *locale,
|
||||
const char *codepage)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBool useSysCP = (UBool)(locale == NULL && codepage == NULL);
|
||||
UFILE *result = (UFILE*) malloc(sizeof(UFILE));
|
||||
if(result == 0)
|
||||
return 0;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBool useSysCP = (UBool)(locale == NULL && codepage == NULL);
|
||||
UFILE *result = (UFILE*) uprv_malloc(sizeof(UFILE));
|
||||
if(result == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
result->fFile = &_iob[_fileno(f)];
|
||||
result->fFile = &_iob[_fileno(f)];
|
||||
#else
|
||||
result->fFile = f;
|
||||
result->fFile = f;
|
||||
#endif
|
||||
result->fOwnFile = FALSE;
|
||||
result->fOwnBundle = FALSE;
|
||||
result->fUCPos = result->fUCBuffer;
|
||||
result->fUCLimit = result->fUCBuffer;
|
||||
result->fConverter = NULL;
|
||||
result->fBundle = NULL;
|
||||
result->fOwnFile = FALSE;
|
||||
result->fOwnBundle = FALSE;
|
||||
result->fUCPos = result->fUCBuffer;
|
||||
result->fUCLimit = result->fUCBuffer;
|
||||
result->fConverter = NULL;
|
||||
result->fBundle = NULL;
|
||||
|
||||
if(hasICUData(codepage)) {
|
||||
/* if locale is 0, use the default */
|
||||
if(locale == 0)
|
||||
locale = uloc_getDefault();
|
||||
if(hasICUData(codepage)) {
|
||||
/* if locale is 0, use the default */
|
||||
if(locale == 0) {
|
||||
locale = uloc_getDefault();
|
||||
}
|
||||
|
||||
result->fBundle = u_loccache_get(locale);
|
||||
if(result->fBundle == 0) {
|
||||
/* DO NOT FCLOSE HERE! */
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* bootstrap mode */
|
||||
return result;
|
||||
}
|
||||
|
||||
/* if the codepage is 0, use the default for the locale */
|
||||
if(codepage == 0) {
|
||||
codepage = uprv_defaultCodePageForLocale(locale);
|
||||
|
||||
|
||||
|
||||
/* if the codepage is still 0, the default codepage will be used */
|
||||
if(codepage == 0) {
|
||||
result->fConverter = ucnv_open(0, &status);
|
||||
if(U_FAILURE(status) || result->fConverter == 0) {
|
||||
/* DO NOT fclose here!!!!!! */
|
||||
free(result);
|
||||
result->fBundle = u_loccache_get(locale);
|
||||
if(result->fBundle == 0) {
|
||||
/* DO NOT FCLOSE HERE! */
|
||||
uprv_free(result);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* bootstrap mode */
|
||||
return result;
|
||||
}
|
||||
} else if (*codepage != '\0') {
|
||||
result->fConverter = ucnv_open(codepage, &status);
|
||||
if(U_FAILURE(status) || result->fConverter == 0) {
|
||||
/* DO NOT fclose here!!!!!! */
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
} else if(useSysCP) { /* if both locale and codepage are 0, use the system default codepage */
|
||||
codepage = 0;
|
||||
}
|
||||
return result;
|
||||
|
||||
/* if the codepage is 0, use the default for the locale */
|
||||
if(codepage == 0) {
|
||||
codepage = uprv_defaultCodePageForLocale(locale);
|
||||
|
||||
/* if the codepage is still 0, the default codepage will be used */
|
||||
if(codepage == 0) {
|
||||
result->fConverter = ucnv_open(0, &status);
|
||||
if(U_FAILURE(status) || result->fConverter == 0) {
|
||||
/* DO NOT fclose here!!!!!! */
|
||||
uprv_free(result);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if (*codepage != '\0') {
|
||||
result->fConverter = ucnv_open(codepage, &status);
|
||||
if(U_FAILURE(status) || result->fConverter == 0) {
|
||||
/* DO NOT fclose here!!!!!! */
|
||||
uprv_free(result);
|
||||
return 0;
|
||||
}
|
||||
} else if(useSysCP) { /* if both locale and codepage are 0, use the system default codepage */
|
||||
codepage = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
U_CAPI void U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fclose(UFILE *file)
|
||||
{
|
||||
fflush(file->fFile);
|
||||
fflush(file->fFile);
|
||||
|
||||
if(file->fOwnFile)
|
||||
fclose(file->fFile);
|
||||
if(file->fOwnFile)
|
||||
fclose(file->fFile);
|
||||
|
||||
if(file->fOwnBundle)
|
||||
u_locbund_delete(file->fBundle);
|
||||
if(file->fOwnBundle)
|
||||
u_locbund_delete(file->fBundle);
|
||||
|
||||
ucnv_close(file->fConverter);
|
||||
|
||||
free(file);
|
||||
ucnv_close(file->fConverter);
|
||||
uprv_free(file);
|
||||
}
|
||||
|
||||
U_CAPI FILE* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fgetfile( UFILE *f)
|
||||
{
|
||||
return f->fFile;
|
||||
return f->fFile;
|
||||
}
|
||||
|
||||
U_CAPI const char* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fgetlocale( UFILE *file)
|
||||
{
|
||||
return file->fBundle->fLocale;
|
||||
return file->fBundle->fLocale;
|
||||
}
|
||||
|
||||
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fsetlocale(const char *locale,
|
||||
UFILE *file)
|
||||
UFILE *file)
|
||||
{
|
||||
if(file->fOwnBundle)
|
||||
u_locbund_delete(file->fBundle);
|
||||
if(file->fOwnBundle)
|
||||
u_locbund_delete(file->fBundle);
|
||||
|
||||
file->fBundle = u_loccache_get(locale);
|
||||
file->fOwnBundle = FALSE;
|
||||
file->fBundle = u_loccache_get(locale);
|
||||
file->fOwnBundle = FALSE;
|
||||
|
||||
return file->fBundle == 0 ? -1 : 0;
|
||||
return file->fBundle == 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
U_CAPI const char* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fgetcodepage(UFILE *file)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const char *codepage;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const char *codepage;
|
||||
|
||||
codepage = ucnv_getName(file->fConverter, &status);
|
||||
if(U_FAILURE(status)) return 0;
|
||||
return codepage;
|
||||
codepage = ucnv_getName(file->fConverter, &status);
|
||||
if(U_FAILURE(status))
|
||||
return 0;
|
||||
return codepage;
|
||||
}
|
||||
|
||||
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fsetcodepage( const char *codepage,
|
||||
UFILE *file)
|
||||
UFILE *file)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
/* if the codepage is 0, use the default for the locale */
|
||||
if(codepage == 0) {
|
||||
codepage = uprv_defaultCodePageForLocale(file->fBundle->fLocale);
|
||||
|
||||
/* if the codepage is still 0, fall back on the default codepage */
|
||||
}
|
||||
/* if the codepage is 0, use the default for the locale */
|
||||
if(codepage == 0) {
|
||||
codepage = uprv_defaultCodePageForLocale(file->fBundle->fLocale);
|
||||
|
||||
ucnv_close(file->fConverter);
|
||||
file->fConverter = ucnv_open(codepage, &status);
|
||||
if(U_FAILURE(status))
|
||||
return -1;
|
||||
return 0;
|
||||
/* if the codepage is still 0, fall back on the default codepage */
|
||||
}
|
||||
|
||||
ucnv_close(file->fConverter);
|
||||
file->fConverter = ucnv_open(codepage, &status);
|
||||
if(U_FAILURE(status))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
U_CAPI UConverter * U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fgetConverter(UFILE *file)
|
||||
{
|
||||
return file->fConverter;
|
||||
return file->fConverter;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "cmemory.h"
|
||||
#include "ufmt_cmn.h"
|
||||
#include "unicode/uchar.h"
|
||||
#include "unicode/ucnv.h"
|
||||
@ -136,7 +136,7 @@ ufmt_defaultCPToUnicode(const char *s,
|
||||
|
||||
/* perform the conversion in one swoop */
|
||||
size = (len + 1) / ucnv_getMinCharSize(defConverter);
|
||||
target = (UChar*) malloc(size * sizeof(UChar));
|
||||
target = (UChar*) uprv_malloc(size * sizeof(UChar));
|
||||
if(target != 0) {
|
||||
|
||||
alias = target;
|
||||
@ -167,7 +167,7 @@ ufmt_unicodeToDefaultCP(const UChar *s,
|
||||
|
||||
/* perform the conversion in one swoop */
|
||||
target = (char*)
|
||||
malloc((len + 1) * ucnv_getMaxCharSize(defConverter) * sizeof(char));
|
||||
uprv_malloc((len + 1) * ucnv_getMaxCharSize(defConverter) * sizeof(char));
|
||||
size = (len) * ucnv_getMaxCharSize(defConverter) * sizeof(char);
|
||||
if(target != 0) {
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -152,11 +152,15 @@ ChoiceFormat::operator=(const ChoiceFormat& that)
|
||||
if (this != &that) {
|
||||
NumberFormat::operator=(that);
|
||||
fCount = that.fCount;
|
||||
delete [] fChoiceLimits; fChoiceLimits = 0;
|
||||
delete [] fClosures; fClosures = 0;
|
||||
delete [] fChoiceFormats; fChoiceFormats = 0;
|
||||
fChoiceLimits = new double[fCount];
|
||||
fClosures = new UBool[fCount];
|
||||
uprv_free(fChoiceLimits);
|
||||
fChoiceLimits = NULL;
|
||||
uprv_free(fClosures);
|
||||
fClosures = NULL;
|
||||
delete [] fChoiceFormats;
|
||||
fChoiceFormats = NULL;
|
||||
|
||||
fChoiceLimits = (double*) uprv_malloc( sizeof(double) * fCount);
|
||||
fClosures = (UBool*) uprv_malloc( sizeof(UBool) * fCount);
|
||||
fChoiceFormats = new UnicodeString[fCount];
|
||||
|
||||
uprv_arrayCopy(that.fChoiceLimits, fChoiceLimits, fCount);
|
||||
@ -170,12 +174,12 @@ ChoiceFormat::operator=(const ChoiceFormat& that)
|
||||
|
||||
ChoiceFormat::~ChoiceFormat()
|
||||
{
|
||||
delete [] fChoiceLimits;
|
||||
fChoiceLimits = 0;
|
||||
delete [] fClosures;
|
||||
fClosures = 0;
|
||||
uprv_free(fChoiceLimits);
|
||||
fChoiceLimits = NULL;
|
||||
uprv_free(fClosures);
|
||||
fClosures = NULL;
|
||||
delete [] fChoiceFormats;
|
||||
fChoiceFormats = 0;
|
||||
fChoiceFormats = NULL;
|
||||
fCount = 0;
|
||||
}
|
||||
|
||||
@ -265,8 +269,8 @@ ChoiceFormat::applyPattern(const UnicodeString& pattern,
|
||||
}
|
||||
|
||||
// Allocate the required storage.
|
||||
double *newLimits = new double[count];
|
||||
UBool *newClosures = new UBool[count];
|
||||
double *newLimits = (double*) uprv_malloc( sizeof(double) * count);
|
||||
UBool *newClosures = (UBool*) uprv_malloc( sizeof(UBool) * count);
|
||||
UnicodeString *newFormats = new UnicodeString[count];
|
||||
|
||||
// Perform the second pass
|
||||
@ -347,8 +351,8 @@ ChoiceFormat::applyPattern(const UnicodeString& pattern,
|
||||
newFormats[k] = buf;
|
||||
|
||||
// Don't modify this object until the parse succeeds
|
||||
delete[] fChoiceLimits;
|
||||
delete[] fClosures;
|
||||
uprv_free(fChoiceLimits);
|
||||
uprv_free(fClosures);
|
||||
delete[] fChoiceFormats;
|
||||
fCount = count;
|
||||
fChoiceLimits = newLimits;
|
||||
@ -359,8 +363,8 @@ ChoiceFormat::applyPattern(const UnicodeString& pattern,
|
||||
error:
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
syntaxError(pattern,i,parseError);
|
||||
delete[] newLimits;
|
||||
delete[] newClosures;
|
||||
uprv_free(newLimits);
|
||||
uprv_free(newClosures);
|
||||
delete[] newFormats;
|
||||
return;
|
||||
|
||||
@ -444,8 +448,8 @@ ChoiceFormat::adoptChoices(double *limits,
|
||||
if(limits == 0 || formats == 0)
|
||||
return;
|
||||
|
||||
delete [] fChoiceLimits;
|
||||
delete [] fClosures;
|
||||
uprv_free(fChoiceLimits);
|
||||
uprv_free(fClosures);
|
||||
delete [] fChoiceFormats;
|
||||
fChoiceLimits = limits;
|
||||
fClosures = closures;
|
||||
@ -453,7 +457,7 @@ ChoiceFormat::adoptChoices(double *limits,
|
||||
fCount = cnt;
|
||||
|
||||
if (fClosures == 0) {
|
||||
fClosures = new UBool[fCount];
|
||||
fClosures = (UBool*) uprv_malloc( sizeof(UBool) * fCount);
|
||||
int32_t i;
|
||||
for (i=0; i<fCount; ++i) {
|
||||
fClosures[i] = FALSE;
|
||||
@ -482,15 +486,15 @@ ChoiceFormat::setChoices( const double* limits,
|
||||
if(limits == 0 || formats == 0)
|
||||
return;
|
||||
|
||||
delete [] fChoiceLimits;
|
||||
delete [] fClosures;
|
||||
uprv_free(fChoiceLimits);
|
||||
uprv_free(fClosures);
|
||||
delete [] fChoiceFormats;
|
||||
|
||||
// Note that the old arrays are deleted and this owns
|
||||
// the created array.
|
||||
fCount = cnt;
|
||||
fChoiceLimits = new double[fCount];
|
||||
fClosures = new UBool[fCount];
|
||||
fChoiceLimits = (double*) uprv_malloc( sizeof(double) * fCount);
|
||||
fClosures = (UBool*) uprv_malloc( sizeof(UBool) * fCount);
|
||||
fChoiceFormats = new UnicodeString[fCount];
|
||||
|
||||
uprv_arrayCopy(limits, fChoiceLimits, fCount);
|
||||
|
@ -160,7 +160,7 @@ void CollationElementIterator::setText(const UnicodeString& source,
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int32_t length = source.length();
|
||||
UChar *string = NULL;
|
||||
if (m_data_->isWritable && m_data_->iteratordata_.string != NULL) {
|
||||
|
@ -12,13 +12,8 @@
|
||||
* 03/25/97 clhuang Initial Implementation.
|
||||
********************************************************************************
|
||||
*/
|
||||
#ifndef _FMTABLE
|
||||
#include "unicode/fmtable.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CMEMORY
|
||||
#include "cmemory.h"
|
||||
#endif
|
||||
|
||||
// *****************************************************************************
|
||||
// class Formattable
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "unicode/ucnv_err.h"
|
||||
#include "unicode/uchar.h"
|
||||
#include "ustrfmt.h"
|
||||
#include "cmemory.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// class MessageFormat
|
||||
@ -116,8 +117,8 @@ MessageFormat::MessageFormat(const UnicodeString& pattern,
|
||||
fCount(kMaxFormat),
|
||||
fArgumentNumbers(NULL)
|
||||
{
|
||||
fOffsets = new int32_t[fCount];
|
||||
fArgumentNumbers = new int32_t[fCount];
|
||||
fOffsets = (int32_t*) uprv_malloc( sizeof(int32_t) * fCount );
|
||||
fArgumentNumbers = (int32_t*) uprv_malloc( sizeof(int32_t) * fCount );
|
||||
for (int32_t i = 0; i < fCount; i++) {
|
||||
fFormats[i] = NULL; // Format instances
|
||||
fOffsets[i] = 0; // Starting offset
|
||||
@ -131,12 +132,11 @@ MessageFormat::MessageFormat(const UnicodeString& pattern,
|
||||
UErrorCode& success)
|
||||
: fLocale(newLocale), // Uses the default locale
|
||||
fOffsets(NULL),
|
||||
fCount(0),
|
||||
fCount(kMaxFormat),
|
||||
fArgumentNumbers(NULL)
|
||||
{
|
||||
fCount = kMaxFormat;
|
||||
fOffsets = new int32_t[fCount];
|
||||
fArgumentNumbers = new int32_t[fCount];
|
||||
fOffsets = (int32_t*) uprv_malloc( sizeof(int32_t) * fCount );
|
||||
fArgumentNumbers = (int32_t*) uprv_malloc( sizeof(int32_t) * fCount );
|
||||
for (int32_t i = 0; i < fCount; i++) {
|
||||
fFormats[i] = NULL; // Format instances
|
||||
fOffsets[i] = 0; // Starting offset
|
||||
@ -151,12 +151,11 @@ MessageFormat::MessageFormat(const UnicodeString& pattern,
|
||||
UErrorCode& success)
|
||||
: fLocale(newLocale), // Uses the default locale
|
||||
fOffsets(NULL),
|
||||
fCount(0),
|
||||
fCount(kMaxFormat),
|
||||
fArgumentNumbers(NULL)
|
||||
{
|
||||
fCount = kMaxFormat;
|
||||
fOffsets = new int32_t[fCount];
|
||||
fArgumentNumbers = new int32_t[fCount];
|
||||
fOffsets = (int32_t*) uprv_malloc( sizeof(int32_t) * fCount );
|
||||
fArgumentNumbers = (int32_t*) uprv_malloc( sizeof(int32_t) * fCount );
|
||||
for (int32_t i = 0; i < fCount; i++) {
|
||||
fFormats[i] = NULL; // Format instances
|
||||
fOffsets[i] = 0; // Starting offset
|
||||
@ -172,8 +171,8 @@ MessageFormat::~MessageFormat()
|
||||
delete fFormats[i];
|
||||
}
|
||||
}
|
||||
delete [] fOffsets;
|
||||
delete [] fArgumentNumbers;
|
||||
uprv_free(fOffsets);
|
||||
uprv_free(fArgumentNumbers);
|
||||
fCount = 0;
|
||||
}
|
||||
|
||||
@ -214,14 +213,16 @@ MessageFormat::operator=(const MessageFormat& that)
|
||||
delete fFormats[j];
|
||||
fFormats[j] = NULL;
|
||||
}
|
||||
delete [] fOffsets; fOffsets = NULL;
|
||||
delete [] fArgumentNumbers; fArgumentNumbers = NULL;
|
||||
uprv_free(fOffsets);
|
||||
fOffsets = NULL;
|
||||
uprv_free(fArgumentNumbers);
|
||||
fArgumentNumbers = NULL;
|
||||
fPattern = that.fPattern;
|
||||
fLocale = that.fLocale;
|
||||
fCount = that.fCount;
|
||||
fMaxOffset = that.fMaxOffset;
|
||||
fOffsets = new int32_t[fCount];
|
||||
fArgumentNumbers = new int32_t[fCount];
|
||||
fOffsets = (int32_t*) uprv_malloc( sizeof(int32_t) * fCount );
|
||||
fArgumentNumbers = (int32_t*) uprv_malloc( sizeof(int32_t) * fCount );
|
||||
// Sets up the format instance array, offsets and argument numbers.
|
||||
for (int32_t i = 0; i < fCount; i++) {
|
||||
if (that.fFormats[i] == NULL) {
|
||||
|
@ -136,8 +136,8 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos
|
||||
|
||||
UChar32 ch;
|
||||
|
||||
u_UCharsToChars(buf, cbuf, ibuf+1);
|
||||
ch = u_charFromName(U_EXTENDED_CHAR_NAME, cbuf, &status);
|
||||
u_UCharsToChars(buf, cbuf, ibuf+1);
|
||||
ch = u_charFromName(U_EXTENDED_CHAR_NAME, cbuf, &status);
|
||||
if (U_SUCCESS(status)) {
|
||||
// Lookup succeeded
|
||||
str.truncate(0);
|
||||
|
@ -35,7 +35,7 @@ util_lcm(llong x, llong y)
|
||||
{
|
||||
x.abs();
|
||||
y.abs();
|
||||
|
||||
|
||||
if (x == 0 || y == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
@ -45,7 +45,7 @@ util_lcm(llong x, llong y)
|
||||
}
|
||||
x -= y * (x/y);
|
||||
} while (x != 0);
|
||||
|
||||
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@ -54,28 +54,28 @@ util_lcm(llong x, llong y)
|
||||
/**
|
||||
* Calculates the least common multiple of x and y.
|
||||
*/
|
||||
static llong
|
||||
util_lcm(llong x, llong y)
|
||||
static llong
|
||||
util_lcm(llong x, llong y)
|
||||
{
|
||||
// binary gcd algorithm from Knuth, "The Art of Computer Programming,"
|
||||
// vol. 2, 1st ed., pp. 298-299
|
||||
llong x1 = x;
|
||||
llong y1 = y;
|
||||
|
||||
|
||||
int p2 = 0;
|
||||
while ((x1 & 1) == 0 && (y1 & 1) == 0) {
|
||||
++p2;
|
||||
x1 >>= 1;
|
||||
y1 >>= 1;
|
||||
}
|
||||
|
||||
|
||||
llong t;
|
||||
if ((x1 & 1) == 1) {
|
||||
t = -y1;
|
||||
} else {
|
||||
t = x1;
|
||||
}
|
||||
|
||||
|
||||
while (t != 0) {
|
||||
while ((t & 1) == 0) {
|
||||
t >>= 1;
|
||||
@ -87,9 +87,9 @@ util_lcm(llong x, llong y)
|
||||
}
|
||||
t = x1 - y1;
|
||||
}
|
||||
|
||||
|
||||
llong gcd = x1 << p2;
|
||||
|
||||
|
||||
// x * y == gcd(x, y) * lcm(x, y)
|
||||
return x / gcd * y;
|
||||
}
|
||||
@ -104,7 +104,7 @@ static const UChar gFourSpaces[] =
|
||||
{
|
||||
0x20, 0x20, 0x20, 0x20, 0
|
||||
}; /* " " */
|
||||
static const UChar gPercentPercent[] =
|
||||
static const UChar gPercentPercent[] =
|
||||
{
|
||||
0x25, 0x25, 0
|
||||
}; /* "%%" */
|
||||
@ -119,13 +119,13 @@ NFRuleSet::NFRuleSet(UnicodeString* descriptions, int32_t index, UErrorCode& sta
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
fractionRules[i] = NULL;
|
||||
}
|
||||
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
UnicodeString& description = descriptions[index]; // !!! make sure index is valid
|
||||
|
||||
|
||||
// if the description begins with a rule set name (the rule set
|
||||
// name can be omitted in formatter descriptions that consist
|
||||
// of only one rule set), copy it out into our "name" member
|
||||
@ -144,33 +144,33 @@ NFRuleSet::NFRuleSet(UnicodeString* descriptions, int32_t index, UErrorCode& sta
|
||||
} else {
|
||||
name.setTo("%default");
|
||||
}
|
||||
|
||||
|
||||
if (description.length() == 0) {
|
||||
// throw new IllegalArgumentException("Empty rule set description");
|
||||
status = U_PARSE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
fIsPublic = name.indexOf(gPercentPercent) != 0;
|
||||
|
||||
|
||||
// all of the other members of NFRuleSet are initialized
|
||||
// by parseRules()
|
||||
}
|
||||
|
||||
void
|
||||
NFRuleSet::parseRules(UnicodeString& description, const RuleBasedNumberFormat* owner, UErrorCode& status)
|
||||
void
|
||||
NFRuleSet::parseRules(UnicodeString& description, const RuleBasedNumberFormat* owner, UErrorCode& status)
|
||||
{
|
||||
// start by creating a Vector whose elements are Strings containing
|
||||
// the descriptions of the rules (one rule per element). The rules
|
||||
// are separated by semicolons (there's no escape facility: ALL
|
||||
// semicolons are rule delimiters)
|
||||
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// dlf - the original code kept a separate description array for no reason,
|
||||
// so I got rid of it. The loop was too complex so I simplified it.
|
||||
|
||||
|
||||
UnicodeString currentDescription;
|
||||
UTextOffset oldP = 0;
|
||||
while (oldP < description.length()) {
|
||||
@ -182,20 +182,20 @@ NFRuleSet::parseRules(UnicodeString& description, const RuleBasedNumberFormat* o
|
||||
NFRule::makeRules(currentDescription, this, rules.last(), owner, rules, status);
|
||||
oldP = p + 1;
|
||||
}
|
||||
|
||||
|
||||
// for rules that didn't specify a base value, their base values
|
||||
// were initialized to 0. Make another pass through the list and
|
||||
// set all those rules' base values. We also remove any special
|
||||
// rules from the list and put them into their own member variables
|
||||
llong defaultBaseValue = (int32_t)0;
|
||||
|
||||
|
||||
// (this isn't a for loop because we might be deleting items from
|
||||
// the vector-- we want to make sure we only increment i when
|
||||
// we _didn't_ delete aything from the vector)
|
||||
uint32_t i = 0;
|
||||
while (i < rules.size()) {
|
||||
NFRule* rule = rules[i];
|
||||
|
||||
|
||||
switch (rule->getType()) {
|
||||
// if the rule's base value is 0, fill in a default
|
||||
// base value (this will be 1 plus the preceding
|
||||
@ -209,31 +209,31 @@ NFRuleSet::parseRules(UnicodeString& description, const RuleBasedNumberFormat* o
|
||||
}
|
||||
++i;
|
||||
break;
|
||||
|
||||
|
||||
// if it's the negative-number rule, copy it into its own
|
||||
// data member and delete it from the list
|
||||
case NFRule::kNegativeNumberRule:
|
||||
negativeNumberRule = rules.remove(i);
|
||||
break;
|
||||
|
||||
|
||||
// if it's the improper fraction rule, copy it into the
|
||||
// correct element of fractionRules
|
||||
case NFRule::kImproperFractionRule:
|
||||
fractionRules[0] = rules.remove(i);
|
||||
break;
|
||||
|
||||
|
||||
// if it's the proper fraction rule, copy it into the
|
||||
// correct element of fractionRules
|
||||
case NFRule::kProperFractionRule:
|
||||
fractionRules[1] = rules.remove(i);
|
||||
break;
|
||||
|
||||
|
||||
// if it's the master rule, copy it into the
|
||||
// correct element of fractionRules
|
||||
case NFRule::kMasterRule:
|
||||
fractionRules[2] = rules.remove(i);
|
||||
break;
|
||||
|
||||
|
||||
// if it's a regular rule that already knows its base value,
|
||||
// check to make sure the rules are in order, and update
|
||||
// the default base value for the next rule
|
||||
@ -261,20 +261,20 @@ NFRuleSet::~NFRuleSet()
|
||||
delete fractionRules[2];
|
||||
}
|
||||
|
||||
UBool
|
||||
util_equalRules(const NFRule* rule1, const NFRule* rule2)
|
||||
UBool
|
||||
util_equalRules(const NFRule* rule1, const NFRule* rule2)
|
||||
{
|
||||
if (rule1) {
|
||||
if (rule2) {
|
||||
return *rule1 == *rule2;
|
||||
}
|
||||
}
|
||||
} else if (!rule2) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UBool
|
||||
UBool
|
||||
NFRuleSet::operator==(const NFRuleSet& rhs) const
|
||||
{
|
||||
if (rules.size() == rhs.rules.size() &&
|
||||
@ -284,7 +284,7 @@ NFRuleSet::operator==(const NFRuleSet& rhs) const
|
||||
util_equalRules(fractionRules[0], rhs.fractionRules[0]) &&
|
||||
util_equalRules(fractionRules[1], rhs.fractionRules[1]) &&
|
||||
util_equalRules(fractionRules[2], rhs.fractionRules[2])) {
|
||||
|
||||
|
||||
for (uint32_t i = 0; i < rules.size(); ++i) {
|
||||
if (*rules[i] != *rhs.rules[i]) {
|
||||
return FALSE;
|
||||
@ -295,28 +295,28 @@ NFRuleSet::operator==(const NFRuleSet& rhs) const
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
NFRuleSet::format(llong number, UnicodeString& toAppendTo, int32_t pos) const
|
||||
{
|
||||
NFRule *rule = findNormalRule(number);
|
||||
rule->doFormat(number, toAppendTo, pos);
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
NFRuleSet::format(double number, UnicodeString& toAppendTo, int32_t pos) const
|
||||
{
|
||||
NFRule *rule = findDoubleRule(number);
|
||||
rule->doFormat(number, toAppendTo, pos);
|
||||
}
|
||||
|
||||
NFRule*
|
||||
NFRule*
|
||||
NFRuleSet::findDoubleRule(double number) const
|
||||
{
|
||||
// if this is a fraction rule set, use findFractionRuleSetRule()
|
||||
if (isFractionRuleSet()) {
|
||||
return findFractionRuleSetRule(number);
|
||||
}
|
||||
|
||||
|
||||
// if the number is negative, return the negative number rule
|
||||
// (if there isn't a negative-number rule, we pretend it's a
|
||||
// positive number)
|
||||
@ -327,25 +327,25 @@ NFRuleSet::findDoubleRule(double number) const
|
||||
number = -number;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if the number isn't an integer, we use one of the fraction rules...
|
||||
if (number != uprv_floor(number)) {
|
||||
// if the number is between 0 and 1, return the proper
|
||||
// fraction rule
|
||||
if (number < 1 && fractionRules[1]) {
|
||||
return fractionRules[1];
|
||||
}
|
||||
}
|
||||
// otherwise, return the improper fraction rule
|
||||
else if (fractionRules[0]) {
|
||||
return fractionRules[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if there's a master rule, use it to format the number
|
||||
if (fractionRules[2]) {
|
||||
return fractionRules[2];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// and if we haven't yet returned a rule, use findNormalRule()
|
||||
// to find the applicable rule
|
||||
llong r = number + 0.5;
|
||||
@ -353,7 +353,7 @@ NFRuleSet::findDoubleRule(double number) const
|
||||
}
|
||||
|
||||
NFRule *
|
||||
NFRuleSet::findNormalRule(llong number) const
|
||||
NFRuleSet::findNormalRule(llong number) const
|
||||
{
|
||||
// if this is a fraction rule set, use findFractionRuleSetRule()
|
||||
// to find the rule (we should only go into this clause if the
|
||||
@ -361,7 +361,7 @@ NFRuleSet::findNormalRule(llong number) const
|
||||
if (fIsFractionRuleSet) {
|
||||
return findFractionRuleSetRule(number.asDouble());
|
||||
}
|
||||
|
||||
|
||||
// if the number is negative, return the negative-number rule
|
||||
// (if there isn't one, pretend the number is positive)
|
||||
if (number < 0) {
|
||||
@ -371,7 +371,7 @@ NFRuleSet::findNormalRule(llong number) const
|
||||
number = -number;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// we have to repeat the preceding two checks, even though we
|
||||
// do them in findRule(), because the version of format() that
|
||||
// takes a long bypasses findRule() and goes straight to this
|
||||
@ -380,43 +380,43 @@ NFRuleSet::findNormalRule(llong number) const
|
||||
// rule, since it's considered a fraction rule. Skipping the
|
||||
// master rule in this function is also how we avoid infinite
|
||||
// recursion)
|
||||
|
||||
// {dlf} unfortunately this fails if there are no rules except
|
||||
// special rules. If there are no rules, use the master rule.
|
||||
|
||||
// {dlf} unfortunately this fails if there are no rules except
|
||||
// special rules. If there are no rules, use the master rule.
|
||||
|
||||
// binary-search the rule list for the applicable rule
|
||||
// (a rule is used for all values from its base value to
|
||||
// the next rule's base value)
|
||||
int32_t hi = rules.size();
|
||||
if (hi > 0) {
|
||||
int32_t lo = 0;
|
||||
|
||||
while (lo < hi) {
|
||||
int32_t mid = (lo + hi) / 2;
|
||||
if (rules[mid]->getBaseValue() == number) {
|
||||
return rules[mid];
|
||||
}
|
||||
else if (rules[mid]->getBaseValue() > number) {
|
||||
hi = mid;
|
||||
}
|
||||
else {
|
||||
lo = mid + 1;
|
||||
}
|
||||
}
|
||||
NFRule *result = rules[hi - 1];
|
||||
|
||||
// use shouldRollBack() to see whether we need to invoke the
|
||||
// rollback rule (see shouldRollBack()'s documentation for
|
||||
// an explanation of the rollback rule). If we do, roll back
|
||||
// one rule and return that one instead of the one we'd normally
|
||||
// return
|
||||
if (result->shouldRollBack(number.asDouble())) {
|
||||
result = rules[hi - 2];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// else use the master rule
|
||||
return fractionRules[2];
|
||||
if (hi > 0) {
|
||||
int32_t lo = 0;
|
||||
|
||||
while (lo < hi) {
|
||||
int32_t mid = (lo + hi) / 2;
|
||||
if (rules[mid]->getBaseValue() == number) {
|
||||
return rules[mid];
|
||||
}
|
||||
else if (rules[mid]->getBaseValue() > number) {
|
||||
hi = mid;
|
||||
}
|
||||
else {
|
||||
lo = mid + 1;
|
||||
}
|
||||
}
|
||||
NFRule *result = rules[hi - 1];
|
||||
|
||||
// use shouldRollBack() to see whether we need to invoke the
|
||||
// rollback rule (see shouldRollBack()'s documentation for
|
||||
// an explanation of the rollback rule). If we do, roll back
|
||||
// one rule and return that one instead of the one we'd normally
|
||||
// return
|
||||
if (result->shouldRollBack(number.asDouble())) {
|
||||
result = rules[hi - 2];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// else use the master rule
|
||||
return fractionRules[2];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -435,13 +435,13 @@ NFRuleSet::findNormalRule(llong number) const
|
||||
* @return The rule to use to format this number
|
||||
*/
|
||||
NFRule*
|
||||
NFRuleSet::findFractionRuleSetRule(double number) const
|
||||
NFRuleSet::findFractionRuleSetRule(double number) const
|
||||
{
|
||||
// the obvious way to do this (multiply the value being formatted
|
||||
// by each rule's base value until you get an integral result)
|
||||
// doesn't work because of rounding error. This method is more
|
||||
// accurate
|
||||
|
||||
|
||||
// find the least common multiple of the rules' base values
|
||||
// and multiply this by the number being formatted. This is
|
||||
// all the precision we need, and we can do all of the rest
|
||||
@ -459,22 +459,22 @@ NFRuleSet::findFractionRuleSetRule(double number) const
|
||||
llong difference(uprv_maxMantissa());
|
||||
int32_t winner = 0;
|
||||
for (uint32_t i = 0; i < rules.size(); ++i) {
|
||||
// "numerator" is the numerator of the fraction if the
|
||||
// "numerator" is the numerator of the fraction if the
|
||||
// denominator is the LCD. The numerator if the rule's
|
||||
// base value is the denominator is "numerator" times the
|
||||
// base value divided bythe LCD. Here we check to see if
|
||||
// that's an integer, and if not, how close it is to being
|
||||
// an integer.
|
||||
tempDifference = numerator * rules[i]->getBaseValue() % leastCommonMultiple;
|
||||
|
||||
|
||||
|
||||
|
||||
// normalize the result of the above calculation: we want
|
||||
// the numerator's distance from the CLOSEST multiple
|
||||
// of the LCD
|
||||
if (leastCommonMultiple - tempDifference < tempDifference) {
|
||||
tempDifference = leastCommonMultiple - tempDifference;
|
||||
}
|
||||
|
||||
|
||||
// if this is as close as we've come, keep track of how close
|
||||
// that is, and the line number of the rule that did it. If
|
||||
// we've scored a direct hit, we don't have to look at any more
|
||||
@ -487,7 +487,7 @@ NFRuleSet::findFractionRuleSetRule(double number) const
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if we have two successive rules that both have the winning base
|
||||
// value, then the first one (the one we found above) is used if
|
||||
// the numerator of the fraction is 1 and the second one is used if
|
||||
@ -501,7 +501,7 @@ NFRuleSet::findFractionRuleSetRule(double number) const
|
||||
++winner;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// finally, return the winning rule
|
||||
return rules[winner];
|
||||
}
|
||||
@ -546,17 +546,17 @@ NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBoun
|
||||
// try matching each rule in the rule set against the text being
|
||||
// parsed. Whichever one matches the most characters is the one
|
||||
// that determines the value we return.
|
||||
|
||||
|
||||
result.setLong(0);
|
||||
|
||||
|
||||
// dump out if there's no text to parse
|
||||
if (text.length() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ParsePosition highWaterMark;
|
||||
ParsePosition workingPos = pos;
|
||||
|
||||
|
||||
#ifdef RBNF_DEBUG
|
||||
fprintf(stderr, "<nfrs> %x '", this);
|
||||
dumpUS(stderr, name);
|
||||
@ -565,7 +565,7 @@ NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBoun
|
||||
fprintf(stderr, "'\n");
|
||||
fprintf(stderr, " parse negative: %d\n", this, negativeNumberRule != 0);
|
||||
#endif
|
||||
|
||||
|
||||
// start by trying the negative number rule (if there is one)
|
||||
if (negativeNumberRule) {
|
||||
Formattable tempResult;
|
||||
@ -606,7 +606,7 @@ NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBoun
|
||||
dumpUS(stderr, text);
|
||||
fprintf(stderr, "' hwm: %d\n", highWaterMark.getIndex());
|
||||
#endif
|
||||
|
||||
|
||||
// finally, go through the regular rules one at a time. We start
|
||||
// at the end of the list because we want to try matching the most
|
||||
// sigificant rule first (this helps ensure that we parse
|
||||
@ -645,32 +645,32 @@ NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBoun
|
||||
// first character we didn't use, and return the result that
|
||||
// corresponds to that string of characters
|
||||
pos = highWaterMark;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
NFRuleSet::appendRules(UnicodeString& result) const
|
||||
{
|
||||
// the rule set name goes first...
|
||||
result.append(name);
|
||||
result.append(gColon);
|
||||
result.append(gLineFeed);
|
||||
|
||||
|
||||
// followed by the regular rules...
|
||||
for (uint32_t i = 0; i < rules.size(); i++) {
|
||||
result.append(gFourSpaces);
|
||||
rules[i]->appendRuleText(result);
|
||||
result.append(gLineFeed);
|
||||
}
|
||||
|
||||
|
||||
// followed by the special rules (if they exist)
|
||||
if (negativeNumberRule) {
|
||||
result.append(gFourSpaces);
|
||||
negativeNumberRule->appendRuleText(result);
|
||||
result.append(gLineFeed);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
for (uint32_t i = 0; i < 3; ++i) {
|
||||
if (fractionRules[i]) {
|
||||
|
@ -84,13 +84,13 @@ static const UChar * const tokenStrings[] = {
|
||||
gEqualPercent, gEqualHash, gEqualZero, NULL
|
||||
};
|
||||
|
||||
void
|
||||
void
|
||||
NFRule::makeRules(UnicodeString& description,
|
||||
const NFRuleSet *ruleSet,
|
||||
const NFRule *predecessor,
|
||||
const RuleBasedNumberFormat *rbnf,
|
||||
NFRuleList& rules,
|
||||
UErrorCode& status)
|
||||
UErrorCode& status)
|
||||
{
|
||||
// we know we're making at least one rule, so go ahead and
|
||||
// new it up and initialize its basevalue and divisor
|
||||
@ -127,7 +127,7 @@ NFRule::makeRules(UnicodeString& description,
|
||||
&& (rule1->baseValue % ((llong)rule1->radix).pow((int32_t)rule1->exponent)) == 0)
|
||||
|| rule1->getType() == kImproperFractionRule
|
||||
|| rule1->getType() == kMasterRule) {
|
||||
|
||||
|
||||
// if it passes that test, new up the second rule. If the
|
||||
// rule set both rules will belong to is a fraction rule
|
||||
// set, they both have the same base value; otherwise,
|
||||
@ -206,7 +206,7 @@ NFRule::makeRules(UnicodeString& description,
|
||||
* "description" with the descriptor and any trailing whitespace
|
||||
* stripped off. Otherwise; it's "descriptor" unchangd.
|
||||
*/
|
||||
void
|
||||
void
|
||||
NFRule::parseRuleDescriptor(UnicodeString& description, UErrorCode& status)
|
||||
{
|
||||
// the description consists of a rule descriptor and a rule body,
|
||||
@ -312,7 +312,7 @@ NFRule::parseRuleDescriptor(UnicodeString& description, UErrorCode& status)
|
||||
// throw new IllegalArgumentException("Rule can't have radix of 0");
|
||||
status = U_PARSE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
exponent = expectedExponent();
|
||||
}
|
||||
|
||||
@ -357,7 +357,7 @@ NFRule::parseRuleDescriptor(UnicodeString& description, UErrorCode& status)
|
||||
* @param predecessor The rule preseding this one in "owners" rule list
|
||||
* @param ownersOwner The RuleBasedFormat that owns this rule
|
||||
*/
|
||||
void
|
||||
void
|
||||
NFRule::extractSubstitutions(const NFRuleSet* ruleSet,
|
||||
const NFRule* predecessor,
|
||||
const RuleBasedNumberFormat* rbnf,
|
||||
@ -405,7 +405,7 @@ NFRule::extractSubstitution(const NFRuleSet* ruleSet,
|
||||
// end will actually find the > in the middle
|
||||
if (ruleText.indexOf(gGreaterGreaterGreater) == subStart) {
|
||||
subEnd = subStart + 2;
|
||||
|
||||
|
||||
// otherwise the substitution token ends with the same character
|
||||
// it began with
|
||||
} else {
|
||||
@ -441,8 +441,8 @@ NFRule::extractSubstitution(const NFRuleSet* ruleSet,
|
||||
* constructed. It should be used at any other time.
|
||||
* @param The new base value for the rule.
|
||||
*/
|
||||
void
|
||||
NFRule::setBaseValue(llong newBaseValue)
|
||||
void
|
||||
NFRule::setBaseValue(llong newBaseValue)
|
||||
{
|
||||
// set the base value
|
||||
baseValue = newBaseValue;
|
||||
@ -480,8 +480,8 @@ NFRule::setBaseValue(llong newBaseValue)
|
||||
* value. This will be the highest power the radix can be raised to
|
||||
* and still produce a result less than or equal to the base value.
|
||||
*/
|
||||
int16_t
|
||||
NFRule::expectedExponent() const
|
||||
int16_t
|
||||
NFRule::expectedExponent() const
|
||||
{
|
||||
// since the log of 0, or the log base 0 of something, causes an
|
||||
// error, declare the exponent in these cases to be 0 (we also
|
||||
@ -510,7 +510,7 @@ NFRule::expectedExponent() const
|
||||
* _any_ of the strings in "strings"). If none of the strings in
|
||||
* "strings" is found in the rule's rule text, returns -1.
|
||||
*/
|
||||
int32_t
|
||||
int32_t
|
||||
NFRule::indexOfAny(const UChar* const strings[]) const
|
||||
{
|
||||
int result = -1;
|
||||
@ -545,10 +545,10 @@ NFRule::operator==(const NFRule& rhs) const
|
||||
|
||||
/*
|
||||
static void
|
||||
util_append_llong(UnicodeString& result, const llong& value)
|
||||
util_append_llong(UnicodeString& result, const llong& value)
|
||||
{
|
||||
llong n(value);
|
||||
|
||||
|
||||
if (n < 0) {
|
||||
result.append(gMinus);
|
||||
n = -n;
|
||||
@ -647,7 +647,7 @@ NFRule::appendRuleText(UnicodeString& result) const
|
||||
* @param pos The position in toInsertInto where the resultant text
|
||||
* should be inserted
|
||||
*/
|
||||
void
|
||||
void
|
||||
NFRule::doFormat(const llong &number, UnicodeString& toInsertInto, int32_t pos) const
|
||||
{
|
||||
// first, insert the rule's rule text into toInsertInto at the
|
||||
@ -669,7 +669,7 @@ NFRule::doFormat(const llong &number, UnicodeString& toInsertInto, int32_t pos)
|
||||
* @param pos The position in toInsertInto where the resultant text
|
||||
* should be inserted
|
||||
*/
|
||||
void
|
||||
void
|
||||
NFRule::doFormat(double number, UnicodeString& toInsertInto, int32_t pos) const
|
||||
{
|
||||
// first, insert the rule's rule text into toInsertInto at the
|
||||
@ -691,7 +691,7 @@ NFRule::doFormat(double number, UnicodeString& toInsertInto, int32_t pos) const
|
||||
* @return True if the rule set should use the rule that precedes
|
||||
* this one in its list; false if it should use this rule
|
||||
*/
|
||||
UBool
|
||||
UBool
|
||||
NFRule::shouldRollBack(double number) const
|
||||
{
|
||||
// we roll back if the rule contains a modulus substitution,
|
||||
@ -754,7 +754,7 @@ static void dumpUS(FILE* f, const UnicodeString& us) {
|
||||
|
||||
UBool
|
||||
NFRule::doParse(const UnicodeString& text,
|
||||
ParsePosition& parsePosition,
|
||||
ParsePosition& parsePosition,
|
||||
UBool isFractionRule,
|
||||
double upperBound,
|
||||
Formattable& resVal) const
|
||||
@ -763,14 +763,14 @@ NFRule::doParse(const UnicodeString& text,
|
||||
// (because we're going to change it) and use our own ParsePosition
|
||||
ParsePosition pp;
|
||||
UnicodeString workText(text);
|
||||
|
||||
|
||||
// check to see whether the text before the first substitution
|
||||
// matches the text at the beginning of the string being
|
||||
// parsed. If it does, strip that off the front of workText;
|
||||
// otherwise, dump out with a mismatch
|
||||
UnicodeString prefix;
|
||||
prefix.setTo(ruleText, 0, sub1->getPos());
|
||||
|
||||
|
||||
#ifdef RBNF_DEBUG
|
||||
fprintf(stderr, "doParse %x ", this);
|
||||
{
|
||||
@ -778,7 +778,7 @@ NFRule::doParse(const UnicodeString& text,
|
||||
appendRuleText(rt);
|
||||
dumpUS(stderr, rt);
|
||||
}
|
||||
|
||||
|
||||
fprintf(stderr, " text: '", this);
|
||||
dumpUS(stderr, text);
|
||||
fprintf(stderr, "' prefix: '");
|
||||
@ -786,11 +786,11 @@ NFRule::doParse(const UnicodeString& text,
|
||||
#endif
|
||||
stripPrefix(workText, prefix, pp);
|
||||
int32_t prefixLength = text.length() - workText.length();
|
||||
|
||||
|
||||
#ifdef RBNF_DEBUG
|
||||
fprintf(stderr, "' pl: %d ppi: %d s1p: %d\n", prefixLength, pp.getIndex(), sub1->getPos());
|
||||
#endif
|
||||
|
||||
|
||||
if (pp.getIndex() == 0 && sub1->getPos() != 0) {
|
||||
// commented out because ParsePosition doesn't have error index in 1.1.x
|
||||
// restored for ICU4C port
|
||||
@ -798,7 +798,7 @@ NFRule::doParse(const UnicodeString& text,
|
||||
resVal.setLong(0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// this is the fun part. The basic guts of the rule-matching
|
||||
// logic is matchToDelimiter(), which is called twice. The first
|
||||
// time it searches the input string for the rule text BETWEEN
|
||||
@ -832,7 +832,7 @@ NFRule::doParse(const UnicodeString& text,
|
||||
double result = 0;
|
||||
int start = 0;
|
||||
double tempBaseValue = (baseValue <= 0) ? 0 : baseValue.asDouble();
|
||||
|
||||
|
||||
UnicodeString temp;
|
||||
do {
|
||||
// our partial parse result starts out as this rule's base
|
||||
@ -840,23 +840,23 @@ NFRule::doParse(const UnicodeString& text,
|
||||
// will compose this in some way with what it gets back from
|
||||
// the substitution, giving us a new partial parse result
|
||||
pp.setIndex(0);
|
||||
|
||||
|
||||
temp.setTo(ruleText, sub1->getPos(), sub2->getPos() - sub1->getPos());
|
||||
double partialResult = matchToDelimiter(workText, start, tempBaseValue,
|
||||
temp, pp, sub1,
|
||||
upperBound);
|
||||
|
||||
|
||||
// if we got a successful match (or were trying to match a
|
||||
// null substitution), pp is now pointing at the first unmatched
|
||||
// character. Take note of that, and try matchToDelimiter()
|
||||
// on the input text again
|
||||
if (pp.getIndex() != 0 || sub1->isNullSubstitution()) {
|
||||
start = pp.getIndex();
|
||||
|
||||
|
||||
UnicodeString workText2;
|
||||
workText2.setTo(workText, pp.getIndex(), workText.length() - pp.getIndex());
|
||||
ParsePosition pp2;
|
||||
|
||||
|
||||
// the second matchToDelimiter() will compose our previous
|
||||
// partial result with whatever it gets back from its
|
||||
// substitution if there's a successful match, giving us
|
||||
@ -865,7 +865,7 @@ NFRule::doParse(const UnicodeString& text,
|
||||
partialResult = matchToDelimiter(workText2, 0, partialResult,
|
||||
temp, pp2, sub2,
|
||||
upperBound);
|
||||
|
||||
|
||||
// if we got a successful match on this second
|
||||
// matchToDelimiter() call, update the high-water mark
|
||||
// and result (if necessary)
|
||||
@ -895,11 +895,11 @@ NFRule::doParse(const UnicodeString& text,
|
||||
// keep trying to match things until the outer matchToDelimiter()
|
||||
// call fails to make a match (each time, it picks up where it
|
||||
// left off the previous time)
|
||||
} while (sub1->getPos() != sub2->getPos()
|
||||
&& pp.getIndex() > 0
|
||||
&& pp.getIndex() < workText.length()
|
||||
} while (sub1->getPos() != sub2->getPos()
|
||||
&& pp.getIndex() > 0
|
||||
&& pp.getIndex() < workText.length()
|
||||
&& pp.getIndex() != start);
|
||||
|
||||
|
||||
// update the caller's ParsePosition with our high-water mark
|
||||
// (i.e., it now points at the first character this function
|
||||
// didn't match-- the ParsePosition is therefore unchanged if
|
||||
@ -910,19 +910,19 @@ NFRule::doParse(const UnicodeString& text,
|
||||
if (highWaterMark > 0) {
|
||||
parsePosition.setErrorIndex(0);
|
||||
}
|
||||
|
||||
|
||||
// this is a hack for one unusual condition: Normally, whether this
|
||||
// rule belong to a fraction rule set or not is handled by its
|
||||
// substitutions. But if that rule HAS NO substitutions, then
|
||||
// we have to account for it here. By definition, if the matching
|
||||
// rule in a fraction rule set has no substitutions, its numerator
|
||||
// is 1, and so the result is the reciprocal of its base value.
|
||||
if (isFractionRule &&
|
||||
highWaterMark > 0 &&
|
||||
if (isFractionRule &&
|
||||
highWaterMark > 0 &&
|
||||
sub1->isNullSubstitution()) {
|
||||
result = 1 / result;
|
||||
}
|
||||
|
||||
|
||||
resVal.setDouble(result);
|
||||
return TRUE; // ??? do we need to worry if it is a long or a double?
|
||||
}
|
||||
@ -943,7 +943,7 @@ NFRule::doParse(const UnicodeString& text,
|
||||
* @return If things match, this is the unparsed part of "text";
|
||||
* if they didn't match, this is "text".
|
||||
*/
|
||||
void
|
||||
void
|
||||
NFRule::stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const
|
||||
{
|
||||
// if the prefix text is empty, dump out without doing anything
|
||||
@ -992,13 +992,13 @@ NFRule::stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosit
|
||||
* the result to a double, so we might as well return one.
|
||||
*/
|
||||
double
|
||||
NFRule::matchToDelimiter(const UnicodeString& text,
|
||||
int32_t startPos,
|
||||
NFRule::matchToDelimiter(const UnicodeString& text,
|
||||
int32_t startPos,
|
||||
double _baseValue,
|
||||
const UnicodeString& delimiter,
|
||||
ParsePosition& pp,
|
||||
const NFSubstitution* sub,
|
||||
double upperBound) const
|
||||
const UnicodeString& delimiter,
|
||||
ParsePosition& pp,
|
||||
const NFSubstitution* sub,
|
||||
double upperBound) const
|
||||
{
|
||||
// if "delimiter" contains real (i.e., non-ignorable) text, search
|
||||
// it for "delimiter" beginning at "start". If that succeeds, then
|
||||
@ -1007,14 +1007,14 @@ NFRule::matchToDelimiter(const UnicodeString& text,
|
||||
if (!allIgnorable(delimiter)) {
|
||||
ParsePosition tempPP;
|
||||
Formattable result;
|
||||
|
||||
|
||||
// use findText() to search for "delimiter". It returns a two-
|
||||
// element array: element 0 is the position of the match, and
|
||||
// element 1 is the number of characters that matched
|
||||
// "delimiter".
|
||||
int32_t dLen;
|
||||
int32_t dPos = findText(text, delimiter, startPos, &dLen);
|
||||
|
||||
|
||||
// if findText() succeeded, isolate the text preceding the
|
||||
// match, and use "sub" to match that text
|
||||
while (dPos >= 0) {
|
||||
@ -1023,7 +1023,7 @@ NFRule::matchToDelimiter(const UnicodeString& text,
|
||||
if (subText.length() > 0) {
|
||||
UBool success = sub->doParse(subText, tempPP, _baseValue, upperBound,
|
||||
formatter->isLenient(), result);
|
||||
|
||||
|
||||
// if the substitution could match all the text up to
|
||||
// where we found "delimiter", then this function has
|
||||
// a successful match. Bump the caller's parse position
|
||||
@ -1044,7 +1044,7 @@ NFRule::matchToDelimiter(const UnicodeString& text,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if we didn't match the substitution, search for another
|
||||
// copy of "delimiter" in "text" and repeat the loop if
|
||||
// we find it
|
||||
@ -1055,7 +1055,7 @@ NFRule::matchToDelimiter(const UnicodeString& text,
|
||||
// leave pp unchanged and return 0
|
||||
pp.setIndex(0);
|
||||
return 0;
|
||||
|
||||
|
||||
// if "delimiter" is empty, or consists only of ignorable characters
|
||||
// (i.e., is semantically empty), thwe we obviously can't search
|
||||
// for "delimiter". Instead, just use "sub" to parse as much of
|
||||
@ -1063,7 +1063,7 @@ NFRule::matchToDelimiter(const UnicodeString& text,
|
||||
} else {
|
||||
ParsePosition tempPP;
|
||||
Formattable result;
|
||||
|
||||
|
||||
// try to match the whole string against the substitution
|
||||
UBool success = sub->doParse(text, tempPP, _baseValue, upperBound,
|
||||
formatter->isLenient(), result);
|
||||
@ -1080,7 +1080,7 @@ NFRule::matchToDelimiter(const UnicodeString& text,
|
||||
else {
|
||||
pp.setErrorIndex(tempPP.getErrorIndex());
|
||||
}
|
||||
|
||||
|
||||
// and if we get to here, then nothing matched, so we return
|
||||
// 0 and leave pp alone
|
||||
return 0;
|
||||
@ -1109,7 +1109,7 @@ NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix) cons
|
||||
if (prefix.length() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// go through all this grief if we're in lenient-parse mode
|
||||
if (formatter->isLenient()) {
|
||||
// get the formatter's collator and use it to create two
|
||||
@ -1122,46 +1122,46 @@ NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix) cons
|
||||
RuleBasedCollator* collator = (RuleBasedCollator*)formatter->getCollator();
|
||||
CollationElementIterator* strIter = collator->createCollationElementIterator(str);
|
||||
CollationElementIterator* prefixIter = collator->createCollationElementIterator(prefix);
|
||||
|
||||
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
|
||||
// The original code was problematic. Consider this match:
|
||||
// prefix = "fifty-"
|
||||
// string = " fifty-7"
|
||||
// The intent is to match string up to the '7', by matching 'fifty-' at position 1
|
||||
// in the string. Unfortunately, we were getting a match, and then computing where
|
||||
// the match terminated by rematching the string. The rematch code was using as an
|
||||
// initial guess the substring of string between 0 and prefix.length. Because of
|
||||
// the leading space and trailing hyphen (both ignorable) this was succeeding, leaving
|
||||
// the position before the hyphen in the string. Recursing down, we then parsed the
|
||||
// remaining string '-7' as numeric. The resulting number turned out as 43 (50 - 7).
|
||||
// This was not pretty, especially since the string "fifty-7" parsed just fine.
|
||||
//
|
||||
// We have newer APIs now, so we can use calls on the iterator to determine what we
|
||||
// matched up to. If we terminate because we hit the last element in the string,
|
||||
// our match terminates at this length. If we terminate because we hit the last element
|
||||
// in the target, our match terminates at one before the element iterator position.
|
||||
|
||||
// The original code was problematic. Consider this match:
|
||||
// prefix = "fifty-"
|
||||
// string = " fifty-7"
|
||||
// The intent is to match string up to the '7', by matching 'fifty-' at position 1
|
||||
// in the string. Unfortunately, we were getting a match, and then computing where
|
||||
// the match terminated by rematching the string. The rematch code was using as an
|
||||
// initial guess the substring of string between 0 and prefix.length. Because of
|
||||
// the leading space and trailing hyphen (both ignorable) this was succeeding, leaving
|
||||
// the position before the hyphen in the string. Recursing down, we then parsed the
|
||||
// remaining string '-7' as numeric. The resulting number turned out as 43 (50 - 7).
|
||||
// This was not pretty, especially since the string "fifty-7" parsed just fine.
|
||||
//
|
||||
// We have newer APIs now, so we can use calls on the iterator to determine what we
|
||||
// matched up to. If we terminate because we hit the last element in the string,
|
||||
// our match terminates at this length. If we terminate because we hit the last element
|
||||
// in the target, our match terminates at one before the element iterator position.
|
||||
|
||||
// match collation elements between the strings
|
||||
int32_t oStr = strIter->next(err);
|
||||
int32_t oPrefix = prefixIter->next(err);
|
||||
|
||||
|
||||
while (oPrefix != CollationElementIterator::NULLORDER) {
|
||||
// skip over ignorable characters in the target string
|
||||
while (CollationElementIterator::primaryOrder(oStr) == 0
|
||||
while (CollationElementIterator::primaryOrder(oStr) == 0
|
||||
&& oStr != CollationElementIterator::NULLORDER) {
|
||||
oStr = strIter->next(err);
|
||||
}
|
||||
|
||||
|
||||
// skip over ignorable characters in the prefix
|
||||
while (CollationElementIterator::primaryOrder(oPrefix) == 0
|
||||
while (CollationElementIterator::primaryOrder(oPrefix) == 0
|
||||
&& oPrefix != CollationElementIterator::NULLORDER) {
|
||||
oPrefix = prefixIter->next(err);
|
||||
}
|
||||
|
||||
// dlf: move this above following test, if we consume the
|
||||
// entire target, aren't we ok even if the source was also
|
||||
// entirely consumed?
|
||||
|
||||
// dlf: move this above following test, if we consume the
|
||||
// entire target, aren't we ok even if the source was also
|
||||
// entirely consumed?
|
||||
|
||||
// if skipping over ignorables brought to the end of
|
||||
// the prefix, we DID match: drop out of the loop
|
||||
@ -1176,16 +1176,16 @@ NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix) cons
|
||||
delete strIter;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// match collation elements from the two strings
|
||||
// (considering only primary differences). If we
|
||||
// get a mismatch, dump out and return 0
|
||||
if (CollationElementIterator::primaryOrder(oStr)
|
||||
if (CollationElementIterator::primaryOrder(oStr)
|
||||
!= CollationElementIterator::primaryOrder(oPrefix)) {
|
||||
delete prefixIter;
|
||||
delete strIter;
|
||||
return 0;
|
||||
|
||||
|
||||
// otherwise, advance to the next character in each string
|
||||
// and loop (we drop out of the loop when we exhaust
|
||||
// collation elements in the prefix)
|
||||
@ -1194,26 +1194,26 @@ NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix) cons
|
||||
oPrefix = prefixIter->next(err);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t result = strIter->getOffset();
|
||||
if (oStr != CollationElementIterator::NULLORDER) {
|
||||
--result; // back over character that we don't want to consume;
|
||||
}
|
||||
|
||||
int32_t result = strIter->getOffset();
|
||||
if (oStr != CollationElementIterator::NULLORDER) {
|
||||
--result; // back over character that we don't want to consume;
|
||||
}
|
||||
|
||||
#ifdef RBNF_DEBUG
|
||||
fprintf(stderr, "prefix length: %d\n", result);
|
||||
fprintf(stderr, "prefix length: %d\n", result);
|
||||
#endif
|
||||
delete prefixIter;
|
||||
delete strIter;
|
||||
|
||||
return result;
|
||||
|
||||
return result;
|
||||
#if 0
|
||||
//----------------------------------------------------------------
|
||||
// JDK 1.2-specific API call
|
||||
// return strIter.getOffset();
|
||||
//----------------------------------------------------------------
|
||||
// JDK 1.1 HACK (take out for 1.2-specific code)
|
||||
|
||||
|
||||
// if we make it to here, we have a successful match. Now we
|
||||
// have to find out HOW MANY characters from the target string
|
||||
// matched the prefix (there isn't necessarily a one-to-one
|
||||
@ -1229,12 +1229,12 @@ NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix) cons
|
||||
temp.setTo(str, 0, prefix.length());
|
||||
if (collator->equals(temp, prefix)) {
|
||||
#ifdef RBNF_DEBUG
|
||||
fprintf(stderr, "returning: %d\n", prefix.length());
|
||||
fprintf(stderr, "returning: %d\n", prefix.length());
|
||||
#endif
|
||||
return prefix.length();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if they're not equal, then we have to compare successively
|
||||
// larger and larger substrings of the target string until we
|
||||
// get to one that matches the prefix. At that point, we know
|
||||
@ -1249,12 +1249,12 @@ NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix) cons
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// SHOULD NEVER GET HERE!!!
|
||||
return 0;
|
||||
//----------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
|
||||
// If lenient parsing is turned off, forget all that crap above.
|
||||
// Just use String.startsWith() and be done with it.
|
||||
} else {
|
||||
@ -1282,8 +1282,8 @@ NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix) cons
|
||||
* the same as the length of "key")
|
||||
*/
|
||||
int32_t
|
||||
NFRule::findText(const UnicodeString& str,
|
||||
const UnicodeString& key,
|
||||
NFRule::findText(const UnicodeString& str,
|
||||
const UnicodeString& key,
|
||||
int32_t startingAt,
|
||||
int32_t* length) const
|
||||
{
|
||||
@ -1292,13 +1292,13 @@ NFRule::findText(const UnicodeString& str,
|
||||
if (!formatter->isLenient()) {
|
||||
*length = key.length();
|
||||
return str.indexOf(key, startingAt);
|
||||
|
||||
|
||||
// but if lenient parsing is turned ON, we've got some work
|
||||
// ahead of us
|
||||
} else {
|
||||
//----------------------------------------------------------------
|
||||
// JDK 1.1 HACK (take out of 1.2-specific code)
|
||||
|
||||
|
||||
// in JDK 1.2, CollationElementIterator provides us with an
|
||||
// API to map between character offsets and collation elements
|
||||
// and we can do this by marching through the string comparing
|
||||
@ -1306,7 +1306,7 @@ NFRule::findText(const UnicodeString& str,
|
||||
// we have to go through this horrible slow mess:
|
||||
int32_t p = startingAt;
|
||||
int32_t keyLen = 0;
|
||||
|
||||
|
||||
// basically just isolate smaller and smaller substrings of
|
||||
// the target string (each running to the end of the string,
|
||||
// and with the first one running from startingAt to the end)
|
||||
@ -1329,7 +1329,7 @@ NFRule::findText(const UnicodeString& str,
|
||||
// which should be "safe"
|
||||
*length = 0;
|
||||
return -1;
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// JDK 1.2 version of this routine
|
||||
//RuleBasedCollator collator = (RuleBasedCollator)formatter.getCollator();
|
||||
@ -1398,21 +1398,21 @@ NFRule::allIgnorable(const UnicodeString& str) const
|
||||
if (str.length() == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// if lenient parsing is turned on, walk through the string with
|
||||
// a collation element iterator and make sure each collation
|
||||
// element is 0 (ignorable) at the primary level
|
||||
if (formatter->isLenient()) {
|
||||
RuleBasedCollator* collator = (RuleBasedCollator*)(formatter->getCollator());
|
||||
CollationElementIterator* iter = collator->createCollationElementIterator(str);
|
||||
|
||||
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
int32_t o = iter->next(err);
|
||||
while (o != CollationElementIterator::NULLORDER
|
||||
&& CollationElementIterator::primaryOrder(o) == 0) {
|
||||
o = iter->next(err);
|
||||
}
|
||||
|
||||
|
||||
delete iter;
|
||||
return o == CollationElementIterator::NULLORDER;
|
||||
}
|
||||
|
@ -23,15 +23,15 @@ static const UChar gPound = 0x0023;
|
||||
static const UChar gZero = 0x0030;
|
||||
static const UChar gSpace = 0x0020;
|
||||
|
||||
static const UChar gEqualsEquals[] =
|
||||
static const UChar gEqualsEquals[] =
|
||||
{
|
||||
0x3D, 0x3D, 0
|
||||
}; /* "==" */
|
||||
static const UChar gGreaterGreaterGreaterThan[] =
|
||||
static const UChar gGreaterGreaterGreaterThan[] =
|
||||
{
|
||||
0x3E, 0x3E, 0x3E, 0
|
||||
}; /* ">>>" */
|
||||
static const UChar gGreaterGreaterThan[] =
|
||||
static const UChar gGreaterGreaterThan[] =
|
||||
{
|
||||
0x3E, 0x3E, 0
|
||||
}; /* ">>" */
|
||||
@ -43,7 +43,7 @@ NFSubstitution::makeSubstitution(int32_t pos,
|
||||
const NFRuleSet* ruleSet,
|
||||
const RuleBasedNumberFormat* formatter,
|
||||
const UnicodeString& description,
|
||||
UErrorCode& status)
|
||||
UErrorCode& status)
|
||||
{
|
||||
// if the description is empty, return a NullSubstitution
|
||||
if (description.length() == 0) {
|
||||
@ -89,7 +89,7 @@ NFSubstitution::makeSubstitution(int32_t pos,
|
||||
if (rule->getBaseValue() == NFRule::kNegativeNumberRule) {
|
||||
return new AbsoluteValueSubstitution(pos, ruleSet, formatter, description, status);
|
||||
}
|
||||
|
||||
|
||||
// if the rule is a fraction rule, return a
|
||||
// FractionalPartSubstitution
|
||||
else if (rule->getBaseValue() == NFRule::kImproperFractionRule
|
||||
@ -97,7 +97,7 @@ NFSubstitution::makeSubstitution(int32_t pos,
|
||||
|| rule->getBaseValue() == NFRule::kMasterRule) {
|
||||
return new FractionalPartSubstitution(pos, ruleSet, formatter, description, status);
|
||||
}
|
||||
|
||||
|
||||
// if the rule set owning the rule is a fraction rule set,
|
||||
// throw an exception
|
||||
else if (ruleSet->isFractionRuleSet()) {
|
||||
@ -223,19 +223,19 @@ NFSubstitution::getDynamicClassID() const {
|
||||
* @param The substitution to compare this one to
|
||||
* @return true if the two substitutions are functionally equivalent
|
||||
*/
|
||||
UBool
|
||||
UBool
|
||||
NFSubstitution::operator==(const NFSubstitution& rhs) const
|
||||
{
|
||||
// compare class and all of the fields all substitutions have
|
||||
// in common
|
||||
// this should be called by subclasses before their own equality tests
|
||||
return getDynamicClassID() == rhs.getDynamicClassID()
|
||||
return getDynamicClassID() == rhs.getDynamicClassID()
|
||||
&& pos == rhs.pos
|
||||
&& (ruleSet == NULL) == (rhs.ruleSet == NULL)
|
||||
&& (ruleSet == NULL) == (rhs.ruleSet == NULL)
|
||||
// && ruleSet == rhs.ruleSet causes circularity, other checks to make instead?
|
||||
&& (numberFormat == NULL
|
||||
? (rhs.numberFormat == NULL)
|
||||
: (*numberFormat == *rhs.numberFormat));
|
||||
&& (numberFormat == NULL
|
||||
? (rhs.numberFormat == NULL)
|
||||
: (*numberFormat == *rhs.numberFormat));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,7 +244,7 @@ NFSubstitution::operator==(const NFSubstitution& rhs) const
|
||||
* not be identical to the description it was created from, but
|
||||
* it'll produce the same result.
|
||||
*/
|
||||
void
|
||||
void
|
||||
NFSubstitution::toString(UnicodeString& text) const
|
||||
{
|
||||
// use tokenChar() to get the character at the beginning and
|
||||
@ -312,7 +312,7 @@ NFSubstitution::doSubstitution(const llong &number, UnicodeString& toInsertInto,
|
||||
* rule text begins (this value is added to this substitution's
|
||||
* position to determine exactly where to insert the new text)
|
||||
*/
|
||||
void
|
||||
void
|
||||
NFSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32_t _pos) const {
|
||||
// perform a transformation on the number being formatted that
|
||||
// is dependent on the type of substitution this is
|
||||
@ -375,11 +375,11 @@ NFSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32
|
||||
* no match this is new Long(0) (not null), and parsePosition
|
||||
* is left unchanged.
|
||||
*/
|
||||
UBool
|
||||
NFSubstitution::doParse(const UnicodeString& text,
|
||||
ParsePosition& parsePosition,
|
||||
UBool
|
||||
NFSubstitution::doParse(const UnicodeString& text,
|
||||
ParsePosition& parsePosition,
|
||||
double baseValue,
|
||||
double upperBound,
|
||||
double upperBound,
|
||||
UBool lenientParse,
|
||||
Formattable& result) const
|
||||
{
|
||||
@ -421,8 +421,8 @@ NFSubstitution::doParse(const UnicodeString& text,
|
||||
// of its own). Derive a parse result and return it as a Long,
|
||||
// if possible, or a Double
|
||||
if (parsePosition.getIndex() != 0) {
|
||||
double tempResult = (result.getType() == Formattable::kLong) ?
|
||||
(double)result.getLong() :
|
||||
double tempResult = (result.getType() == Formattable::kLong) ?
|
||||
(double)result.getLong() :
|
||||
result.getDouble();
|
||||
|
||||
// composeRuleValue() produces a full parse result from
|
||||
@ -458,7 +458,7 @@ NFSubstitution::doParse(const UnicodeString& text,
|
||||
}
|
||||
|
||||
|
||||
UBool
|
||||
UBool
|
||||
NFSubstitution::isNullSubstitution() const {
|
||||
return FALSE;
|
||||
}
|
||||
@ -469,7 +469,7 @@ NFSubstitution::isNullSubstitution() const {
|
||||
* proliferate and partially because we have to port this to C++.)
|
||||
* @return true if this object is an instance of ModulusSubstitution
|
||||
*/
|
||||
UBool
|
||||
UBool
|
||||
NFSubstitution::isModulusSubstitution() const {
|
||||
return FALSE;
|
||||
}
|
||||
@ -486,7 +486,7 @@ SameValueSubstitution::SameValueSubstitution(int32_t _pos,
|
||||
const NFRuleSet* _ruleSet,
|
||||
const RuleBasedNumberFormat* formatter,
|
||||
const UnicodeString& description,
|
||||
UErrorCode& status)
|
||||
UErrorCode& status)
|
||||
: NFSubstitution(_pos, _ruleSet, formatter, description, status)
|
||||
{
|
||||
if (description == gEqualsEquals) {
|
||||
@ -591,7 +591,7 @@ ModulusSubstitution::doSubstitution(const llong & number, UnicodeString& toIns
|
||||
// to format its substitution value)
|
||||
if (ruleToUse == NULL) {
|
||||
NFSubstitution::doSubstitution(number, toInsertInto, _pos);
|
||||
|
||||
|
||||
// a >>> substitution goes straight to a particular rule to
|
||||
// format the substitution value
|
||||
} else {
|
||||
@ -608,7 +608,7 @@ ModulusSubstitution::doSubstitution(const llong & number, UnicodeString& toIns
|
||||
* into
|
||||
* @param pos The position of the rule text in toInsertInto
|
||||
*/
|
||||
void
|
||||
void
|
||||
ModulusSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32_t _pos) const
|
||||
{
|
||||
// if this isn't a >>> substitution, just use the inherited version
|
||||
@ -616,12 +616,12 @@ ModulusSubstitution::doSubstitution(double number, UnicodeString& toInsertInto,
|
||||
// to format its substitution value)
|
||||
if (ruleToUse == NULL) {
|
||||
NFSubstitution::doSubstitution(number, toInsertInto, _pos);
|
||||
|
||||
|
||||
// a >>> substitution goes straight to a particular rule to
|
||||
// format the substitution value
|
||||
} else {
|
||||
double numberToFormat = transformNumber(number);
|
||||
|
||||
|
||||
ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos());
|
||||
}
|
||||
}
|
||||
@ -640,8 +640,8 @@ ModulusSubstitution::doSubstitution(double number, UnicodeString& toInsertInto,
|
||||
* @param baseValue The partial parse result prior to calling this
|
||||
* routine.
|
||||
*/
|
||||
UBool
|
||||
ModulusSubstitution::doParse(const UnicodeString& text,
|
||||
UBool
|
||||
ModulusSubstitution::doParse(const UnicodeString& text,
|
||||
ParsePosition& parsePosition,
|
||||
double baseValue,
|
||||
double upperBound,
|
||||
@ -730,14 +730,14 @@ FractionalPartSubstitution::FractionalPartSubstitution(int32_t _pos,
|
||||
* @param pos The position of the owning rule's rule text in
|
||||
* toInsertInto
|
||||
*/
|
||||
void
|
||||
void
|
||||
FractionalPartSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32_t _pos) const
|
||||
{
|
||||
// if we're not in "byDigits" mode, just use the inherited
|
||||
// doSubstitution() routine
|
||||
if (!byDigits) {
|
||||
NFSubstitution::doSubstitution(number, toInsertInto, _pos);
|
||||
|
||||
|
||||
// if we're in "byDigits" mode, transform the value into an integer
|
||||
// by moving the decimal point eight places to the right and
|
||||
// pulling digits off the right one at a time, formatting each digit
|
||||
@ -816,7 +816,7 @@ FractionalPartSubstitution::doParse(const UnicodeString& text,
|
||||
digit = temp.getType() == Formattable::kLong ?
|
||||
temp.getLong() :
|
||||
(int32_t)temp.getDouble();
|
||||
|
||||
|
||||
if (lenientParse && workPos.getIndex() == 0) {
|
||||
if (!fmt) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
@ -851,7 +851,7 @@ FractionalPartSubstitution::doParse(const UnicodeString& text,
|
||||
}
|
||||
}
|
||||
|
||||
UBool
|
||||
UBool
|
||||
FractionalPartSubstitution::operator==(const NFSubstitution& rhs) const
|
||||
{
|
||||
return NFSubstitution::operator==(rhs) &&
|
||||
@ -881,7 +881,7 @@ AbsoluteValueSubstitution::getDynamicClassID() const {
|
||||
// NumeratorSubstitution
|
||||
//===================================================================
|
||||
|
||||
UBool
|
||||
UBool
|
||||
NumeratorSubstitution::operator==(const NFSubstitution& rhs) const
|
||||
{
|
||||
return NFSubstitution::operator==(rhs) &&
|
||||
|
@ -21,7 +21,7 @@
|
||||
* Changed setMaxFractionDigits per Java implementation.
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/resbund.h"
|
||||
@ -51,7 +51,7 @@ U_NAMESPACE_BEGIN
|
||||
|
||||
const char NumberFormat::fgClassID = 0; // Value is irrelevant
|
||||
|
||||
// If the maximum base 10 exponent were 4, then the largest number would
|
||||
// If the maximum base 10 exponent were 4, then the largest number would
|
||||
// be 99,999 which has 5 digits.
|
||||
const int32_t NumberFormat::fgMaxIntegerDigits = DBL_MAX_10_EXP + 1; // Should be ~40 ? --srl
|
||||
const int32_t NumberFormat::fgMinIntegerDigits = 127;
|
||||
@ -63,7 +63,7 @@ const UChar * const NumberFormat::fgLastResortNumberPatterns[] =
|
||||
gLastResortDecimalPat,
|
||||
gLastResortCurrencyPat,
|
||||
gLastResortPercentPat,
|
||||
gLastResortScientificPat
|
||||
gLastResortScientificPat
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
@ -113,7 +113,7 @@ NumberFormat::operator=(const NumberFormat& rhs)
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
|
||||
UBool
|
||||
NumberFormat::operator==(const Format& that) const
|
||||
{
|
||||
@ -133,7 +133,7 @@ NumberFormat::operator==(const Format& that) const
|
||||
// -------------------------------------
|
||||
// Formats the number object and save the format
|
||||
// result in the toAppendTo string buffer.
|
||||
|
||||
|
||||
UnicodeString&
|
||||
NumberFormat::format(const Formattable& obj,
|
||||
UnicodeString& toAppendTo,
|
||||
@ -151,10 +151,10 @@ NumberFormat::format(const Formattable& obj,
|
||||
// can't try to format a non-numeric object
|
||||
else {
|
||||
status = U_INVALID_FORMAT_ERROR;
|
||||
return toAppendTo;
|
||||
return toAppendTo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Parses the string and save the result object as well
|
||||
// as the final parsed position.
|
||||
@ -166,33 +166,33 @@ NumberFormat::parseObject(const UnicodeString& source,
|
||||
{
|
||||
parse(source, result, parse_pos);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Formats a double number and save the result in a string.
|
||||
|
||||
|
||||
UnicodeString&
|
||||
NumberFormat::format(double number, UnicodeString& toAppendTo) const
|
||||
{
|
||||
FieldPosition pos(0);
|
||||
return format(number, toAppendTo, pos);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Formats a long number and save the result in a string.
|
||||
|
||||
|
||||
UnicodeString&
|
||||
NumberFormat::format(int32_t number, UnicodeString& toAppendTo) const
|
||||
{
|
||||
FieldPosition pos(0);
|
||||
return format(number, toAppendTo, pos);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Parses the text and save the result object. If the returned
|
||||
// parse position is 0, that means the parsing failed, the status
|
||||
// code needs to be set to failure. Ignores the returned parse
|
||||
// code needs to be set to failure. Ignores the returned parse
|
||||
// position, otherwise.
|
||||
|
||||
|
||||
void
|
||||
NumberFormat::parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
@ -206,98 +206,98 @@ NumberFormat::parse(const UnicodeString& text,
|
||||
status = U_INVALID_FORMAT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Sets to only parse integers.
|
||||
|
||||
|
||||
void
|
||||
NumberFormat::setParseIntegerOnly(UBool value)
|
||||
{
|
||||
fParseIntegerOnly = value;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Create a number style NumberFormat instance with the default locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createInstance(UErrorCode& status)
|
||||
{
|
||||
return createInstance(Locale::getDefault(), kNumberStyle, status);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Create a number style NumberFormat instance with the inLocale locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createInstance(const Locale& inLocale, UErrorCode& status)
|
||||
{
|
||||
return createInstance(inLocale, kNumberStyle, status);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Create a currency style NumberFormat instance with the default locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createCurrencyInstance(UErrorCode& status)
|
||||
{
|
||||
return createInstance(Locale::getDefault(), kCurrencyStyle, status);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Create a currency style NumberFormat instance with the inLocale locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createCurrencyInstance(const Locale& inLocale, UErrorCode& status)
|
||||
{
|
||||
return createInstance(inLocale, kCurrencyStyle, status);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Create a percent style NumberFormat instance with the default locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createPercentInstance(UErrorCode& status)
|
||||
{
|
||||
return createInstance(Locale::getDefault(), kPercentStyle, status);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Create a percent style NumberFormat instance with the inLocale locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createPercentInstance(const Locale& inLocale, UErrorCode& status)
|
||||
{
|
||||
return createInstance(inLocale, kPercentStyle, status);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Create a scientific style NumberFormat instance with the default locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createScientificInstance(UErrorCode& status)
|
||||
{
|
||||
return createInstance(Locale::getDefault(), kScientificStyle, status);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Create a scientific style NumberFormat instance with the inLocale locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createScientificInstance(const Locale& inLocale, UErrorCode& status)
|
||||
{
|
||||
return createInstance(inLocale, kScientificStyle, status);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
|
||||
const Locale*
|
||||
NumberFormat::getAvailableLocales(int32_t& count)
|
||||
{
|
||||
return Locale::getAvailableLocales(count);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Checks if the thousand/10 thousand grouping is used in the
|
||||
// Checks if the thousand/10 thousand grouping is used in the
|
||||
// NumberFormat instance.
|
||||
|
||||
UBool
|
||||
@ -305,30 +305,30 @@ NumberFormat::isGroupingUsed() const
|
||||
{
|
||||
return fGroupingUsed;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Sets to use the thousand/10 thousand grouping in the
|
||||
// Sets to use the thousand/10 thousand grouping in the
|
||||
// NumberFormat instance.
|
||||
|
||||
|
||||
void
|
||||
NumberFormat::setGroupingUsed(UBool newValue)
|
||||
{
|
||||
fGroupingUsed = newValue;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Gets the maximum number of digits for the integral part for
|
||||
// this NumberFormat instance.
|
||||
|
||||
|
||||
int32_t NumberFormat::getMaximumIntegerDigits() const
|
||||
{
|
||||
return fMaxIntegerDigits;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Sets the maximum number of digits for the integral part for
|
||||
// this NumberFormat instance.
|
||||
|
||||
|
||||
void
|
||||
NumberFormat::setMaximumIntegerDigits(int32_t newValue)
|
||||
{
|
||||
@ -336,21 +336,21 @@ NumberFormat::setMaximumIntegerDigits(int32_t newValue)
|
||||
if(fMinIntegerDigits > fMaxIntegerDigits)
|
||||
fMinIntegerDigits = fMaxIntegerDigits;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Gets the minimum number of digits for the integral part for
|
||||
// this NumberFormat instance.
|
||||
|
||||
|
||||
int32_t
|
||||
NumberFormat::getMinimumIntegerDigits() const
|
||||
{
|
||||
return fMinIntegerDigits;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Sets the minimum number of digits for the integral part for
|
||||
// this NumberFormat instance.
|
||||
|
||||
|
||||
void
|
||||
NumberFormat::setMinimumIntegerDigits(int32_t newValue)
|
||||
{
|
||||
@ -358,21 +358,21 @@ NumberFormat::setMinimumIntegerDigits(int32_t newValue)
|
||||
if(fMinIntegerDigits > fMaxIntegerDigits)
|
||||
fMaxIntegerDigits = fMinIntegerDigits;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Gets the maximum number of digits for the fractional part for
|
||||
// this NumberFormat instance.
|
||||
|
||||
|
||||
int32_t
|
||||
NumberFormat::getMaximumFractionDigits() const
|
||||
{
|
||||
return fMaxFractionDigits;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Sets the maximum number of digits for the fractional part for
|
||||
// this NumberFormat instance.
|
||||
|
||||
|
||||
void
|
||||
NumberFormat::setMaximumFractionDigits(int32_t newValue)
|
||||
{
|
||||
@ -380,21 +380,21 @@ NumberFormat::setMaximumFractionDigits(int32_t newValue)
|
||||
if(fMaxFractionDigits < fMinFractionDigits)
|
||||
fMinFractionDigits = fMaxFractionDigits;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Gets the minimum number of digits for the fractional part for
|
||||
// this NumberFormat instance.
|
||||
|
||||
|
||||
int32_t
|
||||
NumberFormat::getMinimumFractionDigits() const
|
||||
{
|
||||
return fMinFractionDigits;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Sets the minimum number of digits for the fractional part for
|
||||
// this NumberFormat instance.
|
||||
|
||||
|
||||
void
|
||||
NumberFormat::setMinimumFractionDigits(int32_t newValue)
|
||||
{
|
||||
@ -402,14 +402,14 @@ NumberFormat::setMinimumFractionDigits(int32_t newValue)
|
||||
if (fMaxFractionDigits < fMinFractionDigits)
|
||||
fMaxFractionDigits = fMinFractionDigits;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Creates the NumberFormat instance of the specified style (number, currency,
|
||||
// or percent) for the desired locale.
|
||||
|
||||
|
||||
NumberFormat*
|
||||
NumberFormat::createInstance(const Locale& desiredLocale,
|
||||
EStyles style,
|
||||
NumberFormat::createInstance(const Locale& desiredLocale,
|
||||
EStyles style,
|
||||
UErrorCode& status)
|
||||
{
|
||||
if (U_FAILURE(status)) return NULL;
|
||||
@ -426,7 +426,7 @@ NumberFormat::createInstance(const Locale& desiredLocale,
|
||||
{
|
||||
// We don't appear to have resource data available -- use the last-resort data
|
||||
status = U_USING_FALLBACK_ERROR;
|
||||
|
||||
|
||||
// Use the DecimalFormatSymbols constructor which uses last-resort data
|
||||
DecimalFormatSymbols* symbolsToAdopt = new DecimalFormatSymbols(status);
|
||||
if (symbolsToAdopt == NULL) {
|
||||
|
@ -69,7 +69,7 @@ RuleBasedNumberFormat::RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale&
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const char* fmt_tag = "";
|
||||
switch (tag) {
|
||||
case URBNF_SPELLOUT: fmt_tag = "SpelloutRules"; break;
|
||||
@ -77,7 +77,7 @@ RuleBasedNumberFormat::RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale&
|
||||
case URBNF_DURATION: fmt_tag = "DurationRules"; break;
|
||||
default: status = U_ILLEGAL_ARGUMENT_ERROR; return;
|
||||
}
|
||||
|
||||
|
||||
UResourceBundle* nfrb = ures_open(NULL, locale.getName(), &status);
|
||||
int32_t len = 0;
|
||||
const UChar* description = ures_getStringByKey(nfrb, fmt_tag, &len, &status);
|
||||
@ -102,7 +102,7 @@ RuleBasedNumberFormat::RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs)
|
||||
this->operator=(rhs);
|
||||
}
|
||||
|
||||
RuleBasedNumberFormat&
|
||||
RuleBasedNumberFormat&
|
||||
RuleBasedNumberFormat::operator=(const RuleBasedNumberFormat& rhs)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
@ -120,30 +120,30 @@ RuleBasedNumberFormat::~RuleBasedNumberFormat()
|
||||
dispose();
|
||||
}
|
||||
|
||||
Format*
|
||||
Format*
|
||||
RuleBasedNumberFormat::clone(void) const
|
||||
{
|
||||
RuleBasedNumberFormat * result = NULL;
|
||||
UnicodeString rules = getRules();
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UParseError perror;
|
||||
result = new RuleBasedNumberFormat(rules, locale, perror, status);
|
||||
if (U_FAILURE(status)) {
|
||||
delete result;
|
||||
result = NULL;
|
||||
} else {
|
||||
result->lenient = lenient;
|
||||
}
|
||||
UParseError perror;
|
||||
result = new RuleBasedNumberFormat(rules, locale, perror, status);
|
||||
if (U_FAILURE(status)) {
|
||||
delete result;
|
||||
result = NULL;
|
||||
} else {
|
||||
result->lenient = lenient;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
UBool
|
||||
UBool
|
||||
RuleBasedNumberFormat::operator==(const Format& other) const
|
||||
{
|
||||
if (this == &other) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (other.getDynamicClassID() == getStaticClassID()) {
|
||||
const RuleBasedNumberFormat& rhs = (const RuleBasedNumberFormat&)other;
|
||||
if (locale == rhs.locale &&
|
||||
@ -157,11 +157,11 @@ RuleBasedNumberFormat::operator==(const Format& other) const
|
||||
return *q == NULL && *p == NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UnicodeString
|
||||
UnicodeString
|
||||
RuleBasedNumberFormat::getRules() const
|
||||
{
|
||||
UnicodeString result;
|
||||
@ -171,7 +171,7 @@ RuleBasedNumberFormat::getRules() const
|
||||
return result;
|
||||
}
|
||||
|
||||
UnicodeString
|
||||
UnicodeString
|
||||
RuleBasedNumberFormat::getRuleSetName(int32_t index) const
|
||||
{
|
||||
UnicodeString result;
|
||||
@ -188,7 +188,7 @@ RuleBasedNumberFormat::getRuleSetName(int32_t index) const
|
||||
}
|
||||
|
||||
int32_t
|
||||
RuleBasedNumberFormat::getNumberOfRuleSetNames() const
|
||||
RuleBasedNumberFormat::getNumberOfRuleSetNames() const
|
||||
{
|
||||
int32_t result = 0;
|
||||
for (NFRuleSet** p = ruleSets; *p; ++p) {
|
||||
@ -214,7 +214,7 @@ RuleBasedNumberFormat::findRuleSet(const UnicodeString& name, UErrorCode& status
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UnicodeString&
|
||||
UnicodeString&
|
||||
RuleBasedNumberFormat::format(int32_t number,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const
|
||||
@ -224,7 +224,7 @@ RuleBasedNumberFormat::format(int32_t number,
|
||||
}
|
||||
|
||||
#if 0
|
||||
UnicodeString&
|
||||
UnicodeString&
|
||||
RuleBasedNumberFormat::format(llong number,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const
|
||||
@ -234,7 +234,7 @@ RuleBasedNumberFormat::format(llong number,
|
||||
}
|
||||
#endif
|
||||
|
||||
UnicodeString&
|
||||
UnicodeString&
|
||||
RuleBasedNumberFormat::format(double number,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const
|
||||
@ -244,7 +244,7 @@ RuleBasedNumberFormat::format(double number,
|
||||
}
|
||||
|
||||
|
||||
UnicodeString&
|
||||
UnicodeString&
|
||||
RuleBasedNumberFormat::format(int32_t number,
|
||||
const UnicodeString& ruleSetName,
|
||||
UnicodeString& toAppendTo,
|
||||
@ -267,7 +267,7 @@ RuleBasedNumberFormat::format(int32_t number,
|
||||
}
|
||||
|
||||
#if 0
|
||||
UnicodeString&
|
||||
UnicodeString&
|
||||
RuleBasedNumberFormat::format(llong number,
|
||||
const UnicodeString& ruleSetName,
|
||||
UnicodeString& toAppendTo,
|
||||
@ -290,16 +290,16 @@ RuleBasedNumberFormat::format(llong number,
|
||||
#endif
|
||||
|
||||
// make linker happy
|
||||
UnicodeString&
|
||||
UnicodeString&
|
||||
RuleBasedNumberFormat::format(const Formattable& obj,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const
|
||||
{
|
||||
UErrorCode& status) const
|
||||
{
|
||||
return NumberFormat::format(obj, toAppendTo, pos, status);
|
||||
}
|
||||
|
||||
UnicodeString&
|
||||
UnicodeString&
|
||||
RuleBasedNumberFormat::format(double number,
|
||||
const UnicodeString& ruleSetName,
|
||||
UnicodeString& toAppendTo,
|
||||
@ -320,35 +320,35 @@ RuleBasedNumberFormat::format(double number,
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
RuleBasedNumberFormat::parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
ParsePosition& parsePosition) const
|
||||
{
|
||||
ParsePosition high_pp;
|
||||
Formattable high_result;
|
||||
|
||||
|
||||
for (NFRuleSet** p = ruleSets; *p; ++p) {
|
||||
NFRuleSet *rp = *p;
|
||||
if (rp->isPublic()) {
|
||||
ParsePosition working_pp = parsePosition;
|
||||
Formattable working_result;
|
||||
|
||||
|
||||
rp->parse(text, working_pp, kMaxDouble, working_result);
|
||||
if (working_pp.getIndex() > high_pp.getIndex()) {
|
||||
high_pp = working_pp;
|
||||
high_result = working_result;
|
||||
|
||||
|
||||
if (high_pp.getIndex() == text.length()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (high_pp.getIndex() > parsePosition.getIndex()) {
|
||||
high_pp.setErrorIndex(-1);
|
||||
}
|
||||
|
||||
if (high_pp.getIndex() > parsePosition.getIndex()) {
|
||||
high_pp.setErrorIndex(-1);
|
||||
}
|
||||
parsePosition = high_pp;
|
||||
result = high_result;
|
||||
if (result.getType() == Formattable::kDouble) {
|
||||
@ -369,27 +369,27 @@ RuleBasedNumberFormat::setLenient(UBool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErrorCode& status)
|
||||
{
|
||||
// TODO: implement UParseError
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
UnicodeString description(rules);
|
||||
if (!description.length()) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// start by stripping the trailing whitespace from all the rules
|
||||
// (this is all the whitespace follwing each semicolon in the
|
||||
// description). This allows us to look for rule-set boundaries
|
||||
// by searching for ";%" without having to worry about whitespace
|
||||
// between the ; and the %
|
||||
stripWhitespace(description);
|
||||
|
||||
|
||||
// check to see if there's a set of lenient-parse rules. If there
|
||||
// is, pull them out into our temporary holding place for them,
|
||||
// and delete them from the description before the real desciption-
|
||||
@ -404,7 +404,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErro
|
||||
// rules (there may be whitespace between the name and
|
||||
// the first token in the description)
|
||||
int lpEnd = description.indexOf(gSemiPercent, lp);
|
||||
|
||||
|
||||
if (lpEnd == -1) {
|
||||
lpEnd = description.length() - 1;
|
||||
}
|
||||
@ -412,16 +412,16 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErro
|
||||
while (u_isWhitespace(description.charAt(lpStart))) {
|
||||
++lpStart;
|
||||
}
|
||||
|
||||
|
||||
// copy out the lenient-parse rules and delete them
|
||||
// from the description
|
||||
lenientParseRules = new UnicodeString();
|
||||
lenientParseRules->setTo(description, lpStart, lpEnd - lpStart);
|
||||
|
||||
|
||||
description.remove(lp, lpEnd + 1 - lp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// pre-flight parsing the description and count the number of
|
||||
// rule sets (";%" marks the end of one rule set and the beginning
|
||||
// of the next)
|
||||
@ -431,13 +431,13 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErro
|
||||
++p;
|
||||
}
|
||||
++numRuleSets;
|
||||
|
||||
|
||||
// our rule list is an array of the appropriate size
|
||||
ruleSets = new NFRuleSet*[numRuleSets + 1];
|
||||
for (int i = 0; i <= numRuleSets; ++i) {
|
||||
ruleSets[i] = NULL;
|
||||
}
|
||||
|
||||
|
||||
// divide up the descriptions into individual rule-set descriptions
|
||||
// and store them in a temporary array. At each step, we also
|
||||
// new up a rule set, but all this does is initialize its name
|
||||
@ -446,7 +446,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErro
|
||||
// because we have to know the names and locations of all the rule
|
||||
// sets before we can actually set everything up
|
||||
UnicodeString* ruleSetDescriptions = new UnicodeString[numRuleSets];
|
||||
|
||||
|
||||
{
|
||||
int curRuleSet = 0;
|
||||
UTextOffset start = 0;
|
||||
@ -459,7 +459,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErro
|
||||
ruleSetDescriptions[curRuleSet].setTo(description, start, description.length() - start);
|
||||
ruleSets[curRuleSet] = new NFRuleSet(ruleSetDescriptions, curRuleSet, status);
|
||||
}
|
||||
|
||||
|
||||
// now we can take note of the formatter's default rule set, which
|
||||
// is the last public rule set in the description (it's the last
|
||||
// rather than the first so that a user can create a new formatter
|
||||
@ -477,7 +477,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErro
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// finally, we can go back through the temporary descriptions
|
||||
// list and finish seting up the substructure (and we throw
|
||||
// away the temporary descriptions as we go)
|
||||
@ -486,16 +486,16 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErro
|
||||
ruleSets[i]->parseRules(ruleSetDescriptions[i], this, status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delete[] ruleSetDescriptions;
|
||||
}
|
||||
|
||||
void
|
||||
RuleBasedNumberFormat::stripWhitespace(UnicodeString& description)
|
||||
RuleBasedNumberFormat::stripWhitespace(UnicodeString& description)
|
||||
{
|
||||
// iterate through the characters...
|
||||
UnicodeString result;
|
||||
|
||||
|
||||
int start = 0;
|
||||
while (start != -1 && start < description.length()) {
|
||||
// seek to the first non-whitespace character...
|
||||
@ -503,7 +503,7 @@ RuleBasedNumberFormat::stripWhitespace(UnicodeString& description)
|
||||
&& u_isWhitespace(description.charAt(start))) {
|
||||
++start;
|
||||
}
|
||||
|
||||
|
||||
// locate the next semicolon in the text and copy the text from
|
||||
// our current position up to that semicolon into the result
|
||||
UTextOffset p = description.indexOf(gSemiColon, start);
|
||||
@ -517,7 +517,7 @@ RuleBasedNumberFormat::stripWhitespace(UnicodeString& description)
|
||||
result.append(description, start, p + 1 - start);
|
||||
start = p + 1;
|
||||
}
|
||||
|
||||
|
||||
// when we get here, we've seeked off the end of the sring, and
|
||||
// we terminate the loop (we continue until *start* is -1 rather
|
||||
// than until *p* is -1, because otherwise we'd miss the last
|
||||
@ -526,12 +526,12 @@ RuleBasedNumberFormat::stripWhitespace(UnicodeString& description)
|
||||
start = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
description.setTo(result);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
void
|
||||
RuleBasedNumberFormat::dispose()
|
||||
{
|
||||
if (ruleSets) {
|
||||
@ -541,15 +541,15 @@ RuleBasedNumberFormat::dispose()
|
||||
delete[] ruleSets;
|
||||
ruleSets = NULL;
|
||||
}
|
||||
|
||||
delete collator;
|
||||
collator = NULL;
|
||||
|
||||
delete decimalFormatSymbols;
|
||||
decimalFormatSymbols = NULL;
|
||||
|
||||
delete lenientParseRules;
|
||||
lenientParseRules = NULL;
|
||||
|
||||
delete collator;
|
||||
collator = NULL;
|
||||
|
||||
delete decimalFormatSymbols;
|
||||
decimalFormatSymbols = NULL;
|
||||
|
||||
delete lenientParseRules;
|
||||
lenientParseRules = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -572,18 +572,18 @@ RuleBasedNumberFormat::getCollator() const
|
||||
// then pull out that collator's rules, append any additional
|
||||
// rules specified in the description, and create a _new_
|
||||
// collator based on the combinaiton of those rules
|
||||
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
|
||||
Collator* temp = Collator::createInstance(locale, status);
|
||||
if (U_SUCCESS(status) &&
|
||||
temp->getDynamicClassID() == RuleBasedCollator::getStaticClassID()) {
|
||||
|
||||
|
||||
RuleBasedCollator* newCollator = (RuleBasedCollator*)temp;
|
||||
if (lenientParseRules) {
|
||||
UnicodeString rules(newCollator->getRules());
|
||||
rules.append(*lenientParseRules);
|
||||
|
||||
|
||||
newCollator = new RuleBasedCollator(rules, status);
|
||||
} else {
|
||||
temp = NULL;
|
||||
@ -598,7 +598,7 @@ RuleBasedNumberFormat::getCollator() const
|
||||
}
|
||||
delete temp;
|
||||
}
|
||||
|
||||
|
||||
// if lenient-parse mode is off, this will be null
|
||||
// (see setLenientParseMode())
|
||||
return collator;
|
||||
|
@ -73,7 +73,7 @@ UnicodeString& _appendHex(uint32_t number,
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0
|
||||
};
|
||||
while (digits--) {
|
||||
target += digitString[(number >> (digits*4)) & 0xF];
|
||||
target += digitString[(number >> (digits*4)) & 0xF];
|
||||
}
|
||||
return target;
|
||||
}
|
||||
@ -277,7 +277,7 @@ void TransliterationRuleSet::freeze(UParseError& parseError,UErrorCode& status)
|
||||
|
||||
/* Precompute the index values. This saves a LOT of time.
|
||||
*/
|
||||
int16_t* indexValue = new int16_t[n];
|
||||
int16_t* indexValue = (int16_t*) uprv_malloc( sizeof(int16_t) * n );
|
||||
for (j=0; j<n; ++j) {
|
||||
TransliterationRule* r = (TransliterationRule*) ruleVector->elementAt(j);
|
||||
indexValue[j] = r->getIndexValue();
|
||||
@ -301,7 +301,7 @@ void TransliterationRuleSet::freeze(UParseError& parseError,UErrorCode& status)
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] indexValue;
|
||||
uprv_free(indexValue);
|
||||
index[256] = v.size();
|
||||
|
||||
/* Freeze things into an array.
|
||||
|
@ -1383,7 +1383,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
|
||||
// case 12: // 'w' - WEEK_OF_YEAR
|
||||
// case 13: // 'W' - WEEK_OF_MONTH
|
||||
// case 16: // 'K' - HOUR: 0-based. eg, 11PM + 1 hour =>> 0 AM
|
||||
// 'e' - DOW_LOCAL
|
||||
// 'e' - DOW_LOCAL
|
||||
|
||||
// WORK AROUND BUG IN NUMBER FORMAT IN 1.2B3
|
||||
int32_t parseStart = pos.getIndex();
|
||||
|
@ -8,7 +8,7 @@
|
||||
//
|
||||
// File sortkey.cpp
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by: Helena Shih
|
||||
//
|
||||
@ -22,19 +22,13 @@
|
||||
// 7/31/98 erm hashCode: minimum inc should be 2 not 1,
|
||||
// Cleaned up operator=
|
||||
// 07/12/99 helena HPUX 11 CC port.
|
||||
// 03/06/01 synwee Modified compareTo, to handle the result of
|
||||
// 03/06/01 synwee Modified compareTo, to handle the result of
|
||||
// 2 string similar in contents, but one is longer
|
||||
// than the other
|
||||
//===============================================================================
|
||||
|
||||
#ifndef _SORTKEY
|
||||
#include "unicode/sortkey.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CMEMORY
|
||||
#include "cmemory.h"
|
||||
#endif
|
||||
|
||||
#include "uhash.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
@ -42,8 +36,8 @@ U_NAMESPACE_BEGIN
|
||||
// A hash code of kInvalidHashCode indicates that the has code needs
|
||||
// to be computed. A hash code of kEmptyHashCode is used for empty keys
|
||||
// and for any key whose computed hash code is kInvalidHashCode.
|
||||
const int32_t CollationKey::kInvalidHashCode = 0;
|
||||
const int32_t CollationKey::kEmptyHashCode = 1;
|
||||
#define kInvalidHashCode ((int32_t)0)
|
||||
#define kEmptyHashCode ((int32_t)1)
|
||||
|
||||
CollationKey::CollationKey()
|
||||
: fBogus(FALSE), fCount(0), fCapacity(0),
|
||||
@ -110,7 +104,7 @@ void CollationKey::adopt(uint8_t *values, int32_t count) {
|
||||
// set the key to an empty state
|
||||
CollationKey&
|
||||
CollationKey::reset()
|
||||
{
|
||||
{
|
||||
fCount = 0;
|
||||
fBogus = FALSE;
|
||||
fHashCode = kEmptyHashCode;
|
||||
@ -180,76 +174,76 @@ CollationKey::operator=(const CollationKey& other)
|
||||
Collator::EComparisonResult
|
||||
CollationKey::compareTo(const CollationKey& target) const
|
||||
{
|
||||
uint8_t *src = this->fBytes;
|
||||
uint8_t *tgt = target.fBytes;
|
||||
uint8_t *src = this->fBytes;
|
||||
uint8_t *tgt = target.fBytes;
|
||||
|
||||
// are we comparing the same string
|
||||
if (src == tgt)
|
||||
return Collator::EQUAL;
|
||||
// are we comparing the same string
|
||||
if (src == tgt)
|
||||
return Collator::EQUAL;
|
||||
|
||||
/*
|
||||
int count = (this->fCount < target.fCount) ? this->fCount : target.fCount;
|
||||
if (count == 0)
|
||||
{
|
||||
// If count is 0, at least one of the keys is empty.
|
||||
// An empty key is always LESS than a non-empty one
|
||||
// and EQUAL to another empty
|
||||
if (this->fCount < target.fCount)
|
||||
{
|
||||
return Collator::LESS;
|
||||
}
|
||||
|
||||
if (this->fCount > target.fCount)
|
||||
{
|
||||
return Collator::GREATER;
|
||||
}
|
||||
return Collator::EQUAL;
|
||||
}
|
||||
*/
|
||||
|
||||
int minLength;
|
||||
Collator::EComparisonResult result;
|
||||
|
||||
// are we comparing different lengths?
|
||||
if (this->fCount != target.fCount) {
|
||||
if (this->fCount < target.fCount) {
|
||||
minLength = this->fCount;
|
||||
result = Collator::LESS;
|
||||
}
|
||||
else {
|
||||
minLength = target.fCount;
|
||||
result = Collator::GREATER;
|
||||
}
|
||||
}
|
||||
else {
|
||||
minLength = target.fCount;
|
||||
result = Collator::EQUAL;
|
||||
}
|
||||
|
||||
if (minLength > 0) {
|
||||
int diff = uprv_memcmp(src, tgt, minLength);
|
||||
if (diff > 0) {
|
||||
return Collator::GREATER;
|
||||
}
|
||||
else
|
||||
if (diff < 0) {
|
||||
/*
|
||||
int count = (this->fCount < target.fCount) ? this->fCount : target.fCount;
|
||||
if (count == 0)
|
||||
{
|
||||
// If count is 0, at least one of the keys is empty.
|
||||
// An empty key is always LESS than a non-empty one
|
||||
// and EQUAL to another empty
|
||||
if (this->fCount < target.fCount)
|
||||
{
|
||||
return Collator::LESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
/*
|
||||
if (result < 0)
|
||||
{
|
||||
if (this->fCount > target.fCount)
|
||||
{
|
||||
return Collator::GREATER;
|
||||
}
|
||||
return Collator::EQUAL;
|
||||
}
|
||||
*/
|
||||
|
||||
int minLength;
|
||||
Collator::EComparisonResult result;
|
||||
|
||||
// are we comparing different lengths?
|
||||
if (this->fCount != target.fCount) {
|
||||
if (this->fCount < target.fCount) {
|
||||
minLength = this->fCount;
|
||||
result = Collator::LESS;
|
||||
}
|
||||
else {
|
||||
minLength = target.fCount;
|
||||
result = Collator::GREATER;
|
||||
}
|
||||
}
|
||||
else {
|
||||
minLength = target.fCount;
|
||||
result = Collator::EQUAL;
|
||||
}
|
||||
|
||||
if (minLength > 0) {
|
||||
int diff = uprv_memcmp(src, tgt, minLength);
|
||||
if (diff > 0) {
|
||||
return Collator::GREATER;
|
||||
}
|
||||
else
|
||||
if (diff < 0) {
|
||||
return Collator::LESS;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
/*
|
||||
if (result < 0)
|
||||
{
|
||||
return Collator::LESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (result > 0)
|
||||
{
|
||||
return Collator::GREATER;
|
||||
}
|
||||
return Collator::EQUAL;
|
||||
*/
|
||||
if (result > 0)
|
||||
{
|
||||
return Collator::GREATER;
|
||||
}
|
||||
return Collator::EQUAL;
|
||||
*/
|
||||
}
|
||||
|
||||
CollationKey&
|
||||
@ -276,13 +270,13 @@ CollationKey::ensureCapacity(int32_t newSize)
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Create a copy of the byte array.
|
||||
uint8_t*
|
||||
CollationKey::toByteArray(int32_t& count) const
|
||||
{
|
||||
uint8_t *result = new uint8_t[fCount];
|
||||
|
||||
uint8_t *result = (uint8_t*) uprv_malloc( sizeof(uint8_t) * fCount );
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
count = 0;
|
||||
@ -293,7 +287,7 @@ CollationKey::toByteArray(int32_t& count) const
|
||||
uprv_memcpy(result, fBytes, fCount);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t
|
||||
@ -323,7 +317,7 @@ CollationKey::hashCode() const
|
||||
|
||||
while (p < limit)
|
||||
{
|
||||
hash = ( hash * 37 ) + ((p[0] << 8) + p[1]);
|
||||
hash = ( hash * 37 ) + ((p[0] << 8) + p[1]);
|
||||
p += inc;
|
||||
}
|
||||
|
||||
|
@ -142,8 +142,9 @@ UMatchDegree StringMatcher::matches(const Replaceable& text,
|
||||
* Implement UnicodeMatcher
|
||||
*/
|
||||
UnicodeString& StringMatcher::toPattern(UnicodeString& result,
|
||||
UBool escapeUnprintable) const {
|
||||
result.truncate(0);
|
||||
UBool escapeUnprintable) const
|
||||
{
|
||||
result.truncate(0);
|
||||
UnicodeString str, quoteBuf;
|
||||
if (segmentNumber > 0) {
|
||||
result.append((UChar)40); /*(*/
|
||||
|
@ -266,17 +266,17 @@ CollationElementIterator* RuleBasedCollator::createCollationElementIterator
|
||||
*/
|
||||
const UnicodeString& RuleBasedCollator::getRules() const
|
||||
{
|
||||
return (*urulestring);
|
||||
return (*urulestring);
|
||||
}
|
||||
|
||||
void RuleBasedCollator::getRules(UColRuleOption delta, UnicodeString &buffer)
|
||||
{
|
||||
UChar *rules = NULL;
|
||||
int rulesize = ucol_getRulesEx(ucollator, delta, rules, -1);
|
||||
rules = new UChar[rulesize];
|
||||
int rulesize = ucol_getRulesEx(ucollator, delta, NULL, -1);
|
||||
UChar *rules = (UChar*) uprv_malloc( sizeof(UChar) * (rulesize) );
|
||||
|
||||
ucol_getRulesEx(ucollator, delta, rules, rulesize);
|
||||
buffer.setTo(rules, rulesize);
|
||||
delete rules;
|
||||
uprv_free(rules);
|
||||
}
|
||||
|
||||
Collator::EComparisonResult RuleBasedCollator::compare(
|
||||
|
@ -713,10 +713,11 @@ static const UChar TRANSLITERATE[] = {84,114,97,110,115,108,105,116,101,114,97,1
|
||||
Entry* TransliteratorRegistry::findInBundle(const Spec& specToOpen,
|
||||
const Spec& specToFind,
|
||||
const UnicodeString& variant,
|
||||
UTransDirection direction) {
|
||||
UTransDirection direction)
|
||||
{
|
||||
UnicodeString utag;
|
||||
UnicodeString resStr;
|
||||
int32_t pass;
|
||||
int32_t pass;
|
||||
|
||||
for (pass=0; pass<2; ++pass) {
|
||||
utag.truncate(0);
|
||||
|
@ -2194,7 +2194,7 @@ uint32_t ucol_prv_getSpecialCE(const UCollator *coll, UChar ch, uint32_t CE, col
|
||||
return UTRIE_GET32_FROM_LEAD(UCA->mapping, L);
|
||||
|
||||
} else { // Jamo is Special
|
||||
// Since Hanguls pass the FCD check, it is
|
||||
// Since Hanguls pass the FCD check, it is
|
||||
// guaranteed that we won't be in
|
||||
// the normalization buffer if something like this happens
|
||||
// Move Jamos into normalization buffer
|
||||
@ -2760,7 +2760,7 @@ uint32_t ucol_prv_getSpecialPrevCE(const UCollator *coll, UChar ch, uint32_t CE,
|
||||
source->toReturn = source->CEpos - 1;
|
||||
return *(source->toReturn);
|
||||
} else {
|
||||
// Since Hanguls pass the FCD check, it is
|
||||
// Since Hanguls pass the FCD check, it is
|
||||
// guaranteed that we won't be in
|
||||
// the normalization buffer if something like this happens
|
||||
// Move Jamos into normalization buffer
|
||||
|
@ -137,7 +137,7 @@ uprv_cnttab_constructTable(CntTable *table, uint32_t mainOffset, UErrorCode *sta
|
||||
table->position = 0;
|
||||
|
||||
if(table->offsets != NULL) {
|
||||
free(table->offsets);
|
||||
uprv_free(table->offsets);
|
||||
}
|
||||
table->offsets = (int32_t *)uprv_malloc(table->size*sizeof(int32_t));
|
||||
if(table->offsets == NULL) {
|
||||
@ -292,15 +292,15 @@ U_CAPI void U_EXPORT2
|
||||
uprv_cnttab_close(CntTable *table) {
|
||||
int32_t i = 0;
|
||||
for(i = 0; i<table->size; i++) {
|
||||
free(table->elements[i]->CEs);
|
||||
free(table->elements[i]->codePoints);
|
||||
free(table->elements[i]);
|
||||
uprv_free(table->elements[i]->CEs);
|
||||
uprv_free(table->elements[i]->codePoints);
|
||||
uprv_free(table->elements[i]);
|
||||
}
|
||||
free(table->elements);
|
||||
free(table->CEs);
|
||||
free(table->offsets);
|
||||
free(table->codePoints);
|
||||
free(table);
|
||||
uprv_free(table->elements);
|
||||
uprv_free(table->CEs);
|
||||
uprv_free(table->offsets);
|
||||
uprv_free(table->codePoints);
|
||||
uprv_free(table);
|
||||
}
|
||||
|
||||
/* this is for adding non contractions */
|
||||
|
@ -43,7 +43,7 @@ struct ContractionTable {
|
||||
};
|
||||
|
||||
struct CntTable {
|
||||
ContractionTable **elements;
|
||||
ContractionTable **elements;
|
||||
/*CompactEIntArray *mapping;*/
|
||||
UNewTrie *mapping;
|
||||
UChar *codePoints;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "ucol_elm.h"
|
||||
#include "unicode/uchar.h"
|
||||
#include "unormimp.h"
|
||||
#include "cmemory.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
@ -89,13 +90,13 @@ static int32_t uprv_uca_addExpansion(ExpansionTable *expansions, uint32_t value,
|
||||
return 0;
|
||||
}
|
||||
if(expansions->CEs == NULL) {
|
||||
expansions->CEs = (uint32_t *)malloc(INIT_EXP_TABLE_SIZE*sizeof(uint32_t));
|
||||
expansions->CEs = (uint32_t *)uprv_malloc(INIT_EXP_TABLE_SIZE*sizeof(uint32_t));
|
||||
expansions->size = INIT_EXP_TABLE_SIZE;
|
||||
expansions->position = 0;
|
||||
}
|
||||
|
||||
if(expansions->position == expansions->size) {
|
||||
uint32_t *newData = (uint32_t *)realloc(expansions->CEs, 2*expansions->size*sizeof(uint32_t));
|
||||
uint32_t *newData = (uint32_t *)uprv_realloc(expansions->CEs, 2*expansions->size*sizeof(uint32_t));
|
||||
if(newData == NULL) {
|
||||
#ifdef UCOL_DEBUG
|
||||
fprintf(stderr, "out of memory for expansions\n");
|
||||
@ -1177,7 +1178,7 @@ uprv_uca_assembleTable(tempUCATable *t, UErrorCode *status) {
|
||||
paddedsize(UCOL_UNSAFECP_TABLE_SIZE)); /* Contraction Ending chars */
|
||||
|
||||
|
||||
dataStart = (uint8_t *)malloc(toAllocate);
|
||||
dataStart = (uint8_t *)uprv_malloc(toAllocate);
|
||||
|
||||
UCATableHeader *myData = (UCATableHeader *)dataStart;
|
||||
uprv_memcpy(myData, t->image, sizeof(UCATableHeader));
|
||||
@ -1200,7 +1201,7 @@ uprv_uca_assembleTable(tempUCATable *t, UErrorCode *status) {
|
||||
tableOffset += (uint32_t)(paddedsize(sizeof(UCATableHeader)));
|
||||
|
||||
myData->options = tableOffset;
|
||||
memcpy(dataStart+tableOffset, t->options, sizeof(UColOptionSet));
|
||||
uprv_memcpy(dataStart+tableOffset, t->options, sizeof(UColOptionSet));
|
||||
tableOffset += (uint32_t)(paddedsize(sizeof(UColOptionSet)));
|
||||
|
||||
/* copy expansions */
|
||||
@ -1299,7 +1300,7 @@ uprv_uca_assembleTable(tempUCATable *t, UErrorCode *status) {
|
||||
fprintf(stderr, "calculation screwup!!! Expected to write %i but wrote %i instead!!!\n", toAllocate, tableOffset);
|
||||
#endif
|
||||
*status = U_INTERNAL_PROGRAM_ERROR;
|
||||
free(dataStart);
|
||||
uprv_free(dataStart);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,9 @@
|
||||
#include "ucol_cnt.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "ucol_imp.h"
|
||||
#include "cmemory.h"
|
||||
|
||||
#ifdef UCOL_DEBUG
|
||||
#include "cmemory.h"
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
|
@ -104,7 +104,7 @@ void ucol_tok_initTokenList(UColTokenParser *src, const UChar *rules, const uint
|
||||
nSize = unorm_normalize(rules, rulesLength, UNORM_NFD, 0, src->source, estimatedSize, status);
|
||||
if(nSize > estimatedSize || *status == U_BUFFER_OVERFLOW_ERROR) {
|
||||
*status = U_ZERO_ERROR;
|
||||
src->source = (UChar *)realloc(src->source, (nSize+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar));
|
||||
src->source = (UChar *)uprv_realloc(src->source, (nSize+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar));
|
||||
nSize = unorm_normalize(rules, rulesLength, UNORM_NFD, 0, src->source, nSize+UCOL_TOK_EXTRA_RULE_SPACE_SIZE, status);
|
||||
}
|
||||
src->current = src->source;
|
||||
@ -920,7 +920,7 @@ uint32_t ucol_tok_assembleTokenList(UColTokenParser *src, UParseError *parseErro
|
||||
sourceToken->listHeader = lastToken->listHeader;
|
||||
|
||||
/*
|
||||
1. Find the strongest strength in each list, and set strongestP and strongestN
|
||||
1. Find the strongest strength in each list, and set strongestP and strongestN
|
||||
accordingly in the headers.
|
||||
*/
|
||||
if(lastStrength == UCOL_TOK_RESET
|
||||
|
@ -125,7 +125,7 @@ udat_open(UDateFormatStyle timeStyle,
|
||||
TimeZone *zone = 0;
|
||||
int32_t length = (tzIDLength == -1 ? u_strlen(tzID) : tzIDLength);
|
||||
zone = TimeZone::createTimeZone(UnicodeString((UChar*)tzID,
|
||||
length, length));
|
||||
length, length));
|
||||
if(zone == 0) {
|
||||
*status = U_MEMORY_ALLOCATION_ERROR;
|
||||
delete fmt;
|
||||
|
@ -391,8 +391,8 @@ public:
|
||||
*/
|
||||
virtual CollationKey& getCollationKey(const UChar*source,
|
||||
int32_t sourceLength,
|
||||
CollationKey& key,
|
||||
UErrorCode& status) const = 0;
|
||||
CollationKey& key,
|
||||
UErrorCode& status) const = 0;
|
||||
/**
|
||||
* Generates the hash code for the collation object
|
||||
* @stable
|
||||
@ -606,8 +606,9 @@ public:
|
||||
* @return Number of bytes needed for storing the sort key
|
||||
* @draft ICU 1.8
|
||||
*/
|
||||
virtual int32_t getSortKey(const UnicodeString& source, uint8_t* result,
|
||||
int32_t resultLength) const = 0;
|
||||
virtual int32_t getSortKey(const UnicodeString& source,
|
||||
uint8_t* result,
|
||||
int32_t resultLength) const = 0;
|
||||
|
||||
/**
|
||||
* Get the sort key as an array of bytes from an UChar buffer.
|
||||
@ -625,7 +626,8 @@ public:
|
||||
* @draft ICU 1.8
|
||||
*/
|
||||
virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
|
||||
uint8_t*result, int32_t resultLength) const = 0;
|
||||
uint8_t*result, int32_t resultLength) const = 0;
|
||||
|
||||
// start deprecated APIs
|
||||
/**
|
||||
* Get the decomposition mode of the Collator object.
|
||||
|
@ -21,10 +21,10 @@ class NFRuleSet;
|
||||
|
||||
/** Tags for the predefined rulesets. */
|
||||
enum URBNFRuleSetTag {
|
||||
URBNF_SPELLOUT,
|
||||
URBNF_ORDINAL,
|
||||
URBNF_DURATION,
|
||||
URBNF_COUNT
|
||||
URBNF_SPELLOUT,
|
||||
URBNF_ORDINAL,
|
||||
URBNF_DURATION,
|
||||
URBNF_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
@ -507,7 +507,7 @@ public:
|
||||
* @draft ICU 2.0
|
||||
*/
|
||||
RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
|
||||
UParseError& perror, UErrorCode& status);
|
||||
UParseError& perror, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a RuleBasedNumberFormat from a predefined ruleset. The selector
|
||||
@ -688,7 +688,7 @@ public:
|
||||
* @draft ICU 2.0
|
||||
*/
|
||||
virtual void parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
Formattable& result,
|
||||
ParsePosition& parsePosition) const;
|
||||
|
||||
|
||||
@ -784,12 +784,13 @@ private:
|
||||
inline UnicodeString&
|
||||
RuleBasedNumberFormat::format(const Formattable& obj,
|
||||
UnicodeString& result,
|
||||
UErrorCode& status) const {
|
||||
UErrorCode& status) const
|
||||
{
|
||||
// Don't use Format:: - use immediate base class only,
|
||||
// in case immediate base modifies behavior later.
|
||||
// dlf - the above comment is bogus, if there were a reason to modify
|
||||
// it, it would be virtual, and there's no reason because it is
|
||||
// a one-line macro in NumberFormat anyway, just like this one.
|
||||
// dlf - the above comment is bogus, if there were a reason to modify
|
||||
// it, it would be virtual, and there's no reason because it is
|
||||
// a one-line macro in NumberFormat anyway, just like this one.
|
||||
return NumberFormat::format(obj, result, status);
|
||||
}
|
||||
|
||||
@ -806,18 +807,19 @@ RuleBasedNumberFormat::format(int32_t number, UnicodeString& output) const {
|
||||
}
|
||||
|
||||
inline void
|
||||
RuleBasedNumberFormat::parse(const UnicodeString& text, Formattable& result, UErrorCode& status) const {
|
||||
NumberFormat::parse(text, result, status);
|
||||
RuleBasedNumberFormat::parse(const UnicodeString& text, Formattable& result, UErrorCode& status) const
|
||||
{
|
||||
NumberFormat::parse(text, result, status);
|
||||
}
|
||||
|
||||
inline UBool
|
||||
RuleBasedNumberFormat::isLenient(void) const {
|
||||
return lenient;
|
||||
return lenient;
|
||||
}
|
||||
|
||||
inline NFRuleSet*
|
||||
RuleBasedNumberFormat::getDefaultRuleSet() const {
|
||||
return defaultRuleSet;
|
||||
return defaultRuleSet;
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
@ -87,118 +87,120 @@ class RuleBasedCollator;
|
||||
class U_I18N_API CollationKey {
|
||||
public:
|
||||
/**
|
||||
* This creates an empty collation key based on the null string. An empty
|
||||
* collation key contains no sorting information. When comparing two empty
|
||||
* collation keys, the result is Collator::EQUAL. Comparing empty collation key
|
||||
* with non-empty collation key is always Collator::LESS.
|
||||
* @stable
|
||||
*/
|
||||
CollationKey();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a collation key based on the collation key values.
|
||||
* @param values the collation key values
|
||||
* @param count number of collation key values, including trailing nulls.
|
||||
* @see #createBits
|
||||
* @stable
|
||||
*/
|
||||
CollationKey(const uint8_t* values,
|
||||
int32_t count);
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable
|
||||
*/
|
||||
CollationKey(const CollationKey& other);
|
||||
/**
|
||||
* Sort key destructor.
|
||||
* @stable
|
||||
*/
|
||||
~CollationKey();
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @stable
|
||||
*/
|
||||
const CollationKey& operator=(const CollationKey& other);
|
||||
|
||||
/**
|
||||
* Compare if two collation keys are the same.
|
||||
* @param source the collation key to compare to.
|
||||
* @return Returns true if two collation keys are equal, false otherwise.
|
||||
* @stable
|
||||
*/
|
||||
UBool operator==(const CollationKey& source) const;
|
||||
|
||||
/**
|
||||
* Compare if two collation keys are not the same.
|
||||
* @param source the collation key to compare to.
|
||||
* @return Returns TRUE if two collation keys are different, FALSE otherwise.
|
||||
* @stable
|
||||
*/
|
||||
UBool operator!=(const CollationKey& source) const;
|
||||
* This creates an empty collation key based on the null string. An empty
|
||||
* collation key contains no sorting information. When comparing two empty
|
||||
* collation keys, the result is Collator::EQUAL. Comparing empty collation key
|
||||
* with non-empty collation key is always Collator::LESS.
|
||||
* @stable
|
||||
*/
|
||||
CollationKey();
|
||||
|
||||
|
||||
/**
|
||||
* Test to see if the key is in an invalid state. The key will be in an
|
||||
* invalid state if it couldn't allocate memory for some operation.
|
||||
* @return Returns TRUE if the key is in an invalid, FALSE otherwise.
|
||||
* @stable
|
||||
*/
|
||||
UBool isBogus(void) const;
|
||||
* Creates a collation key based on the collation key values.
|
||||
* @param values the collation key values
|
||||
* @param count number of collation key values, including trailing nulls.
|
||||
* @see #createBits
|
||||
* @stable
|
||||
*/
|
||||
CollationKey(const uint8_t* values,
|
||||
int32_t count);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the collation key values. The storage is owned
|
||||
* by the collation key and the pointer will become invalid if the key
|
||||
* is deleted.
|
||||
* @param count the output parameter of number of collation key values,
|
||||
* including any trailing nulls.
|
||||
* @stable
|
||||
*/
|
||||
const uint8_t* getByteArray(int32_t& count) const;
|
||||
* Copy constructor.
|
||||
* @stable
|
||||
*/
|
||||
CollationKey(const CollationKey& other);
|
||||
|
||||
/**
|
||||
* Extracts the collation key values into a new array. The caller owns
|
||||
* this storage and should free it.
|
||||
* @param count the output parameter of number of collation key values,
|
||||
* including any trailing nulls.
|
||||
* @stable
|
||||
*/
|
||||
uint8_t* toByteArray(int32_t& count) const;
|
||||
* Sort key destructor.
|
||||
* @stable
|
||||
*/
|
||||
~CollationKey();
|
||||
|
||||
/**
|
||||
* Convenience method which does a string(bit-wise) comparison of the
|
||||
* two collation keys.
|
||||
* @param sourceKey source collation key
|
||||
* @param targetKey target collation key
|
||||
* @return Returns Collator::LESS if sourceKey < targetKey,
|
||||
* Collator::GREATER if sourceKey > targetKey and Collator::EQUAL
|
||||
* otherwise.
|
||||
* @stable
|
||||
*/
|
||||
Collator::EComparisonResult compareTo(const CollationKey& target) const;
|
||||
* Assignment operator
|
||||
* @stable
|
||||
*/
|
||||
const CollationKey& operator=(const CollationKey& other);
|
||||
|
||||
/**
|
||||
* Creates an integer that is unique to the collation key. NOTE: this
|
||||
* is not the same as String.hashCode.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . UErrorCode status = U_ZERO_ERROR;
|
||||
* . Collator *myCollation = Collator::createInstance(Locale::US, status);
|
||||
* . if (U_FAILURE(status)) return;
|
||||
* . CollationKey key1, key2;
|
||||
* . UErrorCode status1 = U_ZERO_ERROR, status2 = U_ZERO_ERROR;
|
||||
* . myCollation->getCollationKey("abc", key1, status1);
|
||||
* . if (U_FAILURE(status1)) { delete myCollation; return; }
|
||||
* . myCollation->getCollationKey("ABC", key2, status2);
|
||||
* . if (U_FAILURE(status2)) { delete myCollation; return; }
|
||||
* . // key1.hashCode() != key2.hashCode()
|
||||
* </pre>
|
||||
* @return the hash value based on the string's collation order.
|
||||
* @see UnicodeString#hashCode
|
||||
* @stable
|
||||
*/
|
||||
int32_t hashCode(void) const;
|
||||
* Compare if two collation keys are the same.
|
||||
* @param source the collation key to compare to.
|
||||
* @return Returns true if two collation keys are equal, false otherwise.
|
||||
* @stable
|
||||
*/
|
||||
UBool operator==(const CollationKey& source) const;
|
||||
|
||||
/**
|
||||
* Compare if two collation keys are not the same.
|
||||
* @param source the collation key to compare to.
|
||||
* @return Returns TRUE if two collation keys are different, FALSE otherwise.
|
||||
* @stable
|
||||
*/
|
||||
UBool operator!=(const CollationKey& source) const;
|
||||
|
||||
|
||||
/**
|
||||
* Test to see if the key is in an invalid state. The key will be in an
|
||||
* invalid state if it couldn't allocate memory for some operation.
|
||||
* @return Returns TRUE if the key is in an invalid, FALSE otherwise.
|
||||
* @stable
|
||||
*/
|
||||
UBool isBogus(void) const;
|
||||
|
||||
/**
|
||||
* Returns a pointer to the collation key values. The storage is owned
|
||||
* by the collation key and the pointer will become invalid if the key
|
||||
* is deleted.
|
||||
* @param count the output parameter of number of collation key values,
|
||||
* including any trailing nulls.
|
||||
* @stable
|
||||
*/
|
||||
const uint8_t* getByteArray(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Extracts the collation key values into a new array. The caller owns
|
||||
* this storage and should free it.
|
||||
* @param count the output parameter of number of collation key values,
|
||||
* including any trailing nulls.
|
||||
* @stable
|
||||
*/
|
||||
uint8_t* toByteArray(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Convenience method which does a string(bit-wise) comparison of the
|
||||
* two collation keys.
|
||||
* @param sourceKey source collation key
|
||||
* @param targetKey target collation key
|
||||
* @return Returns Collator::LESS if sourceKey < targetKey,
|
||||
* Collator::GREATER if sourceKey > targetKey and Collator::EQUAL
|
||||
* otherwise.
|
||||
* @stable
|
||||
*/
|
||||
Collator::EComparisonResult compareTo(const CollationKey& target) const;
|
||||
|
||||
/**
|
||||
* Creates an integer that is unique to the collation key. NOTE: this
|
||||
* is not the same as String.hashCode.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . UErrorCode status = U_ZERO_ERROR;
|
||||
* . Collator *myCollation = Collator::createInstance(Locale::US, status);
|
||||
* . if (U_FAILURE(status)) return;
|
||||
* . CollationKey key1, key2;
|
||||
* . UErrorCode status1 = U_ZERO_ERROR, status2 = U_ZERO_ERROR;
|
||||
* . myCollation->getCollationKey("abc", key1, status1);
|
||||
* . if (U_FAILURE(status1)) { delete myCollation; return; }
|
||||
* . myCollation->getCollationKey("ABC", key2, status2);
|
||||
* . if (U_FAILURE(status2)) { delete myCollation; return; }
|
||||
* . // key1.hashCode() != key2.hashCode()
|
||||
* </pre>
|
||||
* @return the hash value based on the string's collation order.
|
||||
* @see UnicodeString#hashCode
|
||||
* @stable
|
||||
*/
|
||||
int32_t hashCode(void) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
@ -207,25 +209,22 @@ private:
|
||||
* @param size output parameter of the number of collation key values
|
||||
* @return a pointer to an array of 16-bit collation key values.
|
||||
*/
|
||||
void adopt(uint8_t *values, int32_t count);
|
||||
void adopt(uint8_t *values, int32_t count);
|
||||
|
||||
/*
|
||||
* Creates a collation key with a string.
|
||||
*/
|
||||
CollationKey& ensureCapacity(int32_t newSize);
|
||||
CollationKey& setToBogus(void);
|
||||
CollationKey& reset(void);
|
||||
* Creates a collation key with a string.
|
||||
*/
|
||||
CollationKey& ensureCapacity(int32_t newSize);
|
||||
CollationKey& setToBogus(void);
|
||||
CollationKey& reset(void);
|
||||
|
||||
friend class RuleBasedCollator;
|
||||
friend class RuleBasedCollator;
|
||||
|
||||
static const int32_t kInvalidHashCode;
|
||||
static const int32_t kEmptyHashCode;
|
||||
|
||||
UBool fBogus;
|
||||
int32_t fCount;
|
||||
int32_t fCapacity;
|
||||
int32_t fHashCode;
|
||||
uint8_t* fBytes;
|
||||
UBool fBogus;
|
||||
int32_t fCount;
|
||||
int32_t fCapacity;
|
||||
int32_t fHashCode;
|
||||
uint8_t* fBytes;
|
||||
};
|
||||
|
||||
inline UBool
|
||||
|
@ -150,7 +150,7 @@ UnicodeSet::UnicodeSet() :
|
||||
len(1), capacity(1 + START_EXTRA), bufferCapacity(0),
|
||||
buffer(0)
|
||||
{
|
||||
list = new UChar32[capacity];
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
list[0] = UNICODESET_HIGH;
|
||||
_dbgct(this);
|
||||
}
|
||||
@ -166,7 +166,7 @@ UnicodeSet::UnicodeSet(UChar32 start, UChar32 end) :
|
||||
len(1), capacity(1 + START_EXTRA), bufferCapacity(0),
|
||||
buffer(0)
|
||||
{
|
||||
list = new UChar32[capacity];
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
list[0] = UNICODESET_HIGH;
|
||||
complement(start, end);
|
||||
_dbgct(this);
|
||||
@ -183,7 +183,7 @@ UnicodeSet::UnicodeSet(const UnicodeString& pattern,
|
||||
len(0), capacity(START_EXTRA), bufferCapacity(0),
|
||||
buffer(0)
|
||||
{
|
||||
list = new UChar32[capacity];
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
applyPattern(pattern, status);
|
||||
_dbgct(this);
|
||||
}
|
||||
@ -195,7 +195,7 @@ UnicodeSet::UnicodeSet(const UnicodeString& pattern, ParsePosition& pos,
|
||||
len(0), capacity(START_EXTRA), bufferCapacity(0),
|
||||
buffer(0)
|
||||
{
|
||||
list = new UChar32[capacity];
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
applyPattern(pattern, pos, &symbols, status);
|
||||
_dbgct(this);
|
||||
}
|
||||
@ -206,7 +206,7 @@ UnicodeSet::UnicodeSet(const UnicodeString& pattern, ParsePosition& pos,
|
||||
len(0), capacity(START_EXTRA), bufferCapacity(0),
|
||||
buffer(0)
|
||||
{
|
||||
list = new UChar32[capacity];
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
applyPattern(pattern, pos, NULL, status);
|
||||
_dbgct(this);
|
||||
}
|
||||
@ -230,7 +230,7 @@ UnicodeSet::UnicodeSet(int8_t category, UErrorCode& status) :
|
||||
UnicodeString pattern(FALSE, CATEGORY_NAMES + category*2, 2);
|
||||
pattern.insert(0, OPEN);
|
||||
pattern.append(CLOSE);
|
||||
list = new UChar32[capacity];
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
applyPattern(pattern, status);
|
||||
}
|
||||
}
|
||||
@ -245,7 +245,7 @@ UnicodeSet::UnicodeSet(const UnicodeSet& o) :
|
||||
capacity(o.len + GROW_EXTRA), bufferCapacity(0),
|
||||
buffer(0)
|
||||
{
|
||||
list = new UChar32[capacity];
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
*this = o;
|
||||
_dbgct(this);
|
||||
}
|
||||
@ -255,8 +255,8 @@ UnicodeSet::UnicodeSet(const UnicodeSet& o) :
|
||||
*/
|
||||
UnicodeSet::~UnicodeSet() {
|
||||
_dbgdt(this); // first!
|
||||
delete[] list;
|
||||
delete[] buffer;
|
||||
uprv_free(list);
|
||||
uprv_free(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -925,12 +925,12 @@ UChar32 UnicodeSet::getRangeEnd(int32_t index) const {
|
||||
void UnicodeSet::compact() {
|
||||
if (len != capacity) {
|
||||
capacity = len;
|
||||
UChar32* temp = new UChar32[capacity];
|
||||
UChar32* temp = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
uprv_memcpy(temp, list, len*sizeof(UChar32));
|
||||
delete[] list;
|
||||
uprv_free(list);
|
||||
list = temp;
|
||||
}
|
||||
delete[] buffer;
|
||||
uprv_free(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
@ -1402,19 +1402,21 @@ void UnicodeSet::_applyPattern(const UnicodeString& pattern,
|
||||
//----------------------------------------------------------------
|
||||
|
||||
void UnicodeSet::ensureCapacity(int32_t newLen) {
|
||||
if (newLen <= capacity) return;
|
||||
if (newLen <= capacity)
|
||||
return;
|
||||
capacity = newLen + GROW_EXTRA;
|
||||
UChar32* temp = new UChar32[capacity];
|
||||
UChar32* temp = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
uprv_memcpy(temp, list, len*sizeof(UChar32));
|
||||
delete[] list;
|
||||
uprv_free(list);
|
||||
list = temp;
|
||||
}
|
||||
|
||||
void UnicodeSet::ensureBufferCapacity(int32_t newLen) {
|
||||
if (buffer != NULL && newLen <= bufferCapacity) return;
|
||||
delete[] buffer;
|
||||
if (buffer != NULL && newLen <= bufferCapacity)
|
||||
return;
|
||||
uprv_free(buffer);
|
||||
bufferCapacity = newLen + GROW_EXTRA;
|
||||
buffer = new UChar32[bufferCapacity];
|
||||
buffer = (UChar32*) uprv_malloc(sizeof(UChar32) * bufferCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,7 +137,7 @@ unum_open( UNumberFormatStyle style,
|
||||
break;
|
||||
|
||||
case UNUM_SPELLOUT:
|
||||
return (UNumberFormat*)new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale(locale), *status);
|
||||
return (UNumberFormat*)new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale(locale), *status);
|
||||
|
||||
default:
|
||||
*status = U_UNSUPPORTED_ERROR;
|
||||
@ -151,7 +151,7 @@ unum_open( UNumberFormatStyle style,
|
||||
|
||||
return retVal;
|
||||
}else{
|
||||
/* we don't support RBNF patterns yet */
|
||||
/* we don't support RBNF patterns yet */
|
||||
UParseError tErr;
|
||||
int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
|
||||
const UnicodeString pat((UChar*)pattern, len, len);
|
||||
|
@ -76,7 +76,7 @@ ReplaceableGlue::ReplaceableGlue(UReplaceable *replaceable,
|
||||
}
|
||||
|
||||
ReplaceableGlue::~ReplaceableGlue() {
|
||||
delete[] buf;
|
||||
uprv_free(buf);
|
||||
}
|
||||
|
||||
int32_t ReplaceableGlue::getLength() const {
|
||||
@ -96,9 +96,9 @@ void ReplaceableGlue::handleReplaceBetween(UTextOffset start,
|
||||
const UnicodeString& text) {
|
||||
int32_t len = text.length();
|
||||
if (buf == 0 || bufLen < len) {
|
||||
delete[] buf;
|
||||
uprv_free(buf);
|
||||
bufLen = len + BUF_PAD;
|
||||
buf = new UChar[bufLen];
|
||||
buf = (UChar*) uprv_malloc(sizeof(UChar) * bufLen);
|
||||
}
|
||||
text.extract(0, len, buf);
|
||||
(*func->replace)(rep, start, limit, buf, len);
|
||||
|
@ -1,8 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1998-2000, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************/
|
||||
#error This file is obsolete! Use icu\source\extra\ustdio\ufile.c instead!
|
@ -1,8 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1998-2000, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************/
|
||||
#error This file is obsolete! Use icu\source\extra\ustdio\ustdio.c instead!
|
@ -322,7 +322,7 @@ void gentz::fixupNameToEquiv() {
|
||||
uint32_t i;
|
||||
|
||||
// First make a list that maps indices to offsets
|
||||
uint32_t *offsets = new uint32_t[equivCount];
|
||||
uint32_t *offsets = (uint32_t*) uprv_malloc(sizeof(uint32_t) * equivCount);
|
||||
offsets[0] = header.equivTableDelta;
|
||||
if (offsets[0] % 4 != 0) {
|
||||
die("Header size is not 4-aligned");
|
||||
@ -345,7 +345,7 @@ void gentz::fixupNameToEquiv() {
|
||||
nameToEquiv[i] = offsets[x];
|
||||
}
|
||||
|
||||
delete[] offsets;
|
||||
uprv_free(offsets);
|
||||
}
|
||||
|
||||
TZEquivalencyGroup* gentz::parseEquivTable(FileStream* in) {
|
||||
@ -376,7 +376,7 @@ TZEquivalencyGroup* gentz::parseEquivTable(FileStream* in) {
|
||||
}
|
||||
maxPossibleSize *= n; // Get size of entire set of structs.
|
||||
|
||||
int8_t *result = new int8_t[maxPossibleSize];
|
||||
int8_t *result = (int8_t*) uprv_malloc(sizeof(int8_t) * maxPossibleSize);
|
||||
if (result == 0) {
|
||||
die("Out of memory");
|
||||
}
|
||||
@ -476,7 +476,7 @@ OffsetIndex* gentz::parseOffsetIndexTable(FileStream* in) {
|
||||
uint32_t maxPossibleSize = n * (sizeof(OffsetIndex) +
|
||||
(maxPerOffset-1) * sizeof(uint16_t));
|
||||
|
||||
int8_t *result = new int8_t[maxPossibleSize];
|
||||
int8_t *result = (int8_t*) uprv_malloc(sizeof(int8_t) * maxPossibleSize);
|
||||
if (result == 0) {
|
||||
die("Out of memory");
|
||||
}
|
||||
@ -541,7 +541,7 @@ CountryIndex* gentz::parseCountryIndexTable(FileStream* in) {
|
||||
uint32_t expectedSize = n*(sizeof(CountryIndex)-sizeof(uint16_t)) +
|
||||
header.count * sizeof(uint16_t);
|
||||
uint32_t pad = (4 - (expectedSize % 4)) % 4; // This will be 0 or 2
|
||||
int8_t *result = new int8_t[expectedSize + pad];
|
||||
int8_t *result = (int8_t*) uprv_malloc(sizeof(int8_t) * (expectedSize + pad));
|
||||
if (result == 0) {
|
||||
die("Out of memory");
|
||||
}
|
||||
@ -655,8 +655,8 @@ char* gentz::parseNameTable(FileStream* in) {
|
||||
if (n != (int32_t)header.count) {
|
||||
die("Zone count doesn't match name table count");
|
||||
}
|
||||
char* names = new char[nameTableSize];
|
||||
nameToEquiv = new uint32_t[n];
|
||||
char* names = (char*) uprv_malloc(sizeof(char) * nameTableSize);
|
||||
nameToEquiv = (uint32_t*) uprv_malloc(sizeof(uint32_t) * n);
|
||||
if (names == 0 || nameToEquiv == 0) {
|
||||
die("Out of memory");
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "toolutil.h"
|
||||
#include "cstring.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "cmemory.h"
|
||||
|
||||
#ifdef XP_MAC_CONSOLE
|
||||
#include <console.h>
|
||||
@ -257,7 +257,7 @@ static InverseTableHeader *assembleInverseTable(UErrorCode *status)
|
||||
uint32_t contsByteSize = sContPos * sizeof(UChar);
|
||||
uint32_t i = 0;
|
||||
|
||||
result = (InverseTableHeader *)malloc(headerByteSize + inverseTableByteSize + contsByteSize);
|
||||
result = (InverseTableHeader *)uprv_malloc(headerByteSize + inverseTableByteSize + contsByteSize);
|
||||
if(result != NULL) {
|
||||
result->byteSize = headerByteSize + inverseTableByteSize + contsByteSize;
|
||||
|
||||
|
@ -71,7 +71,7 @@ static UBool ucbuf_autodetect_nrw(FileStream* in, const char** cp,int* numRead){
|
||||
}else if(start[0] == '\x0E' && start[1] == '\xFE' && start[2] == '\xFF'){
|
||||
*cp ="SCSU";
|
||||
signatureLength=3;
|
||||
}else if(start[0] == '\x00' && start[1] == '\x00' &&
|
||||
}else if(start[0] == '\x00' && start[1] == '\x00' &&
|
||||
start[2] == '\xFE' && start[3]=='\xFF'){
|
||||
*cp = "UTF-32BE";
|
||||
signatureLength=4;
|
||||
@ -79,27 +79,29 @@ static UBool ucbuf_autodetect_nrw(FileStream* in, const char** cp,int* numRead){
|
||||
signatureLength=0;
|
||||
autodetect=FALSE;
|
||||
}
|
||||
while(signatureLength<*numRead) {
|
||||
T_FileStream_rewind(in);
|
||||
T_FileStream_read(in, start, *numRead);
|
||||
/* while(signatureLength<*numRead) {
|
||||
T_FileStream_ungetc(start[--*numRead], in);
|
||||
}
|
||||
}*/
|
||||
return autodetect;
|
||||
}
|
||||
|
||||
/* Autodetects UTF8, UTF-16-BigEndian and UTF-16-LittleEndian BOMs*/
|
||||
U_CAPI UBool U_EXPORT2
|
||||
ucbuf_autodetect(FileStream* in,const char** cp){
|
||||
UBool autodetect = FALSE;
|
||||
int numRead =0;
|
||||
const char* tcp;
|
||||
autodetect=ucbuf_autodetect_nrw(in,&tcp, &numRead);
|
||||
*cp =tcp;
|
||||
/* rewind the file Stream */
|
||||
T_FileStream_rewind(in);
|
||||
return autodetect;
|
||||
UBool autodetect = FALSE;
|
||||
int numRead =0;
|
||||
const char* tcp;
|
||||
autodetect=ucbuf_autodetect_nrw(in,&tcp, &numRead);
|
||||
*cp =tcp;
|
||||
/* rewind the file Stream */
|
||||
T_FileStream_rewind(in);
|
||||
return autodetect;
|
||||
}
|
||||
|
||||
/* fill the uchar buffer */
|
||||
static UCHARBUF*
|
||||
static UCHARBUF*
|
||||
ucbuf_fillucbuf( UCHARBUF* buf,UErrorCode* err){
|
||||
UChar* pTarget=NULL;
|
||||
UChar* target=NULL;
|
||||
@ -118,18 +120,22 @@ ucbuf_fillucbuf( UCHARBUF* buf,UErrorCode* err){
|
||||
#if DEBUG
|
||||
memset(pTarget+offset,0xff,sizeof(UChar)*(MAX_IN_BUF-offset));
|
||||
#endif
|
||||
|
||||
|
||||
/* read the file */
|
||||
numRead=T_FileStream_read(buf->in,cbuf,MAX_IN_BUF-offset);
|
||||
buf->remaining-=numRead;
|
||||
|
||||
/* just to be sure...*/
|
||||
if ( 0 == numRead )
|
||||
buf->remaining = 0;
|
||||
|
||||
target=pTarget;
|
||||
/* convert the bytes */
|
||||
if(buf->conv){
|
||||
/* set the callback to stop */
|
||||
UConverterToUCallback toUOldAction ;
|
||||
void* toUOldContext;
|
||||
void* toUNewContext=NULL;
|
||||
void* toUNewContext=NULL;
|
||||
ucnv_setToUCallBack(buf->conv,
|
||||
UCNV_TO_U_CALLBACK_STOP,
|
||||
toUNewContext,
|
||||
@ -143,7 +149,7 @@ ucbuf_fillucbuf( UCHARBUF* buf,UErrorCode* err){
|
||||
ucnv_toUnicode(buf->conv,&target,target+(MAX_U_BUF-offset),
|
||||
&source,source+numRead,NULL,
|
||||
(UBool)(buf->remaining==0),err);
|
||||
|
||||
|
||||
if(U_FAILURE(*err)){
|
||||
char context[CONTEXT_LEN];
|
||||
char preContext[CONTEXT_LEN];
|
||||
@ -152,9 +158,9 @@ ucbuf_fillucbuf( UCHARBUF* buf,UErrorCode* err){
|
||||
int32_t start=0;
|
||||
int32_t stop =0;
|
||||
int32_t pos =0;
|
||||
|
||||
|
||||
if( buf->showWarning==TRUE){
|
||||
fprintf(stderr,"\n###WARNING: Encountered abnormal bytes while"
|
||||
fprintf(stderr,"\n###WARNING: Encountered abnormal bytes while"
|
||||
" converting input stream to target encoding: %s\n",
|
||||
u_errorName(*err));
|
||||
}
|
||||
@ -164,17 +170,17 @@ ucbuf_fillucbuf( UCHARBUF* buf,UErrorCode* err){
|
||||
/* now get the context chars */
|
||||
ucnv_getInvalidChars(buf->conv,context,&len,err);
|
||||
context[len]= 0 ; /* null terminate the buffer */
|
||||
|
||||
|
||||
pos = source-cbuf-len;
|
||||
|
||||
/* for pre-context */
|
||||
start = (pos <=CONTEXT_LEN)? 0 : (pos - (CONTEXT_LEN-1));
|
||||
stop = pos-len;
|
||||
|
||||
|
||||
memcpy(preContext,cbuf+start,stop-start);
|
||||
/* null terminate the buffer */
|
||||
preContext[stop-start] = 0;
|
||||
|
||||
|
||||
/* for post-context */
|
||||
start = pos+len;
|
||||
stop = ((pos+CONTEXT_LEN)<= (sourceLimit-cbuf) )? (pos+(CONTEXT_LEN-1)) : (sourceLimit-cbuf);
|
||||
@ -182,18 +188,18 @@ ucbuf_fillucbuf( UCHARBUF* buf,UErrorCode* err){
|
||||
memcpy(postContext,source,stop-start);
|
||||
/* null terminate the buffer */
|
||||
postContext[stop-start] = 0;
|
||||
|
||||
|
||||
if(buf->showWarning ==TRUE){
|
||||
/* print out the context */
|
||||
fprintf(stderr,"\tPre-context: %s\n",preContext);
|
||||
fprintf(stderr,"\tContext: %s\n",context);
|
||||
fprintf(stderr,"\tPost-context: %s\n", postContext);
|
||||
}
|
||||
|
||||
|
||||
/* reset the converter */
|
||||
ucnv_reset(buf->conv);
|
||||
|
||||
/* set the call back to substiture
|
||||
/* set the call back to substitute
|
||||
* and restart conversion
|
||||
*/
|
||||
ucnv_setToUCallBack(buf->conv,
|
||||
@ -211,7 +217,7 @@ ucbuf_fillucbuf( UCHARBUF* buf,UErrorCode* err){
|
||||
ucnv_toUnicode(buf->conv,&target,target+(MAX_U_BUF-offset),
|
||||
&source,sourceLimit,NULL,
|
||||
(UBool)(buf->remaining==0),err);
|
||||
|
||||
|
||||
}
|
||||
numRead= target-pTarget;
|
||||
|
||||
@ -253,7 +259,7 @@ ucbuf_getc(UCHARBUF* buf,UErrorCode* err){
|
||||
|
||||
|
||||
/* u_unescapeAt() callback to return a UChar*/
|
||||
static UChar
|
||||
static UChar
|
||||
_charAt(int32_t offset, void *context) {
|
||||
return ((UCHARBUF*) context)->currentPos[offset];
|
||||
}
|
||||
@ -276,17 +282,17 @@ ucbuf_getcx(UCHARBUF* buf,UErrorCode* err) {
|
||||
} else {
|
||||
c1 = U_EOF;
|
||||
}
|
||||
|
||||
|
||||
c2 = *(buf->currentPos);
|
||||
|
||||
/* If it isn't a backslash, return it */
|
||||
if (c1 != 0x005C) {
|
||||
return c1;
|
||||
}
|
||||
|
||||
|
||||
/* Determine the amount of data in the buffer */
|
||||
length = buf->bufLimit-buf->currentPos;
|
||||
|
||||
|
||||
/* The longest escape sequence is \Uhhhhhhhh; make sure
|
||||
we have at least that many characters */
|
||||
if (length < 10) {
|
||||
@ -295,7 +301,7 @@ ucbuf_getcx(UCHARBUF* buf,UErrorCode* err) {
|
||||
ucbuf_fillucbuf(buf,err);
|
||||
length = buf->bufLimit-buf->buffer;
|
||||
}
|
||||
|
||||
|
||||
/* Process the escape */
|
||||
offset = 0;
|
||||
c32 = u_unescapeAt(_charAt, &offset, length, (void*)buf);
|
||||
@ -307,7 +313,7 @@ ucbuf_getcx(UCHARBUF* buf,UErrorCode* err) {
|
||||
/* Update the current buffer position */
|
||||
buf->currentPos += offset;
|
||||
}else{
|
||||
/* unescaping failed so we just return
|
||||
/* unescaping failed so we just return
|
||||
* c1 and not consume the buffer
|
||||
* this is useful for rules with escapes
|
||||
* in resouce bundles
|
||||
@ -364,11 +370,11 @@ ucbuf_open(FileStream* in,const char* cp, UBool showWarning, UErrorCode* err){
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: this method will fail if at the
|
||||
/* TODO: this method will fail if at the
|
||||
* begining of buffer and the uchar to unget
|
||||
* is from the previous buffer. Need to implement
|
||||
* system to take care of that situation.
|
||||
*/
|
||||
*/
|
||||
U_CAPI void U_EXPORT2
|
||||
ucbuf_ungetc(UChar32 c,UCHARBUF* buf){
|
||||
/* decrement currentPos pointer
|
||||
@ -380,7 +386,7 @@ ucbuf_ungetc(UChar32 c,UCHARBUF* buf){
|
||||
}
|
||||
|
||||
/* frees the resources of UChar* buffer */
|
||||
static void
|
||||
static void
|
||||
ucbuf_closebuf(UCHARBUF* buf){
|
||||
uprv_free(buf->buffer);
|
||||
buf->buffer = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user