ICU-6132 Undo some unneccessary changes. Remove some tabs. Make sure that the UErrorCode is propagated when possible. When a UErrorCode is available, don't check for a NULL return value.

X-SVN-Rev: 23479
This commit is contained in:
George Rhoten 2008-02-23 19:15:18 +00:00
parent 6d5e7e7226
commit de6512a9c1
44 changed files with 595 additions and 774 deletions

View File

@ -334,11 +334,11 @@ hasService(void)
URegistryKey U_EXPORT2
BreakIterator::registerInstance(BreakIterator* toAdopt, const Locale& locale, UBreakIteratorType kind, UErrorCode& status)
{
ICULocaleService *service = getService();
if (service == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
ICULocaleService *service = getService();
if (service == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
return service->registerInstance(toAdopt, locale, kind, status);
}
@ -363,7 +363,7 @@ BreakIterator::getAvailableLocales(void)
{
ICULocaleService *service = getService();
if (service == NULL) {
return NULL;
return NULL;
}
return service->getAvailableLocales();
}

View File

@ -394,7 +394,7 @@ Locale::Locale( const char * newLanguage,
togo_heap = (char *)uprv_malloc(sizeof(char)*(size+1));
// If togo_heap could not be created, initialize with default settings.
if (togo_heap == NULL) {
init(NULL, FALSE);
init(NULL, FALSE);
}
togo = togo_heap;
}
@ -485,7 +485,7 @@ Locale &Locale::operator=(const Locale &other)
if(other.fullName != other.fullNameBuffer) {
fullName = (char *)uprv_malloc(sizeof(char)*(uprv_strlen(other.fullName)+1));
if (fullName == NULL) {
return *this;
return *this;
}
}
/* Copy the full name */
@ -1326,7 +1326,7 @@ Locale::getBaseName() const
if(baseNameSize >= ULOC_FULLNAME_CAPACITY) {
((Locale *)this)->baseName = (char *)uprv_malloc(sizeof(char) * baseNameSize + 1);
if (baseName == NULL) {
return baseName;
return baseName;
}
uloc_getBaseName(fullName, baseName, baseNameSize+1, &status);
}

View File

@ -614,12 +614,12 @@ extern U_IMPORT char *U_TZNAME[];
#if !UCONFIG_NO_FILE_IO && (defined(U_DARWIN) || defined(U_LINUX) || defined(U_BSD))
/* These platforms are likely to use Olson timezone IDs. */
#define CHECK_LOCALTIME_LINK 1
#if defined(U_LINUX)
#define TZDEFAULT "/etc/localtime"
#define TZZONEINFO "/usr/share/zoneinfo/"
#else
#if defined(U_DARWIN)
#include <tzfile.h>
#define TZZONEINFO (TZDIR "/")
#else
#define TZDEFAULT "/etc/localtime"
#define TZZONEINFO "/usr/share/zoneinfo/"
#endif
static char gTimeZoneBuffer[PATH_MAX];
static char *gTimeZoneBufferPtr = NULL;
@ -891,7 +891,7 @@ u_setDataDirectory(const char *directory) {
newDataDir = (char *)uprv_malloc(length + 2);
/* Exit out if newDataDir could not be created. */
if (newDataDir == NULL) {
return;
return;
}
uprv_strcpy(newDataDir, directory);
@ -1196,7 +1196,7 @@ The leftmost codepage (.xxx) wins.
correctedPOSIXLocale = uprv_malloc(uprv_strlen(posixID)+1);
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
return NULL;
}
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
correctedPOSIXLocale[p-posixID] = 0;
@ -1213,7 +1213,7 @@ The leftmost codepage (.xxx) wins.
correctedPOSIXLocale = uprv_malloc(uprv_strlen(posixID)+1);
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
return NULL;
}
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
correctedPOSIXLocale[p-posixID] = 0;
@ -1260,7 +1260,7 @@ The leftmost codepage (.xxx) wins.
correctedPOSIXLocale = (char *)uprv_malloc(uprv_strlen(posixID) + 1);
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
return NULL;
}
posixID = uprv_strcpy(correctedPOSIXLocale, posixID);
}

View File

@ -323,12 +323,10 @@ void RuleBasedBreakIterator::setText(UText *ut, UErrorCode &status) {
if (fDCharIter == NULL) {
static const UChar c = 0;
fDCharIter = new UCharCharacterIterator(&c, 0);
}
// Check for Null pointer
if (fDCharIter == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
if (fDCharIter == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
}
if (fCharIter!=fSCharIter && fCharIter!=fDCharIter) {

View File

@ -151,14 +151,14 @@ RBBINode *RBBINode::cloneTree() {
n = new RBBINode(*this);
// Check for null pointer.
if (n != NULL) {
if (fLeftChild != NULL) {
n->fLeftChild = fLeftChild->cloneTree();
n->fLeftChild->fParent = n;
}
if (fRightChild != NULL) {
n->fRightChild = fRightChild->cloneTree();
n->fRightChild->fParent = n;
}
if (fLeftChild != NULL) {
n->fLeftChild = fLeftChild->cloneTree();
n->fLeftChild->fParent = n;
}
if (fRightChild != NULL) {
n->fRightChild = fRightChild->cloneTree();
n->fRightChild->fParent = n;
}
}
}
return n;

View File

@ -292,9 +292,8 @@ RBBIRuleBuilder::createRuleBasedBreakIterator( const UnicodeString &rules,
// in the run-time format.
//
RBBIDataHeader *data = builder.flattenData(); // returns NULL if error
if (data == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
if (U_FAILURE(*builder.fStatus)) {
return NULL;
}

View File

@ -96,11 +96,6 @@ RBBIRuleScanner::RBBIRuleScanner(RBBIRuleBuilder *rb)
fRuleNum = 0;
fNodeStack[0] = NULL;
fRuleSets[kRuleSet_rule_char-128] = NULL;
fRuleSets[kRuleSet_white_space-128] = NULL;
fRuleSets[kRuleSet_name_char-128] = NULL;
fRuleSets[kRuleSet_name_start_char-128] = NULL;
fRuleSets[kRuleSet_digit_char-128] = NULL;
fSymbolTable = NULL;
fSetTable = NULL;
@ -126,48 +121,34 @@ RBBIRuleScanner::RBBIRuleScanner(RBBIRuleBuilder *rb)
// all instances of RBBIRuleScanners. BUT this is quite a bit simpler,
// and the time to build these few sets should be small compared to a
// full break iterator build.
fRuleSets[kRuleSet_rule_char-128] = new UnicodeSet(gRuleSet_rule_char_pattern, *rb->fStatus);
fRuleSets[kRuleSet_white_space-128] = uprv_openRuleWhiteSpaceSet(rb->fStatus);
fRuleSets[kRuleSet_name_char-128] = new UnicodeSet(gRuleSet_name_char_pattern, *rb->fStatus);
fRuleSets[kRuleSet_name_start_char-128] = new UnicodeSet(gRuleSet_name_start_char_pattern, *rb->fStatus);
fRuleSets[kRuleSet_digit_char-128] = new UnicodeSet(gRuleSet_digit_char_pattern, *rb->fStatus);
fRuleSets[kRuleSet_rule_char-128] = UnicodeSet(gRuleSet_rule_char_pattern, *rb->fStatus);
UnicodeSet *whitespaceSet = uprv_openRuleWhiteSpaceSet(rb->fStatus);
if (U_FAILURE(*rb->fStatus)) {
return;
}
fRuleSets[kRuleSet_white_space-128] = *whitespaceSet;
delete whitespaceSet;
fRuleSets[kRuleSet_name_char-128] = UnicodeSet(gRuleSet_name_char_pattern, *rb->fStatus);
fRuleSets[kRuleSet_name_start_char-128] = UnicodeSet(gRuleSet_name_start_char_pattern, *rb->fStatus);
fRuleSets[kRuleSet_digit_char-128] = UnicodeSet(gRuleSet_digit_char_pattern, *rb->fStatus);
if (*rb->fStatus == U_ILLEGAL_ARGUMENT_ERROR) {
// This case happens if ICU's data is missing. UnicodeSet tries to look up property
// names from the init string, can't find them, and claims an illegal arguement.
// Change the error so that the actual problem will be clearer to users.
*rb->fStatus = U_BRK_INIT_ERROR;
}
if (fRuleSets[kRuleSet_rule_char-128] == NULL ||
fRuleSets[kRuleSet_white_space-128] == NULL ||
fRuleSets[kRuleSet_name_char-128] == NULL ||
fRuleSets[kRuleSet_name_start_char-128] == NULL ||
fRuleSets[kRuleSet_digit_char-128] == NULL ) {
delete fRuleSets[kRuleSet_rule_char-128];
delete fRuleSets[kRuleSet_white_space-128];
delete fRuleSets[kRuleSet_name_char-128];
delete fRuleSets[kRuleSet_name_start_char-128];
delete fRuleSets[kRuleSet_digit_char-128];
fRuleSets[kRuleSet_rule_char-128] = NULL;
fRuleSets[kRuleSet_white_space-128] = NULL;
fRuleSets[kRuleSet_name_char-128] = NULL;
fRuleSets[kRuleSet_name_start_char-128] = NULL;
fRuleSets[kRuleSet_digit_char-128] = NULL;
*rb->fStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(*rb->fStatus)) {
return;
}
fSymbolTable = new RBBISymbolTable(this, rb->fRules, *rb->fStatus);
if (fSymbolTable == NULL) {
*rb->fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
*rb->fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
fSetTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, rb->fStatus);
if (fSetTable == NULL) {
*rb->fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
if (U_FAILURE(*rb->fStatus)) {
return;
}
uhash_setValueDeleter(fSetTable, RBBISetTable_deleter);
}
@ -180,12 +161,6 @@ RBBIRuleScanner::RBBIRuleScanner(RBBIRuleBuilder *rb)
//
//------------------------------------------------------------------------------
RBBIRuleScanner::~RBBIRuleScanner() {
delete fRuleSets[kRuleSet_rule_char-128];
delete fRuleSets[kRuleSet_white_space-128];
delete fRuleSets[kRuleSet_name_char-128];
delete fRuleSets[kRuleSet_name_start_char-128];
delete fRuleSets[kRuleSet_digit_char-128];
delete fSymbolTable;
if (fSetTable != NULL) {
uhash_close(fSetTable);
@ -724,8 +699,8 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
//
RBBINode *usetNode = new RBBINode(RBBINode::uset);
if (usetNode == NULL) {
error(U_MEMORY_ALLOCATION_ERROR);
return;
error(U_MEMORY_ALLOCATION_ERROR);
return;
}
usetNode->fInputSet = setToAdopt;
usetNode->fParent = node;
@ -745,14 +720,14 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
el = (RBBISetTableEl *)uprv_malloc(sizeof(RBBISetTableEl));
UnicodeString *tkey = new UnicodeString(s);
if (tkey == NULL || el == NULL || setToAdopt == NULL) {
// Delete to avoid memory leak
delete tkey;
uprv_free(el);
delete setToAdopt;
tkey = NULL;
el = NULL;
setToAdopt = NULL;
// Delete to avoid memory leak
delete tkey;
tkey = NULL;
uprv_free(el);
el = NULL;
delete setToAdopt;
setToAdopt = NULL;
error(U_MEMORY_ALLOCATION_ERROR);
return;
}
@ -1017,12 +992,7 @@ void RBBIRuleScanner::parse() {
if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class &&
fC.fEscaped == FALSE && // char is not escaped &&
fC.fChar != (UChar32)-1) { // char is not EOF
UnicodeSet *uniset = fRuleSets[tableEl->fCharClass-128];
// This is a result of fRuleSets[] initialization error.
if (uniset == NULL) {
return;
}
if (uniset->contains(fC.fChar)) {
if (fRuleSets[tableEl->fCharClass-128].contains(fC.fChar)) {
// Table row specified a character class, or set of characters,
// and the current char matches it.
break;
@ -1180,7 +1150,7 @@ void RBBIRuleScanner::scanSet() {
fSymbolTable,
localStatus);
if (uset == NULL) {
localStatus = U_MEMORY_ALLOCATION_ERROR;
localStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(localStatus)) {
// TODO: Get more accurate position of the error from UnicodeSet's return info.

View File

@ -137,7 +137,7 @@ private:
// The key is the string used for creating
// the set.
UnicodeSet *fRuleSets[10]; // Unicode Sets that are needed during
UnicodeSet fRuleSets[10]; // Unicode Sets that are needed during
// the scanning of RBBI rules. The
// indicies for these are assigned by the
// perl script that builds the state tables.

View File

@ -138,8 +138,8 @@ void RBBISetBuilder::build() {
//
fRangeList = new RangeDescriptor(*fStatus); // will check for status here
if (fRangeList == NULL) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
fRangeList->fStartChar = 0;
fRangeList->fEndChar = 0x10ffff;
@ -359,8 +359,8 @@ void RBBISetBuilder::addValToSets(UVector *sets, uint32_t val) {
void RBBISetBuilder::addValToSet(RBBINode *usetNode, uint32_t val) {
RBBINode *leafNode = new RBBINode(RBBINode::leafChar);
if (leafNode == NULL) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
leafNode->fVal = (unsigned short)val;
if (usetNode->fLeftChild == NULL) {
@ -372,8 +372,8 @@ void RBBISetBuilder::addValToSet(RBBINode *usetNode, uint32_t val) {
// and the new value as the right child.
RBBINode *orNode = new RBBINode(RBBINode::opOr);
if (orNode == NULL) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
orNode->fLeftChild = usetNode->fLeftChild;
orNode->fRightChild = leafNode;

View File

@ -94,9 +94,10 @@ void RBBITableBuilder::build() {
RBBINode *bofLeaf = new RBBINode(RBBINode::leafChar);
// Delete and exit if memory allocation failed.
if (bofTop == NULL || bofLeaf == NULL) {
delete bofTop;
delete bofLeaf;
return;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
delete bofTop;
delete bofLeaf;
return;
}
bofTop->fLeftChild = bofLeaf;
bofTop->fRightChild = fTree;
@ -113,15 +114,17 @@ void RBBITableBuilder::build() {
RBBINode *cn = new RBBINode(RBBINode::opCat);
// Exit if memory allocation failed.
if (cn == NULL) {
return;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
cn->fLeftChild = fTree;
fTree->fParent = cn;
cn->fRightChild = new RBBINode(RBBINode::endMark);
// Delete and exit if memory allocation failed.
if (cn->fRightChild == NULL) {
delete cn;
return;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
delete cn;
return;
}
cn->fRightChild->fParent = cn;
fTree = cn;
@ -549,41 +552,41 @@ void RBBITableBuilder::buildStateTable() {
int lastInputSymbol = fRB->fSetBuilder->getNumCharCategories() - 1;
failState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
if (failState == NULL) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
goto ExitBuildSTdeleteall;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
goto ExitBuildSTdeleteall;
}
failState->fPositions = new UVector(*fStatus);
if (failState->fPositions == NULL) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (failState->fPositions == NULL || U_FAILURE(*fStatus)) {
goto ExitBuildSTdeleteall;
goto ExitBuildSTdeleteall;
}
fDStates->addElement(failState, *fStatus);
if (U_FAILURE(*fStatus)) {
goto ExitBuildSTdeleteall;
goto ExitBuildSTdeleteall;
}
// initially, the only unmarked state in Dstates is firstpos(root),
// where toot is the root of the syntax tree for (r)#;
initialState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
if (initialState == NULL) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(*fStatus)) {
goto ExitBuildSTdeleteall;
goto ExitBuildSTdeleteall;
}
initialState->fPositions = new UVector(*fStatus);
if (initialState->fPositions == NULL) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
*fStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(*fStatus)) {
goto ExitBuildSTdeleteall;
goto ExitBuildSTdeleteall;
}
setAdd(initialState->fPositions, fTree->fFirstPosSet);
fDStates->addElement(initialState, *fStatus);
if (U_FAILURE(*fStatus)) {
goto ExitBuildSTdeleteall;
goto ExitBuildSTdeleteall;
}
// while there is an unmarked state T in Dstates do begin
@ -672,8 +675,8 @@ void RBBITableBuilder::buildStateTable() {
return;
// delete local pointers only if error occured.
ExitBuildSTdeleteall:
delete initialState;
delete failState;
delete initialState;
delete failState;
}

View File

@ -624,31 +624,34 @@ U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd) {
uprv_strcpy(resB->fResPath, toAdd);
}
*/
static void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd) {
int32_t resPathLenOrig = resB->fResPathLen;
if(resB->fResPath == NULL) {
resB->fResPath = resB->fResBuf;
*(resB->fResPath) = 0;
resB->fResPathLen = 0;
}
resB->fResPathLen += lenToAdd;
if(RES_BUFSIZE <= resB->fResPathLen+1) {
if(resB->fResPath == resB->fResBuf) {
resB->fResPath = (char *)uprv_malloc((resB->fResPathLen+1)*sizeof(char));
/* Check that memory was allocated correctly. */
if (resB->fResPath == NULL) {
return;
}
uprv_strcpy(resB->fResPath, resB->fResBuf);
} else {
resB->fResPath = (char *)uprv_realloc(resB->fResPath, (resB->fResPathLen+1)*sizeof(char));
/* Check that memory was reallocated correctly. */
if (resB->fResPath == NULL) {
return;
}
static void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd, UErrorCode *status) {
int32_t resPathLenOrig = resB->fResPathLen;
if(resB->fResPath == NULL) {
resB->fResPath = resB->fResBuf;
*(resB->fResPath) = 0;
resB->fResPathLen = 0;
}
resB->fResPathLen += lenToAdd;
if(RES_BUFSIZE <= resB->fResPathLen+1) {
if(resB->fResPath == resB->fResBuf) {
resB->fResPath = (char *)uprv_malloc((resB->fResPathLen+1)*sizeof(char));
/* Check that memory was allocated correctly. */
if (resB->fResPath == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_strcpy(resB->fResPath, resB->fResBuf);
} else {
char *temp = (char *)uprv_realloc(resB->fResPath, (resB->fResPathLen+1)*sizeof(char));
/* Check that memory was reallocated correctly. */
if (temp == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return;
}
resB->fResPath = temp;
}
}
}
uprv_strcpy(resB->fResPath + resPathLenOrig, toAdd);
uprv_strcpy(resB->fResPath + resPathLenOrig, toAdd);
}
static void ures_freeResPath(UResourceBundle *resB) {
@ -956,19 +959,19 @@ static UResourceBundle *init_resb_result(const ResourceData *rdata, Resource r,
/*resB->fParentRes = parent;*/
resB->fTopLevelData = parent->fTopLevelData;
if(parent->fResPath && parent != resB) {
ures_appendResPath(resB, parent->fResPath, parent->fResPathLen);
ures_appendResPath(resB, parent->fResPath, parent->fResPathLen, status);
}
if(key != NULL) {
ures_appendResPath(resB, key, (int32_t)uprv_strlen(key));
ures_appendResPath(resB, key, (int32_t)uprv_strlen(key), status);
if(resB->fResPath[resB->fResPathLen-1] != RES_PATH_SEPARATOR) {
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1);
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1, status);
}
} else if(index >= 0) {
char buf[256];
int32_t len = T_CString_integerToString(buf, index, 10);
ures_appendResPath(resB, buf, len);
ures_appendResPath(resB, buf, len, status);
if(resB->fResPath[resB->fResPathLen-1] != RES_PATH_SEPARATOR) {
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1);
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1, status);
}
}
/* Make sure that Purify doesn't complain about uninitialized memory copies. */
@ -1007,11 +1010,11 @@ UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *origin
r->fResPath = NULL;
r->fResPathLen = 0;
if(original->fResPath) {
ures_appendResPath(r, original->fResPath, original->fResPathLen);
ures_appendResPath(r, original->fResPath, original->fResPathLen, status);
}
ures_setIsStackObject(r, isStackObject);
if(r->fData != NULL) {
entryIncrease(r->fData);
entryIncrease(r->fData);
}
}
return r;

View File

@ -435,8 +435,8 @@ uprv_openRuleWhiteSpaceSet(UErrorCode* ec) {
U_NAMESPACE_QUALIFIER UnicodeSet *set=new U_NAMESPACE_QUALIFIER UnicodeSet(9, 0xd);
// Check for new failure.
if (set == NULL) {
*ec = U_MEMORY_ALLOCATION_ERROR;
return NULL;
*ec = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
set->UnicodeSet::add(0x20).add(0x85).add(0x200e, 0x200f).add(0x2028, 0x2029);
return set;

View File

@ -183,9 +183,8 @@ AnyTransliterator::AnyTransliterator(const UnicodeString& id,
targetScript(theTargetScript)
{
cache = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &ec);
if (cache == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
return;
if (U_FAILURE(ec)) {
return;
}
uhash_setValueDeleter(cache, _deleteTransliterator);
@ -210,9 +209,8 @@ AnyTransliterator::AnyTransliterator(const AnyTransliterator& o) :
// Don't copy the cache contents
UErrorCode ec = U_ZERO_ERROR;
cache = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &ec);
if (cache == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
return;
if (U_FAILURE(ec)) {
return;
}
uhash_setValueDeleter(cache, _deleteTransliterator);
}

View File

@ -326,11 +326,11 @@ protected:
} else {
UnicodeString *ret = new UnicodeString();
if (ret == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
status = U_MEMORY_ALLOCATION_ERROR;
} else {
ret->append((UChar)0x40); // '@' is a variant character
ret->append(UNICODE_STRING("calendar=", 9));
(*ret) += UnicodeString(keyword,-1,US_INV);
ret->append((UChar)0x40); // '@' is a variant character
ret->append(UNICODE_STRING("calendar=", 9));
(*ret) += UnicodeString(keyword,-1,US_INV);
}
return ret;
}
@ -407,8 +407,8 @@ getCalendarService(UErrorCode &status)
#endif
ICULocaleService * newservice = new CalendarService();
if (newservice == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return newservice;
status = U_MEMORY_ALLOCATION_ERROR;
return newservice;
}
#ifdef U_DEBUG_CALSVC
fprintf(stderr, "Registering classes..\n");
@ -555,7 +555,7 @@ fZone(0)
clear();
fZone = TimeZone::createDefault();
if (fZone == NULL) {
success = U_MEMORY_ALLOCATION_ERROR;
success = U_MEMORY_ALLOCATION_ERROR;
}
setWeekCountData(Locale::getDefault(), NULL, success);
}
@ -641,9 +641,11 @@ Calendar::operator=(const Calendar &right)
fAreFieldsVirtuallySet = right.fAreFieldsVirtuallySet;
fLenient = right.fLenient;
if (fZone != NULL) {
delete fZone;
delete fZone;
}
if (right.fZone != NULL) {
fZone = right.fZone->clone();
}
fZone = right.fZone->clone();
fFirstDayOfWeek = right.fFirstDayOfWeek;
fMinimalDaysInFirstWeek = right.fMinimalDaysInFirstWeek;
fNextStamp = right.fNextStamp;
@ -2104,8 +2106,8 @@ Calendar::getActualMinimum(UCalendarDateFields field, UErrorCode& status) const
// accept anything for the field values
Calendar *work = (Calendar*)this->clone();
if (work == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
work->setLenient(TRUE);

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2007, International Business Machines Corporation and *
* Copyright (C) 1996-2008, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -463,23 +463,23 @@ const CollationElementIterator& CollationElementIterator::operator=(
/* CE buffer */
int32_t CEsize;
if (coliter->extendCEs) {
uprv_memcpy(coliter->CEs, othercoliter->CEs, sizeof(uint32_t) * UCOL_EXPAND_CE_BUFFER_SIZE);
CEsize = sizeof(othercoliter->extendCEs);
if (CEsize > 0) {
othercoliter->extendCEs = (uint32_t *)uprv_malloc(CEsize);
uprv_memcpy(coliter->extendCEs, othercoliter->extendCEs, CEsize);
}
coliter->toReturn = coliter->extendCEs +
(othercoliter->toReturn - othercoliter->extendCEs);
coliter->CEpos = coliter->extendCEs + CEsize;
uprv_memcpy(coliter->CEs, othercoliter->CEs, sizeof(uint32_t) * UCOL_EXPAND_CE_BUFFER_SIZE);
CEsize = sizeof(othercoliter->extendCEs);
if (CEsize > 0) {
othercoliter->extendCEs = (uint32_t *)uprv_malloc(CEsize);
uprv_memcpy(coliter->extendCEs, othercoliter->extendCEs, CEsize);
}
coliter->toReturn = coliter->extendCEs +
(othercoliter->toReturn - othercoliter->extendCEs);
coliter->CEpos = coliter->extendCEs + CEsize;
} else {
CEsize = (int32_t)(othercoliter->CEpos - othercoliter->CEs);
if (CEsize > 0) {
uprv_memcpy(coliter->CEs, othercoliter->CEs, CEsize);
}
coliter->toReturn = coliter->CEs +
(othercoliter->toReturn - othercoliter->CEs);
coliter->CEpos = coliter->CEs + CEsize;
CEsize = (int32_t)(othercoliter->CEpos - othercoliter->CEs);
if (CEsize > 0) {
uprv_memcpy(coliter->CEs, othercoliter->CEs, CEsize);
}
coliter->toReturn = coliter->CEs +
(othercoliter->toReturn - othercoliter->CEs);
coliter->CEpos = coliter->CEs + CEsize;
}
if (othercoliter->fcdPosition != NULL) {

View File

@ -707,7 +707,7 @@ public:
{
CollationLocaleListEnumeration *result = new CollationLocaleListEnumeration();
if (result) {
result->index = index;
result->index = index;
}
return result;
}

View File

@ -280,40 +280,41 @@ void CompoundTransliterator::freeTransliterators(void) {
* Assignment operator.
*/
CompoundTransliterator& CompoundTransliterator::operator=(
const CompoundTransliterator& t) {
const CompoundTransliterator& t)
{
Transliterator::operator=(t);
int32_t i = 0;
UBool failed = FALSE;
if (trans != NULL) {
for (i=0; i<count; ++i) {
delete trans[i];
trans[i] = 0;
}
for (i=0; i<count; ++i) {
delete trans[i];
trans[i] = 0;
}
}
if (t.count > count) {
if (trans != NULL) {
uprv_free(trans);
}
if (trans != NULL) {
uprv_free(trans);
}
trans = (Transliterator **)uprv_malloc(t.count * sizeof(Transliterator *));
}
count = t.count;
if (trans != NULL) {
for (i=0; i<count; ++i) {
trans[i] = t.trans[i]->clone();
if (trans[i] == NULL) {
failed = TRUE;
break;
}
}
for (i=0; i<count; ++i) {
trans[i] = t.trans[i]->clone();
if (trans[i] == NULL) {
failed = TRUE;
break;
}
}
}
// if memory allocation failed delete backwards trans array
if (failed && i > 0) {
int32_t n;
for (n = i-1; n >= 0; n--) {
uprv_free(trans[n]);
trans[n] = NULL;
}
int32_t n;
for (n = i-1; n >= 0; n--) {
uprv_free(trans[n]);
trans[n] = NULL;
}
}
numAnonymousRBTs = t.numAnonymousRBTs;
return *this;
@ -347,24 +348,24 @@ void CompoundTransliterator::setTransliterators(Transliterator* const transliter
int32_t transCount) {
Transliterator** a = (Transliterator **)uprv_malloc(transCount * sizeof(Transliterator *));
if (a == NULL) {
return;
return;
}
int32_t i = 0;
UBool failed = FALSE;
for (i=0; i<transCount; ++i) {
a[i] = transliterators[i]->clone();
if (a[i] == NULL) {
failed = TRUE;
break;
failed = TRUE;
break;
}
}
if (failed && i > 0) {
int32_t n;
for (n = i-1; n >= 0; n--) {
uprv_free(a[n]);
a[n] = NULL;
}
return;
int32_t n;
for (n = i-1; n >= 0; n--) {
uprv_free(a[n]);
a[n] = NULL;
}
return;
}
adoptTransliterators(a, transCount);
}

View File

@ -18,19 +18,19 @@
U_NAMESPACE_BEGIN
CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) :
fmt(NULL) {
fmt(NULL)
{
fmt = NumberFormat::createCurrencyInstance(locale, ec);
}
CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) :
MeasureFormat(other), fmt(NULL) {
MeasureFormat(other), fmt(NULL)
{
fmt = (NumberFormat*) other.fmt->clone();
}
CurrencyFormat::~CurrencyFormat() {
if (fmt != NULL) {
delete fmt;
}
delete fmt;
}
UBool CurrencyFormat::operator==(const Format& other) const {
@ -51,22 +51,16 @@ Format* CurrencyFormat::clone() const {
UnicodeString& CurrencyFormat::format(const Formattable& obj,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& ec) const {
if (fmt != NULL) {
return fmt->format(obj, appendTo, pos, ec);
}
// Set error code; fmt should never be NULL
// this is the case due to failure in construction process
ec = U_MEMORY_ALLOCATION_ERROR;
return appendTo;
UErrorCode& ec) const
{
return fmt->format(obj, appendTo, pos, ec);
}
void CurrencyFormat::parseObject(const UnicodeString& source,
Formattable& result,
ParsePosition& pos) const {
if (fmt != NULL) {
fmt->parseCurrency(source, result, pos);
}
ParsePosition& pos) const
{
fmt->parseCurrency(source, result, pos);
}
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat)

View File

@ -346,10 +346,10 @@ DateFormat::adoptCalendar(Calendar* newCalendar)
void
DateFormat::setCalendar(const Calendar& newCalendar)
{
Calendar* newCalClone = newCalendar.clone();
if (newCalClone != NULL) {
adoptCalendar(newCalClone);
}
Calendar* newCalClone = newCalendar.clone();
if (newCalClone != NULL) {
adoptCalendar(newCalClone);
}
}
//----------------------------------------------------------------------
@ -374,10 +374,10 @@ DateFormat::adoptNumberFormat(NumberFormat* newNumberFormat)
void
DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)
{
NumberFormat* newNumFmtClone = (NumberFormat*)newNumberFormat.clone();
if (newNumFmtClone != NULL) {
adoptNumberFormat(newNumFmtClone);
}
NumberFormat* newNumFmtClone = (NumberFormat*)newNumberFormat.clone();
if (newNumFmtClone != NULL) {
adoptNumberFormat(newNumFmtClone);
}
}
//----------------------------------------------------------------------
@ -393,18 +393,18 @@ DateFormat::getNumberFormat() const
void
DateFormat::adoptTimeZone(TimeZone* zone)
{
if (fCalendar != NULL) {
fCalendar->adoptTimeZone(zone);
}
if (fCalendar != NULL) {
fCalendar->adoptTimeZone(zone);
}
}
//----------------------------------------------------------------------
void
DateFormat::setTimeZone(const TimeZone& zone)
{
if (fCalendar != NULL) {
fCalendar->setTimeZone(zone);
}
if (fCalendar != NULL) {
fCalendar->setTimeZone(zone);
}
}
//----------------------------------------------------------------------
@ -412,12 +412,12 @@ DateFormat::setTimeZone(const TimeZone& zone)
const TimeZone&
DateFormat::getTimeZone() const
{
if (fCalendar != NULL) {
return fCalendar->getTimeZone();
}
// If calendar doesn't exists, create default timezone.
// fCalendar is rarely null
return *(TimeZone::createDefault());
if (fCalendar != NULL) {
return fCalendar->getTimeZone();
}
// If calendar doesn't exists, create default timezone.
// fCalendar is rarely null
return *(TimeZone::createDefault());
}
//----------------------------------------------------------------------
@ -425,9 +425,9 @@ DateFormat::getTimeZone() const
void
DateFormat::setLenient(UBool lenient)
{
if (fCalendar != NULL) {
fCalendar->setLenient(lenient);
}
if (fCalendar != NULL) {
fCalendar->setLenient(lenient);
}
}
//----------------------------------------------------------------------
@ -435,11 +435,11 @@ DateFormat::setLenient(UBool lenient)
UBool
DateFormat::isLenient() const
{
if (fCalendar != NULL) {
return fCalendar->isLenient();
}
// fCalendar is rarely null
return FALSE;
if (fCalendar != NULL) {
return fCalendar->isLenient();
}
// fCalendar is rarely null
return FALSE;
}
U_NAMESPACE_END

View File

@ -1819,10 +1819,10 @@ int32_t DecimalFormat::compareComplexAffix(const UnicodeString& affixPat,
const char* loc = getLocaleID(ULOC_VALID_LOCALE, ec);
if (U_FAILURE(ec) || loc == NULL || *loc == 0) {
// applyPattern has been called; use the symbols
if (fSymbols == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
if (fSymbols == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
loc = fSymbols->getLocale().getName();
ec = U_ZERO_ERROR;
}
@ -2137,9 +2137,9 @@ void DecimalFormat::setRoundingIncrement(double newValue) {
fRoundingIncrement = new DigitList();
}
if (fRoundingIncrement != NULL) {
fRoundingIncrement->set((int32_t)newValue);
fRoundingDouble = newValue;
return;
fRoundingIncrement->set((int32_t)newValue);
fRoundingDouble = newValue;
return;
}
}
// These statements are executed if newValue is less than 0.0
@ -3726,11 +3726,11 @@ void DecimalFormat::setCurrency(const UChar* theCurrency) {
void DecimalFormat::getEffectiveCurrency(UChar* result, UErrorCode& ec) const {
if (fSymbols == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
return;
ec = U_MEMORY_ALLOCATION_ERROR;
return;
}
ec = U_ZERO_ERROR;
const UChar* c = getCurrency();
const UChar* c = getCurrency();
if (*c == 0) {
const UnicodeString &intl =
fSymbols->getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol);

View File

@ -280,26 +280,26 @@ DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings)
fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *));
if (fZoneStrings != NULL) {
for (row=0; row<fZoneStringsRowCount; ++row)
{
fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount);
if (fZoneStrings[row] == NULL) {
failed = TRUE;
break;
}
for (col=0; col<fZoneStringsColCount; ++col) {
// fastCopyFrom() - see assignArray comments
fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]);
}
}
for (row=0; row<fZoneStringsRowCount; ++row)
{
fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount);
if (fZoneStrings[row] == NULL) {
failed = TRUE;
break;
}
for (col=0; col<fZoneStringsColCount; ++col) {
// fastCopyFrom() - see assignArray comments
fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]);
}
}
}
// If memory allocation failed, roll back and delete fZoneStrings
if (failed) {
for (int i = row; i >= 0; i--) {
delete[] fZoneStrings[i];
}
uprv_free(fZoneStrings);
fZoneStrings = NULL;
for (int i = row; i >= 0; i--) {
delete[] fZoneStrings[i];
}
uprv_free(fZoneStrings);
fZoneStrings = NULL;
}
}

View File

@ -71,7 +71,8 @@ static inline UBool instanceOfMeasure(const UObject* a) {
static inline Formattable* createArrayCopy(const Formattable* array, int32_t count) {
Formattable *result = new Formattable[count];
if (result != NULL) {
for (int32_t i=0; i<count; ++i) result[i] = array[i]; // Don't memcpy!
for (int32_t i=0; i<count; ++i)
result[i] = array[i]; // Don't memcpy!
}
return result;
}
@ -274,11 +275,11 @@ Formattable::operator==(const Formattable& that) const
}
break;
case kObject:
if (fValue.fObject == NULL || that.fValue.fObject == NULL) {
equal = FALSE;
} else {
equal = objectEquals(fValue.fObject, that.fValue.fObject);
}
if (fValue.fObject == NULL || that.fValue.fObject == NULL) {
equal = FALSE;
} else {
equal = objectEquals(fValue.fObject, that.fValue.fObject);
}
break;
}
@ -370,10 +371,10 @@ Formattable::getLong(UErrorCode& status) const
return (int32_t)fValue.fDouble; // loses fraction
}
case Formattable::kObject:
if (fValue.fObject == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
if (fValue.fObject == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
// TODO Later replace this with instanceof call
if (instanceOfMeasure(fValue.fObject)) {
return ((const Measure*) fValue.fObject)->
@ -408,10 +409,10 @@ Formattable::getInt64(UErrorCode& status) const
return (int64_t)fValue.fDouble;
}
case Formattable::kObject:
if (fValue.fObject == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
if (fValue.fObject == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
// TODO Later replace this with instanceof call
if (instanceOfMeasure(fValue.fObject)) {
return ((const Measure*) fValue.fObject)->
@ -438,10 +439,10 @@ Formattable::getDouble(UErrorCode& status) const
case Formattable::kDouble:
return fValue.fDouble;
case Formattable::kObject:
if (fValue.fObject == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
if (fValue.fObject == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
// TODO Later replace this with instanceof call
if (instanceOfMeasure(fValue.fObject)) {
return ((const Measure*) fValue.fObject)->
@ -564,9 +565,9 @@ Formattable::getString(UnicodeString& result, UErrorCode& status) const
result.setToBogus();
} else {
if (fValue.fString == NULL) {
setError(status, U_MEMORY_ALLOCATION_ERROR);
setError(status, U_MEMORY_ALLOCATION_ERROR);
} else {
result = *fValue.fString;
result = *fValue.fString;
}
}
return result;
@ -581,8 +582,8 @@ Formattable::getString(UErrorCode& status) const
return *getBogus();
}
if (fValue.fString == NULL) {
setError(status, U_MEMORY_ALLOCATION_ERROR);
return *getBogus();
setError(status, U_MEMORY_ALLOCATION_ERROR);
return *getBogus();
}
return *fValue.fString;
}

View File

@ -75,12 +75,10 @@ UnicodeReplacer* FunctionReplacer::toReplacer() const {
int32_t FunctionReplacer::replace(Replaceable& text,
int32_t start,
int32_t limit,
int32_t& cursor) {
int32_t& cursor)
{
// First delegate to subordinate replacer
if (replacer == NULL || translit == NULL) {
return -1;
}
int32_t len = replacer->toReplacer()->replace(text, start, limit, cursor);
limit = start + len;
@ -95,15 +93,13 @@ int32_t FunctionReplacer::replace(Replaceable& text,
*/
UnicodeString& FunctionReplacer::toReplacerPattern(UnicodeString& rule,
UBool escapeUnprintable) const {
if (translit != NULL && replacer != NULL) {
UnicodeString str;
rule.truncate(0);
rule.append(AMPERSAND);
rule.append(translit->getID());
rule.append(OPEN);
rule.append(replacer->toReplacer()->toReplacerPattern(str, escapeUnprintable));
rule.append(CLOSE);
}
UnicodeString str;
rule.truncate(0);
rule.append(AMPERSAND);
rule.append(translit->getID());
rule.append(OPEN);
rule.append(replacer->toReplacer()->toReplacerPattern(str, escapeUnprintable));
rule.append(CLOSE);
return rule;
}
@ -112,18 +108,14 @@ UnicodeString& FunctionReplacer::toReplacerPattern(UnicodeString& rule,
*/
void FunctionReplacer::addReplacementSetTo(UnicodeSet& toUnionTo) const {
UnicodeSet set;
if (translit != NULL) {
toUnionTo.addAll(translit->getTargetSet(set));
}
toUnionTo.addAll(translit->getTargetSet(set));
}
/**
* UnicodeFunctor API
*/
void FunctionReplacer::setData(const TransliterationRuleData* d) {
if (replacer != NULL) {
replacer->setData(d);
}
replacer->setData(d);
}
U_NAMESPACE_END

View File

@ -94,7 +94,7 @@ IslamicCalendar::IslamicCalendar(const Locale& aLocale, UErrorCode& success, ECi
: Calendar(TimeZone::createDefault(), aLocale, success),
civil(beCivil)
{
setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
}
IslamicCalendar::IslamicCalendar(const IslamicCalendar& other) : Calendar(other), civil(other.civil) {
@ -234,7 +234,7 @@ int32_t IslamicCalendar::trueMonthStart(int32_t month) const
// moonAge will fail due to memory allocation error
double age = moonAge(origin, status);
if (U_FAILURE(status)) {
goto trueMonthStartEnd;
goto trueMonthStartEnd;
}
if (age >= 0) {
@ -243,7 +243,7 @@ int32_t IslamicCalendar::trueMonthStart(int32_t month) const
origin -= kOneDay;
age = moonAge(origin, status);
if (U_FAILURE(status)) {
goto trueMonthStartEnd;
goto trueMonthStartEnd;
}
} while (age >= 0);
}
@ -253,7 +253,7 @@ int32_t IslamicCalendar::trueMonthStart(int32_t month) const
origin += kOneDay;
age = moonAge(origin, status);
if (U_FAILURE(status)) {
goto trueMonthStartEnd;
goto trueMonthStartEnd;
}
} while (age < 0);
}
@ -283,10 +283,9 @@ double IslamicCalendar::moonAge(UDate time, UErrorCode &status)
umtx_lock(&astroLock);
if(gIslamicCalendarAstro == NULL) {
gIslamicCalendarAstro = new CalendarAstronomer();
// Memory allocation error
if (gIslamicCalendarAstro == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return age;
status = U_MEMORY_ALLOCATION_ERROR;
return age;
}
ucln_i18n_registerCleanup(UCLN_I18N_ISLAMIC_CALENDAR, calendar_islamic_cleanup);
}

View File

@ -1310,7 +1310,7 @@ MessageFormat::parse(const UnicodeString& source,
// If resultArray could not be created, exit out.
// Avoid crossing initialization of variables above.
if (resultArray == NULL) {
goto PARSE_ERROR;
goto PARSE_ERROR;
}
for (int32_t i = 0; i < subformatCount; ++i) {
// match up to format
@ -1465,12 +1465,10 @@ MessageFormat::autoQuoteApostrophe(const UnicodeString& pattern, UErrorCode& sta
static Format* makeRBNF(URBNFRuleSetTag tag, const Locale& locale, const UnicodeString& defaultRuleSet, UErrorCode& ec) {
RuleBasedNumberFormat* fmt = new RuleBasedNumberFormat(tag, locale, ec);
if (fmt == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
ec = U_MEMORY_ALLOCATION_ERROR;
} else if (U_SUCCESS(ec) && defaultRuleSet.length() > 0) {
fmt->setDefaultRuleSet(defaultRuleSet, ec);
if (U_FAILURE(ec)) { // ignore unrecognized default rule set
ec = U_ZERO_ERROR;
}
UErrorCode localStatus = U_ZERO_ERROR; // ignore unrecognized default rule set
fmt->setDefaultRuleSet(defaultRuleSet, localStatus);
}
return fmt;
}

View File

@ -197,7 +197,7 @@ OlsonTimeZone::OlsonTimeZone(const UResourceBundle* top,
data[10] * U_MILLIS_PER_SECOND, ec);
// Make sure finalZone was created
if (finalZone == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
ec = U_MEMORY_ALLOCATION_ERROR;
}
} else {
ec = U_INVALID_FORMAT_ERROR;
@ -650,9 +650,9 @@ OlsonTimeZone::initTransitionRules(UErrorCode& status) {
initialRule = new InitialTimeZoneRule((dst == 0 ? stdName : dstName), raw, dst);
// Check to make sure initialRule was created
if (initialRule == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
firstTZTransitionIdx = 0;
@ -706,9 +706,9 @@ OlsonTimeZone::initTransitionRules(UErrorCode& status) {
raw, dst, times, nTimes, DateTimeRule::UTC_TIME);
// Check for memory allocation error
if (historicRules[typeIdx] == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
}
}
@ -720,9 +720,9 @@ OlsonTimeZone::initTransitionRules(UErrorCode& status) {
*initialRule, *historicRules[typeIdx]);
// Check to make sure firstTZTransition was created.
if (firstTZTransition == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
}
}
@ -733,9 +733,9 @@ OlsonTimeZone::initTransitionRules(UErrorCode& status) {
initialRule = new InitialTimeZoneRule((dst == 0 ? stdName : dstName), raw, dst);
// Check to make sure initialRule was created.
if (initialRule == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
}
if (finalZone != NULL) {
@ -754,9 +754,9 @@ OlsonTimeZone::initTransitionRules(UErrorCode& status) {
finalZoneWithStartYear = (SimpleTimeZone*)finalZone->clone();
// Check to make sure finalZone was actually cloned.
if (finalZoneWithStartYear == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
// finalYear is 1 year before the actual final year.
// See the comment in the construction method.
@ -767,27 +767,27 @@ OlsonTimeZone::initTransitionRules(UErrorCode& status) {
firstFinalRule = tzt.getTo()->clone();
// Check to make sure firstFinalRule received proper clone.
if (firstFinalRule == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
startTime = tzt.getTime();
} else {
finalZoneWithStartYear = (SimpleTimeZone*)finalZone->clone();
// Check to make sure finalZoneWithStartYear received proper clone before dereference.
if (finalZoneWithStartYear == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
finalZone->getID(tzid);
firstFinalRule = new TimeArrayTimeZoneRule(tzid,
finalZone->getRawOffset(), 0, &startTime, 1, DateTimeRule::UTC_TIME);
// Check firstFinalRule was properly created.
if (firstFinalRule == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
}
TimeZoneRule *prevRule = NULL;
@ -801,9 +801,9 @@ OlsonTimeZone::initTransitionRules(UErrorCode& status) {
firstFinalTZTransition = new TimeZoneTransition();
// Check to make sure firstFinalTZTransition was created before dereferencing
if (firstFinalTZTransition == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
status = U_MEMORY_ALLOCATION_ERROR;
deleteTransitionRules();
return;
}
firstFinalTZTransition->setTime(startTime);
firstFinalTZTransition->adoptFrom(prevRule->clone());

View File

@ -61,10 +61,6 @@ UMatchDegree Quantifier::matches(const Replaceable& text,
int32_t& offset,
int32_t limit,
UBool incremental) {
// Exit out if matcher is NULL.
if (matcher == NULL) {
return U_MISMATCH;
}
int32_t start = offset;
uint32_t count = 0;
while (count < maxCount) {
@ -98,10 +94,6 @@ UMatchDegree Quantifier::matches(const Replaceable& text,
*/
UnicodeString& Quantifier::toPattern(UnicodeString& result,
UBool escapeUnprintable) const {
// If matcher is NULL, return result unchanged.
if (matcher == NULL) {
return result;
}
result.truncate(0);
matcher->toMatcher()->toPattern(result, escapeUnprintable);
if (minCount == 0) {
@ -128,14 +120,14 @@ UnicodeString& Quantifier::toPattern(UnicodeString& result,
* Implement UnicodeMatcher
*/
UBool Quantifier::matchesIndexValue(uint8_t v) const {
return (minCount == 0) || (matcher != NULL && matcher->toMatcher()->matchesIndexValue(v));
return (minCount == 0) || matcher->toMatcher()->matchesIndexValue(v);
}
/**
* Implement UnicodeMatcher
*/
void Quantifier::addMatchSetTo(UnicodeSet& toUnionTo) const {
if (matcher != NULL && maxCount > 0) {
if (maxCount > 0) {
matcher->toMatcher()->addMatchSetTo(toUnionTo);
}
}
@ -144,9 +136,7 @@ void Quantifier::addMatchSetTo(UnicodeSet& toUnionTo) const {
* Implement UnicodeFunctor
*/
void Quantifier::setData(const TransliterationRuleData* d) {
if (matcher != NULL) {
matcher->setData(d);
}
}
U_NAMESPACE_END

View File

@ -65,19 +65,19 @@ TransliterationRuleData::TransliterationRuleData(const TransliterationRuleData&
for (i=0; i<variablesLength; ++i) {
variables[i] = other.variables[i]->clone();
if (variables[i] == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
break;
status = U_MEMORY_ALLOCATION_ERROR;
break;
}
}
}
// Remove the array and exit if memory allocation error occured.
if (status == U_MEMORY_ALLOCATION_ERROR) {
for (int32_t n = i-1; n >= 0; n++) {
delete variables[n];
}
uprv_free(variables);
variables = NULL;
return;
if (U_FAILURE(status)) {
for (int32_t n = i-1; n >= 0; n++) {
delete variables[n];
}
uprv_free(variables);
variables = NULL;
return;
}
// Do this last, _after_ setting up variables[].

View File

@ -531,7 +531,7 @@ int32_t RuleHalf::parseSection(const UnicodeString& rule, int32_t pos, int32_t l
new StringMatcher(buf, bufSegStart, buf.length(),
segmentNumber, *parser.curData);
if (m == NULL) {
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
}
// Record and associate object and segment number
@ -572,7 +572,7 @@ int32_t RuleHalf::parseSection(const UnicodeString& rule, int32_t pos, int32_t l
FunctionReplacer *r =
new FunctionReplacer(t, new StringReplacer(output, parser.curData));
if (r == NULL) {
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
}
// Replace the buffer contents with a stand-in
@ -666,7 +666,7 @@ int32_t RuleHalf::parseSection(const UnicodeString& rule, int32_t pos, int32_t l
UnicodeFunctor *m =
new StringMatcher(buf, qstart, qlimit, 0, *parser.curData);
if (m == NULL) {
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
}
int32_t min = 0;
int32_t max = Quantifier::MAX;
@ -683,7 +683,7 @@ int32_t RuleHalf::parseSection(const UnicodeString& rule, int32_t pos, int32_t l
}
m = new Quantifier(m, min, max);
if (m == NULL) {
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
}
buf.truncate(qstart);
buf.append(parser.generateStandInFor(m, status));
@ -1017,12 +1017,12 @@ void TransliteratorParser::parseRules(const UnicodeString& rule,
pos = p;
} else {
if (parsingIDs) {
tempstr = new UnicodeString(idBlockResult);
// NULL pointer check
if (tempstr == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
tempstr = new UnicodeString(idBlockResult);
// NULL pointer check
if (tempstr == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
if (direction == UTRANS_FORWARD)
idBlockVector.addElement(tempstr, status);
else
@ -1032,8 +1032,8 @@ void TransliteratorParser::parseRules(const UnicodeString& rule,
curData = new TransliterationRuleData(status);
// NULL pointer check
if (curData == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
parseData->data = curData;
@ -1058,12 +1058,12 @@ void TransliteratorParser::parseRules(const UnicodeString& rule,
}
if (parsingIDs && idBlockResult.length() > 0) {
tempstr = new UnicodeString(idBlockResult);
// NULL pointer check
if (tempstr == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
tempstr = new UnicodeString(idBlockResult);
// NULL pointer check
if (tempstr == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
if (direction == UTRANS_FORWARD)
idBlockVector.addElement(tempstr, status);
else
@ -1088,8 +1088,8 @@ void TransliteratorParser::parseRules(const UnicodeString& rule,
data->variables = (UnicodeFunctor**)uprv_malloc(data->variablesLength * sizeof(UnicodeFunctor*));
// NULL pointer check
if (data->variables == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
data->variablesAreOwned = (i == 0);
}
@ -1103,12 +1103,11 @@ void TransliteratorParser::parseRules(const UnicodeString& rule,
int32_t pos = -1;
const UHashElement* he = variableNames.nextElement(pos);
while (he != NULL) {
UnicodeString* tempus = (UnicodeString*)(((UnicodeString*)(he->value.pointer))->clone());
// Null pointer check
if (tempus == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
UnicodeString* tempus = (UnicodeString*)(((UnicodeString*)(he->value.pointer))->clone());
if (tempus == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
data->variableNames.put(*((UnicodeString*)(he->key.pointer)),
tempus, status);
he = variableNames.nextElement(pos);
@ -1343,7 +1342,7 @@ int32_t TransliteratorParser::parseRule(const UnicodeString& rule, int32_t pos,
UnicodeString* value = new UnicodeString(right->text);
// NULL pointer check
if (value == NULL) {
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
}
variableNames.put(undefinedVariableName, value, status);
++variableLimit;
@ -1431,7 +1430,7 @@ int32_t TransliteratorParser::parseRule(const UnicodeString& rule, int32_t pos,
segmentsArray = (UnicodeFunctor **)uprv_malloc(segmentObjects.size() * sizeof(UnicodeFunctor *));
// Null pointer check
if (segmentsArray == NULL) {
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
}
segmentObjects.toArray((void**) segmentsArray);
}
@ -1445,8 +1444,8 @@ int32_t TransliteratorParser::parseRule(const UnicodeString& rule, int32_t pos,
status);
//Null pointer check
if (temptr == NULL) {
uprv_free(segmentsArray);
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
uprv_free(segmentsArray);
return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
}
curData->ruleSet.addRule(temptr, status);
@ -1503,8 +1502,8 @@ UChar TransliteratorParser::parseSet(const UnicodeString& rule,
UnicodeSet* set = new UnicodeSet(rule, pos, USET_IGNORE_SPACE, parseData, status);
// Null pointer check
if (set == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return (UChar)0x0000; // Return empty character with error.
status = U_MEMORY_ALLOCATION_ERROR;
return (UChar)0x0000; // Return empty character with error.
}
set->compact();
return generateStandInFor(set, status);
@ -1587,12 +1586,12 @@ void TransliteratorParser::setSegmentObject(int32_t seg, StringMatcher* adopted,
*/
UChar TransliteratorParser::getDotStandIn(UErrorCode& status) {
if (dotStandIn == (UChar) -1) {
UnicodeSet* tempus = new UnicodeSet(DOT_SET, status);
// Null pointer check.
if (tempus == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return (UChar)0x0000;
}
UnicodeSet* tempus = new UnicodeSet(DOT_SET, status);
// Null pointer check.
if (tempus == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return (UChar)0x0000;
}
dotStandIn = generateStandInFor(tempus, status);
}
return dotStandIn;

View File

@ -173,10 +173,6 @@ TransliterationRule::TransliterationRule(TransliterationRule& other) :
segmentsCount = 0;
if (other.segmentsCount > 0) {
segments = (UnicodeFunctor **)uprv_malloc(other.segmentsCount * sizeof(UnicodeFunctor *));
// Null pointer check
if (segments == NULL) {
return;
}
uprv_memcpy(segments, other.segments, other.segmentsCount*sizeof(segments[0]));
}
@ -353,10 +349,6 @@ static inline int32_t posAfter(const Replaceable& str, int32_t pos) {
UMatchDegree TransliterationRule::matchAndReplace(Replaceable& text,
UTransPosition& pos,
UBool incremental) const {
// This occurs if there was a memory allocation error for output.
if (output == NULL) {
return U_MISMATCH;
}
// Matching and replacing are done in one method because the
// replacement operation needs information obtained during the
// match. Another way to do this is to have the match method
@ -473,10 +465,6 @@ UMatchDegree TransliterationRule::matchAndReplace(Replaceable& text,
*/
UnicodeString& TransliterationRule::toRule(UnicodeString& rule,
UBool escapeUnprintable) const {
// This occurs if there was a memory allocation error for output.
if (output == NULL) {
return rule;
}
// Accumulate special characters (and non-specials following them)
// into quoteBuf. Append quoteBuf, within single quotes, when
@ -526,10 +514,6 @@ UnicodeString& TransliterationRule::toRule(UnicodeString& rule,
}
void TransliterationRule::setData(const TransliterationRuleData* d) {
// This occurs if there was a memory allocation error for output.
if (output == NULL) {
return;
}
data = d;
if (anteContext != NULL) anteContext->setData(d);
if (postContext != NULL) postContext->setData(d);
@ -562,10 +546,6 @@ void TransliterationRule::addSourceSetTo(UnicodeSet& toUnionTo) const {
* into the given set.
*/
void TransliterationRule::addTargetSetTo(UnicodeSet& toUnionTo) const {
// This occurs if there was a memory allocation error for output.
if (output == NULL) {
return;
}
output->toReplacer()->addReplacementSetTo(toUnionTo);
}

View File

@ -163,13 +163,13 @@ U_NAMESPACE_BEGIN
TransliterationRuleSet::TransliterationRuleSet(UErrorCode& status) : UMemory() {
ruleVector = new UVector(&_deleteRule, NULL, status);
if (U_FAILURE(status)) {
return;
return;
}
rules = NULL;
maxContextLength = 0;
if (ruleVector == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
rules = NULL;
maxContextLength = 0;
}
/**
@ -188,15 +188,15 @@ TransliterationRuleSet::TransliterationRuleSet(const TransliterationRuleSet& oth
if (other.ruleVector != 0 && ruleVector != 0 && U_SUCCESS(status)) {
len = other.ruleVector->size();
for (i=0; i<len && U_SUCCESS(status); ++i) {
TransliterationRule *tempTranslitRule = new TransliterationRule(*(TransliterationRule*)other.ruleVector->elementAt(i));
// Null pointer test
if (tempTranslitRule == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
break;
}
TransliterationRule *tempTranslitRule = new TransliterationRule(*(TransliterationRule*)other.ruleVector->elementAt(i));
// Null pointer test
if (tempTranslitRule == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
break;
}
ruleVector->addElement(tempTranslitRule, status);
if (U_FAILURE(status)) {
break;
break;
}
}
}

View File

@ -173,8 +173,7 @@ void RegexCompile::compile(
if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class &&
fC.fQuoted == FALSE && // char is not escaped &&
fC.fChar != (UChar32)-1) { // char is not EOF
UnicodeSet *uniset = RegexStaticSets::gStaticSets->fRuleSets[tableEl->fCharClass-128];
if (uniset->contains(fC.fChar)) {
if (RegexStaticSets::gStaticSets->fRuleSets[tableEl->fCharClass-128].contains(fC.fChar)) {
// Table row specified a character class, or set of characters,
// and the current char matches it.
break;
@ -309,8 +308,8 @@ void RegexCompile::compile(
fRXPat->fSets8 = new Regex8BitSet[numSets];
// Null pointer check.
if (fRXPat->fSets8 == NULL) {
e = *fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
e = *fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
int32_t i;
for (i=0; i<numSets; i++) {

View File

@ -153,10 +153,6 @@ fRuleDigitsAlias(NULL)
for (i=0; i<URX_LAST_SET; i++) {
fPropSets[i] = NULL;
}
for (i=0; i<(int32_t)(sizeof(fRuleSets)/sizeof(fRuleSets[0])); i++) {
fRuleSets[i] = NULL;
}
// Then init the sets to their correct values.
fPropSets[URX_ISWORD_SET] = new UnicodeSet(UnicodeString(TRUE, gIsWordPattern, -1), *status);
fPropSets[URX_ISSPACE_SET] = new UnicodeSet(UnicodeString(TRUE, gIsSpacePattern, -1), *status);
@ -212,32 +208,20 @@ fRuleDigitsAlias(NULL)
}
// Sets used while parsing rules, but not referenced from the parse state table
fRuleSets[kRuleSet_rule_char-128] = new UnicodeSet(UnicodeString(TRUE, gRuleSet_rule_char_pattern, -1), *status);
fRuleSets[kRuleSet_digit_char-128] = new UnicodeSet(UnicodeString(TRUE, gRuleSet_digit_char_pattern, -1), *status);
//Check for null pointers
if (fRuleSets[kRuleSet_rule_char-128] == NULL ||
fRuleSets[kRuleSet_digit_char-128] == NULL) {
goto ExitConstrDeleteAll;
}
fRuleDigitsAlias = fRuleSets[kRuleSet_digit_char-128];
fRuleSets[kRuleSet_rule_char-128] = UnicodeSet(UnicodeString(TRUE, gRuleSet_rule_char_pattern, -1), *status);
fRuleSets[kRuleSet_digit_char-128] = UnicodeSet(UnicodeString(TRUE, gRuleSet_digit_char_pattern, -1), *status);
fRuleDigitsAlias = &fRuleSets[kRuleSet_digit_char-128];
for (i=0; i<(int32_t)(sizeof(fRuleSets)/sizeof(fRuleSets[0])); i++) {
if (fRuleSets[i]) {
fRuleSets[i]->compact();
}
fRuleSets[i].compact();
}
return; // If we reached this point, everything is fine so just exit
ExitConstrDeleteAll: // Remove fPropSets and fRuleSets and return error
for (i=0; i<URX_LAST_SET; i++) {
delete fPropSets[i];
fPropSets[i] = NULL;
}
for (i=0; i<(int32_t)(sizeof(fRuleSets)/sizeof(fRuleSets[0])); i++) {
delete fRuleSets[i];
fRuleSets[i] = NULL;
}
*status = U_MEMORY_ALLOCATION_ERROR;
*status = U_MEMORY_ALLOCATION_ERROR;
}
@ -248,10 +232,6 @@ RegexStaticSets::~RegexStaticSets() {
delete fPropSets[i];
fPropSets[i] = NULL;
}
for (i=0; i<(int32_t)(sizeof(fRuleSets)/sizeof(fRuleSets[0])); i++) {
delete fRuleSets[i];
fRuleSets[i] = NULL;
}
fRuleDigitsAlias = NULL;
}

View File

@ -1,7 +1,7 @@
//
// regexst.h
//
// Copyright (C) 2003-2007, International Business Machines Corporation and others.
// Copyright (C) 2003-2008, International Business Machines Corporation and others.
// All Rights Reserved.
//
// This file contains declarations for the class RegexStaticSets
@ -41,7 +41,7 @@ public:
UnicodeSet *fPropSets[URX_LAST_SET]; // The sets for common regex items, e.g. \s
Regex8BitSet fPropSets8[URX_LAST_SET]; // Fast bitmap sets for latin-1 range for above.
UnicodeSet *fRuleSets[10]; // Sets used while parsing regexp patterns.
UnicodeSet fRuleSets[10]; // Sets used while parsing regexp patterns.
UnicodeSet fUnescapeCharSet; // Set of chars handled by unescape when
// encountered with a \ in a pattern.
UnicodeSet *fRuleDigitsAlias;

View File

@ -25,17 +25,14 @@ SearchIterator::SearchIterator(const SearchIterator &other)
{
m_breakiterator_ = other.m_breakiterator_;
m_text_ = other.m_text_;
m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
// Null pointer check.
if (m_search_ != NULL) {
m_search_->breakIter = other.m_search_->breakIter;
m_search_->isCanonicalMatch = other.m_search_->isCanonicalMatch;
m_search_->isOverlap = other.m_search_->isOverlap;
m_search_->matchedIndex = other.m_search_->matchedIndex;
m_search_->matchedLength = other.m_search_->matchedLength;
m_search_->text = other.m_search_->text;
m_search_->textLength = other.m_search_->textLength;
}
m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
m_search_->breakIter = other.m_search_->breakIter;
m_search_->isCanonicalMatch = other.m_search_->isCanonicalMatch;
m_search_->isOverlap = other.m_search_->isOverlap;
m_search_->matchedIndex = other.m_search_->matchedIndex;
m_search_->matchedLength = other.m_search_->matchedLength;
m_search_->text = other.m_search_->text;
m_search_->textLength = other.m_search_->textLength;
}
SearchIterator::~SearchIterator()
@ -51,11 +48,6 @@ void SearchIterator::setAttribute(USearchAttribute attribute,
USearchAttributeValue value,
UErrorCode &status)
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
if (U_SUCCESS(status)) {
switch (attribute)
{
@ -77,10 +69,6 @@ void SearchIterator::setAttribute(USearchAttribute attribute,
USearchAttributeValue SearchIterator::getAttribute(
USearchAttribute attribute) const
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return USEARCH_DEFAULT;
}
switch (attribute) {
case USEARCH_OVERLAP :
return (m_search_->isOverlap == TRUE ? USEARCH_ON : USEARCH_OFF);
@ -94,28 +82,16 @@ USearchAttributeValue SearchIterator::getAttribute(
int32_t SearchIterator::getMatchedStart() const
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return USEARCH_DONE;
}
return m_search_->matchedIndex;
}
int32_t SearchIterator::getMatchedLength() const
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return USEARCH_DONE;
}
return m_search_->matchedLength;
}
void SearchIterator::getMatchedText(UnicodeString &result) const
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return;
}
int32_t matchedindex = m_search_->matchedIndex;
int32_t matchedlength = m_search_->matchedLength;
if (matchedindex != USEARCH_DONE && matchedlength != 0) {
@ -129,11 +105,6 @@ void SearchIterator::getMatchedText(UnicodeString &result) const
void SearchIterator::setBreakIterator(BreakIterator *breakiter,
UErrorCode &status)
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
if (U_SUCCESS(status)) {
m_search_->breakIter = NULL;
// the c++ breakiterator may not make use of ubreakiterator.
@ -149,11 +120,6 @@ const BreakIterator * SearchIterator::getBreakIterator(void) const
void SearchIterator::setText(const UnicodeString &text, UErrorCode &status)
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
if (U_SUCCESS(status)) {
if (text.length() == 0) {
status = U_ILLEGAL_ARGUMENT_ERROR;
@ -186,10 +152,6 @@ UBool SearchIterator::operator==(const SearchIterator &that) const
if (this == &that) {
return TRUE;
}
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return FALSE;
}
return (m_breakiterator_ == that.m_breakiterator_ &&
m_search_->isCanonicalMatch == that.m_search_->isCanonicalMatch &&
m_search_->isOverlap == that.m_search_->isOverlap &&
@ -224,11 +186,7 @@ int32_t SearchIterator::following(int32_t position,
int32_t SearchIterator::last(UErrorCode &status)
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(status)) {
if (U_FAILURE(status)) {
return USEARCH_DONE;
}
setOffset(m_search_->textLength, status);
@ -247,10 +205,6 @@ int32_t SearchIterator::preceding(int32_t position,
int32_t SearchIterator::next(UErrorCode &status)
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_SUCCESS(status)) {
int32_t offset = getOffset();
int32_t matchindex = m_search_->matchedIndex;
@ -296,10 +250,6 @@ int32_t SearchIterator::next(UErrorCode &status)
int32_t SearchIterator::previous(UErrorCode &status)
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_SUCCESS(status)) {
int32_t offset;
if (m_search_->reset) {
@ -342,10 +292,6 @@ int32_t SearchIterator::previous(UErrorCode &status)
void SearchIterator::reset()
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return;
}
UErrorCode status = U_ZERO_ERROR;
setMatchNotFound();
setOffset(0, status);
@ -360,19 +306,16 @@ void SearchIterator::reset()
SearchIterator::SearchIterator()
{
m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
// Null pointer check
if (m_search_ != NULL) {
m_search_->breakIter = NULL;
m_search_->isOverlap = FALSE;
m_search_->isCanonicalMatch = FALSE;
m_search_->isForwardSearching = TRUE;
m_search_->reset = TRUE;
m_search_->matchedIndex = USEARCH_DONE;
m_search_->matchedLength = 0;
m_search_->text = NULL;
m_search_->textLength = 0;
m_breakiterator_ = NULL;
}
m_search_->breakIter = NULL;
m_search_->isOverlap = FALSE;
m_search_->isCanonicalMatch = FALSE;
m_search_->isForwardSearching = TRUE;
m_search_->reset = TRUE;
m_search_->matchedIndex = USEARCH_DONE;
m_search_->matchedLength = 0;
m_search_->text = NULL;
m_search_->textLength = 0;
m_breakiterator_ = NULL;
}
SearchIterator::SearchIterator(const UnicodeString &text,
@ -381,18 +324,15 @@ SearchIterator::SearchIterator(const UnicodeString &text,
m_text_(text)
{
m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
// Null pointer check
if (m_search_ != NULL) {
m_search_->breakIter = NULL;
m_search_->isOverlap = FALSE;
m_search_->isCanonicalMatch = FALSE;
m_search_->isForwardSearching = TRUE;
m_search_->reset = TRUE;
m_search_->matchedIndex = USEARCH_DONE;
m_search_->matchedLength = 0;
m_search_->text = m_text_.getBuffer();
m_search_->textLength = text.length();
}
m_search_->breakIter = NULL;
m_search_->isOverlap = FALSE;
m_search_->isCanonicalMatch = FALSE;
m_search_->isForwardSearching = TRUE;
m_search_->reset = TRUE;
m_search_->matchedIndex = USEARCH_DONE;
m_search_->matchedLength = 0;
m_search_->text = m_text_.getBuffer();
m_search_->textLength = text.length();
}
SearchIterator::SearchIterator(CharacterIterator &text,
@ -400,20 +340,17 @@ SearchIterator::SearchIterator(CharacterIterator &text,
m_breakiterator_(breakiter)
{
m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
// Null pointer check.
if (m_search_ != NULL) {
m_search_->breakIter = NULL;
m_search_->isOverlap = FALSE;
m_search_->isCanonicalMatch = FALSE;
m_search_->isForwardSearching = TRUE;
m_search_->reset = TRUE;
m_search_->matchedIndex = USEARCH_DONE;
m_search_->matchedLength = 0;
text.getText(m_text_);
m_search_->text = m_text_.getBuffer();
m_search_->textLength = m_text_.length();
m_breakiterator_ = breakiter;
}
m_search_->breakIter = NULL;
m_search_->isOverlap = FALSE;
m_search_->isCanonicalMatch = FALSE;
m_search_->isForwardSearching = TRUE;
m_search_->reset = TRUE;
m_search_->matchedIndex = USEARCH_DONE;
m_search_->matchedLength = 0;
text.getText(m_text_);
m_search_->text = m_text_.getBuffer();
m_search_->textLength = m_text_.length();
m_breakiterator_ = breakiter;
}
// protected methods ------------------------------------------------------
@ -436,19 +373,11 @@ SearchIterator & SearchIterator::operator=(const SearchIterator &that)
void SearchIterator::setMatchLength(int32_t length)
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return;
}
m_search_->matchedLength = length;
}
void SearchIterator::setMatchStart(int32_t position)
{
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return;
}
m_search_->matchedIndex = position;
}
@ -457,10 +386,6 @@ void SearchIterator::setMatchNotFound()
setMatchStart(USEARCH_DONE);
setMatchLength(0);
UErrorCode status = U_ZERO_ERROR;
// This is due to memory allocation error in the constructor.
if (m_search_ == NULL) {
return;
}
// by default no errors should be returned here since offsets are within
// range.
if (m_search_->isForwardSearching) {

View File

@ -638,10 +638,6 @@ _appendSymbol(UnicodeString& dst,
void
SimpleDateFormat::appendGMT(UnicodeString &appendTo, Calendar& cal, UErrorCode& status) const{
int32_t offset = cal.get(UCAL_ZONE_OFFSET, status) + cal.get(UCAL_DST_OFFSET, status);
// Caused by memory allocation during fSymbols creation.
if (fSymbols == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(status)) {
return;
}
@ -666,10 +662,6 @@ SimpleDateFormat::appendGMT(UnicodeString &appendTo, Calendar& cal, UErrorCode&
int32_t
SimpleDateFormat::parseGMT(const UnicodeString &text, ParsePosition &pos) const {
// Caused by memory allocation during fSymbols creation.
if (fSymbols == NULL) {
return 0;
}
if (!isDefaultGMTFormat()) {
int32_t start = pos.getIndex();
@ -881,7 +873,6 @@ SimpleDateFormat::parseGMTDefault(const UnicodeString &text, ParsePosition &pos)
UBool
SimpleDateFormat::isDefaultGMTFormat() const {
// fSymbols null pointer is checked in calling methods.
// GMT pattern
if (fSymbols->fGmtFormat.length() == 0) {
// No GMT pattern is set
@ -937,10 +928,6 @@ SimpleDateFormat::formatRFC822TZ(UnicodeString &appendTo, int32_t offset) const
void
SimpleDateFormat::initGMTFormatters(UErrorCode &status) {
// Caused by memory allocation error earlier in fSymbols creation.
if (fSymbols == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(status)) {
return;
}
@ -989,10 +976,6 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
Calendar& cal,
UErrorCode& status) const
{
// Caused by memory allocation during fSymbols creation.
if (fSymbols == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(status)) {
return;
}
@ -1827,12 +1810,6 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
ParsePosition pos(0);
int32_t patternCharIndex;
UnicodeString temp;
// Caused by memory allocation during fSymbols creation.
if (fSymbols == NULL) {
return -1; // Failed
}
UChar *patternCharPtr = u_strchr(DateFormatSymbols::getPatternUChars(), ch);
#if defined (U_DEBUG_CAL)
@ -2383,13 +2360,8 @@ UnicodeString&
SimpleDateFormat::toLocalizedPattern(UnicodeString& result,
UErrorCode& status) const
{
// Caused by memory allocation during fSymbols creation.
if (fSymbols == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
} else {
translatePattern(fPattern, result, DateFormatSymbols::getPatternUChars(), fSymbols->fLocalPatternChars, status);
}
return result;
translatePattern(fPattern, result, DateFormatSymbols::getPatternUChars(), fSymbols->fLocalPatternChars, status);
return result;
}
//----------------------------------------------------------------------
@ -2406,11 +2378,6 @@ void
SimpleDateFormat::applyLocalizedPattern(const UnicodeString& pattern,
UErrorCode &status)
{
// Caused by memory allocation during fSymbols creation.
if (fSymbols == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
translatePattern(pattern, fPattern, fSymbols->fLocalPatternChars, DateFormatSymbols::getPatternUChars(), status);
}

View File

@ -94,7 +94,7 @@ static U_NAMESPACE_QUALIFIER TransliteratorRegistry* registry = 0;
// Macro to check/initialize the registry. ONLY USE WITHIN
// MUTEX. Avoids function call when registry is initialized.
#define HAVE_REGISTRY (registry!=0 || initializeRegistry())
#define HAVE_REGISTRY(status) (registry!=0 || initializeRegistry(status))
// Empty string
static const UChar EMPTY[] = {0}; //""
@ -950,10 +950,13 @@ Transliterator::createInstance(const UnicodeString& ID,
}
// Check null pointer
if (t != NULL) {
t->setID(canonID);
if (globalFilter != NULL) {
t->adoptFilter(globalFilter);
}
t->setID(canonID);
if (globalFilter != NULL) {
t->adoptFilter(globalFilter);
}
}
else if (U_SUCCESS(status)) {
status = U_MEMORY_ALLOCATION_ERROR;
}
return t;
}
@ -975,7 +978,7 @@ Transliterator* Transliterator::createBasicInstance(const UnicodeString& id,
umtx_init(&registryMutex);
umtx_lock(&registryMutex);
if (HAVE_REGISTRY) {
if (HAVE_REGISTRY(ec)) {
t = registry->get(id, alias, ec);
}
umtx_unlock(&registryMutex);
@ -1007,7 +1010,7 @@ Transliterator* Transliterator::createBasicInstance(const UnicodeString& id,
// Step 2. reget
umtx_lock(&registryMutex);
if (HAVE_REGISTRY) {
if (HAVE_REGISTRY(ec)) {
t = registry->reget(id, parser, alias, ec);
}
umtx_unlock(&registryMutex);
@ -1119,12 +1122,12 @@ Transliterator::createFromRules(const UnicodeString& ID,
t = new CompoundTransliterator(transliterators, passNumber - 1, parseError, status);
// Null pointer check
if (t != NULL) {
t->setID(ID);
t->adoptFilter(parser.orphanCompoundFilter());
}
t->setID(ID);
t->adoptFilter(parser.orphanCompoundFilter());
}
}
if (t == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
if (U_SUCCESS(status) && t == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
return t;
}
@ -1177,25 +1180,25 @@ const Transliterator& Transliterator::getElement(int32_t index, UErrorCode& ec)
UnicodeSet& Transliterator::getSourceSet(UnicodeSet& result) const {
handleGetSourceSet(result);
if (filter != NULL) {
UnicodeSet* filterSet;
UBool deleteFilterSet = FALSE;
// Most, but not all filters will be UnicodeSets. Optimize for
// the high-runner case.
if (filter->getDynamicClassID() == UnicodeSet::getStaticClassID()) {
filterSet = (UnicodeSet*) filter;
} else {
filterSet = new UnicodeSet();
// Check null pointer
if (filterSet == NULL) {
return result;
}
deleteFilterSet = TRUE;
filter->addMatchSetTo(*filterSet);
}
result.retainAll(*filterSet);
if (deleteFilterSet) {
delete filterSet;
}
UnicodeSet* filterSet;
UBool deleteFilterSet = FALSE;
// Most, but not all filters will be UnicodeSets. Optimize for
// the high-runner case.
if (filter->getDynamicClassID() == UnicodeSet::getStaticClassID()) {
filterSet = (UnicodeSet*) filter;
} else {
filterSet = new UnicodeSet();
// Check null pointer
if (filterSet == NULL) {
return result;
}
deleteFilterSet = TRUE;
filter->addMatchSetTo(*filterSet);
}
result.retainAll(*filterSet);
if (deleteFilterSet) {
delete filterSet;
}
}
return result;
}
@ -1214,7 +1217,8 @@ void U_EXPORT2 Transliterator::registerFactory(const UnicodeString& id,
Transliterator::Token context) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
if (HAVE_REGISTRY) {
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_registerFactory(id, factory, context);
}
}
@ -1224,7 +1228,8 @@ void U_EXPORT2 Transliterator::registerFactory(const UnicodeString& id,
void Transliterator::_registerFactory(const UnicodeString& id,
Transliterator::Factory factory,
Transliterator::Token context) {
registry->put(id, factory, context, TRUE);
UErrorCode ec = U_ZERO_ERROR;
registry->put(id, factory, context, TRUE, ec);
}
// To be called only by Transliterator subclasses that are called
@ -1252,27 +1257,31 @@ void Transliterator::_registerSpecialInverse(const UnicodeString& target,
void U_EXPORT2 Transliterator::registerInstance(Transliterator* adoptedPrototype) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
if (HAVE_REGISTRY) {
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_registerInstance(adoptedPrototype);
}
}
void Transliterator::_registerInstance(Transliterator* adoptedPrototype) {
registry->put(adoptedPrototype, TRUE);
UErrorCode ec = U_ZERO_ERROR;
registry->put(adoptedPrototype, TRUE, ec);
}
void U_EXPORT2 Transliterator::registerAlias(const UnicodeString& aliasID,
const UnicodeString& realID) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
if (HAVE_REGISTRY) {
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_registerAlias(aliasID, realID);
}
}
void Transliterator::_registerAlias(const UnicodeString& aliasID,
const UnicodeString& realID) {
registry->put(aliasID, realID, FALSE, TRUE);
UErrorCode ec = U_ZERO_ERROR;
registry->put(aliasID, realID, FALSE, TRUE, ec);
}
/**
@ -1286,7 +1295,8 @@ void Transliterator::_registerAlias(const UnicodeString& aliasID,
void U_EXPORT2 Transliterator::unregister(const UnicodeString& ID) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
if (HAVE_REGISTRY) {
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
registry->remove(ID);
}
}
@ -1298,9 +1308,14 @@ void U_EXPORT2 Transliterator::unregister(const UnicodeString& ID) {
* i from 0 to countAvailableIDs() - 1.
*/
int32_t U_EXPORT2 Transliterator::countAvailableIDs(void) {
int32_t retVal = 0;
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
return HAVE_REGISTRY ? registry->countAvailableIDs() : 0;
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
retVal = registry->countAvailableIDs();
}
return retVal;
}
/**
@ -1313,7 +1328,8 @@ const UnicodeString& U_EXPORT2 Transliterator::getAvailableID(int32_t index) {
const UnicodeString* result = NULL;
umtx_init(&registryMutex);
umtx_lock(&registryMutex);
if (HAVE_REGISTRY) {
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
result = &registry->getAvailableID(index);
}
umtx_unlock(&registryMutex);
@ -1326,7 +1342,7 @@ StringEnumeration* U_EXPORT2 Transliterator::getAvailableIDs(UErrorCode& ec) {
StringEnumeration* result = NULL;
umtx_init(&registryMutex);
umtx_lock(&registryMutex);
if (HAVE_REGISTRY) {
if (HAVE_REGISTRY(ec)) {
result = registry->getAvailableIDs();
}
umtx_unlock(&registryMutex);
@ -1339,14 +1355,16 @@ StringEnumeration* U_EXPORT2 Transliterator::getAvailableIDs(UErrorCode& ec) {
int32_t U_EXPORT2 Transliterator::countAvailableSources(void) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
return HAVE_REGISTRY ? _countAvailableSources() : 0;
UErrorCode ec = U_ZERO_ERROR;
return HAVE_REGISTRY(ec) ? _countAvailableSources() : 0;
}
UnicodeString& U_EXPORT2 Transliterator::getAvailableSource(int32_t index,
UnicodeString& result) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
if (HAVE_REGISTRY) {
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_getAvailableSource(index, result);
}
return result;
@ -1355,7 +1373,8 @@ UnicodeString& U_EXPORT2 Transliterator::getAvailableSource(int32_t index,
int32_t U_EXPORT2 Transliterator::countAvailableTargets(const UnicodeString& source) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
return HAVE_REGISTRY ? _countAvailableTargets(source) : 0;
UErrorCode ec = U_ZERO_ERROR;
return HAVE_REGISTRY(ec) ? _countAvailableTargets(source) : 0;
}
UnicodeString& U_EXPORT2 Transliterator::getAvailableTarget(int32_t index,
@ -1363,7 +1382,8 @@ UnicodeString& U_EXPORT2 Transliterator::getAvailableTarget(int32_t index,
UnicodeString& result) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
if (HAVE_REGISTRY) {
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_getAvailableTarget(index, source, result);
}
return result;
@ -1373,7 +1393,8 @@ int32_t U_EXPORT2 Transliterator::countAvailableVariants(const UnicodeString& so
const UnicodeString& target) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
return HAVE_REGISTRY ? _countAvailableVariants(source, target) : 0;
UErrorCode ec = U_ZERO_ERROR;
return HAVE_REGISTRY(ec) ? _countAvailableVariants(source, target) : 0;
}
UnicodeString& U_EXPORT2 Transliterator::getAvailableVariant(int32_t index,
@ -1382,7 +1403,8 @@ UnicodeString& U_EXPORT2 Transliterator::getAvailableVariant(int32_t index,
UnicodeString& result) {
umtx_init(&registryMutex);
Mutex lock(&registryMutex);
if (HAVE_REGISTRY) {
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_getAvailableVariant(index, source, target, result);
}
return result;
@ -1446,13 +1468,11 @@ UChar Transliterator::filteredCharAt(const Replaceable& text, int32_t i) const {
* unlock, since no other thread that is waiting on the registryMutex
* cannot itself proceed until the registry is initialized.
*/
UBool Transliterator::initializeRegistry() {
UBool Transliterator::initializeRegistry(UErrorCode &status) {
if (registry != 0) {
return TRUE;
}
UErrorCode status = U_ZERO_ERROR;
registry = new TransliteratorRegistry(status);
if (registry == 0 || U_FAILURE(status)) {
delete registry;
@ -1528,13 +1548,13 @@ UBool Transliterator::initializeRegistry() {
(ures_getUnicodeStringByKey(res, "direction", &status).charAt(0) ==
0x0046 /*F*/) ?
UTRANS_FORWARD : UTRANS_REVERSE;
registry->put(id, UnicodeString(TRUE, resString, len), dir, TRUE, visible);
registry->put(id, UnicodeString(TRUE, resString, len), dir, TRUE, visible, status);
}
break;
case 0x61: // 'a'
// 'alias'; row[2]=createInstance argument
resString = ures_getString(res, &len, &status);
registry->put(id, UnicodeString(TRUE, resString, len), TRUE, TRUE);
registry->put(id, UnicodeString(TRUE, resString, len), TRUE, TRUE, status);
break;
}
}
@ -1560,27 +1580,29 @@ UBool Transliterator::initializeRegistry() {
NameUnicodeTransliterator* tempNameUnicodeTranslit = new NameUnicodeTransliterator();
// Check for null pointers
if (tempNullTranslit == NULL || tempLowercaseTranslit == NULL || tempUppercaseTranslit == NULL ||
tempTitlecaseTranslit == NULL || tempUnicodeTranslit == NULL || tempNameUnicodeTranslit == NULL) {
delete tempNullTranslit;
delete tempLowercaseTranslit;
delete tempUppercaseTranslit;
delete tempTitlecaseTranslit;
delete tempUnicodeTranslit;
delete tempNameUnicodeTranslit;
// Since there was an error, remove registry
delete registry;
registry = NULL;
return 0;
tempTitlecaseTranslit == NULL || tempUnicodeTranslit == NULL || tempNameUnicodeTranslit == NULL)
{
delete tempNullTranslit;
delete tempLowercaseTranslit;
delete tempUppercaseTranslit;
delete tempTitlecaseTranslit;
delete tempUnicodeTranslit;
delete tempNameUnicodeTranslit;
// Since there was an error, remove registry
delete registry;
registry = NULL;
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
registry->put(tempNullTranslit, TRUE);
registry->put(tempLowercaseTranslit, TRUE);
registry->put(tempUppercaseTranslit, TRUE);
registry->put(tempTitlecaseTranslit, TRUE);
registry->put(tempUnicodeTranslit, TRUE);
registry->put(tempNameUnicodeTranslit, TRUE);
registry->put(tempNullTranslit, TRUE, status);
registry->put(tempLowercaseTranslit, TRUE, status);
registry->put(tempUppercaseTranslit, TRUE, status);
registry->put(tempTitlecaseTranslit, TRUE, status);
registry->put(tempUnicodeTranslit, TRUE, status);
registry->put(tempNameUnicodeTranslit, TRUE, status);
RemoveTransliterator::registerIDs(); // Must be within mutex
EscapeTransliterator::registerIDs();

View File

@ -610,62 +610,70 @@ Transliterator* TransliteratorRegistry::reget(const UnicodeString& ID,
}
void TransliteratorRegistry::put(Transliterator* adoptedProto,
UBool visible) {
UBool visible,
UErrorCode& ec)
{
Entry *entry = new Entry();
// Null pointer check
if (entry != NULL) {
entry->adoptPrototype(adoptedProto);
registerEntry(adoptedProto->getID(), entry, visible);
if (entry == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
return;
}
entry->adoptPrototype(adoptedProto);
registerEntry(adoptedProto->getID(), entry, visible);
}
void TransliteratorRegistry::put(const UnicodeString& ID,
Transliterator::Factory factory,
Transliterator::Token context,
UBool visible) {
UBool visible,
UErrorCode& ec) {
Entry *entry = new Entry();
// Null pointer check
if (entry != NULL) {
entry->setFactory(factory, context);
registerEntry(ID, entry, visible);
if (entry == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
return;
}
entry->setFactory(factory, context);
registerEntry(ID, entry, visible);
}
void TransliteratorRegistry::put(const UnicodeString& ID,
const UnicodeString& resourceName,
UTransDirection dir,
UBool readonlyResourceAlias,
UBool visible) {
UBool visible,
UErrorCode& ec) {
Entry *entry = new Entry();
// Null pointer check
if (entry != NULL) {
entry->entryType = (dir == UTRANS_FORWARD) ? Entry::RULES_FORWARD
: Entry::RULES_REVERSE;
if (readonlyResourceAlias) {
entry->stringArg.setTo(TRUE, resourceName.getBuffer(), -1);
}
else {
entry->stringArg = resourceName;
}
registerEntry(ID, entry, visible);
if (entry == NULL) {
ec = U_MEMORY_ALLOCATION_ERROR;
return;
}
entry->entryType = (dir == UTRANS_FORWARD) ? Entry::RULES_FORWARD
: Entry::RULES_REVERSE;
if (readonlyResourceAlias) {
entry->stringArg.setTo(TRUE, resourceName.getBuffer(), -1);
}
else {
entry->stringArg = resourceName;
}
registerEntry(ID, entry, visible);
}
void TransliteratorRegistry::put(const UnicodeString& ID,
const UnicodeString& alias,
UBool readonlyAliasAlias,
UBool visible) {
UBool visible,
UErrorCode& ec) {
Entry *entry = new Entry();
// Null pointer check
if (entry != NULL) {
entry->entryType = Entry::ALIAS;
if (readonlyAliasAlias) {
entry->stringArg.setTo(TRUE, alias.getBuffer(), -1);
}
else {
entry->stringArg = alias;
}
registerEntry(ID, entry, visible);
entry->entryType = Entry::ALIAS;
if (readonlyAliasAlias) {
entry->stringArg.setTo(TRUE, alias.getBuffer(), -1);
}
else {
entry->stringArg = alias;
}
registerEntry(ID, entry, visible);
}
}

View File

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2001-2006, International Business Machines
* Copyright (c) 2001-2008, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
@ -202,7 +202,8 @@ class TransliteratorRegistry : public UMemory {
* underlying static locale resource store is masked.
*/
void put(Transliterator* adoptedProto,
UBool visible);
UBool visible,
UErrorCode& ec);
/**
* Register an ID and a factory function pointer. This adds an
@ -212,7 +213,8 @@ class TransliteratorRegistry : public UMemory {
void put(const UnicodeString& ID,
Transliterator::Factory factory,
Transliterator::Token context,
UBool visible);
UBool visible,
UErrorCode& ec);
/**
* Register an ID and a resource name. This adds an entry to the
@ -223,7 +225,8 @@ class TransliteratorRegistry : public UMemory {
const UnicodeString& resourceName,
UTransDirection dir,
UBool readonlyResourceAlias,
UBool visible);
UBool visible,
UErrorCode& ec);
/**
* Register an ID and an alias ID. This adds an entry to the
@ -233,7 +236,8 @@ class TransliteratorRegistry : public UMemory {
void put(const UnicodeString& ID,
const UnicodeString& alias,
UBool readonlyAliasAlias,
UBool visible);
UBool visible,
UErrorCode& ec);
/**
* Unregister an ID. This removes an entry from the dynamic store

View File

@ -379,10 +379,8 @@ uprv_cnttab_insertContraction(CntTable *table, uint32_t element, UChar codePoint
if((element == 0xFFFFFF) || (tbl = table->elements[element]) == NULL) {
tbl = addATableElement(table, &element, status);
// Check for null pointer
if (tbl == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return 0;
if (U_FAILURE(*status)) {
return 0;
}
}
@ -424,10 +422,8 @@ uprv_cnttab_addContraction(CntTable *table, uint32_t element, UChar codePoint, u
if((element == 0xFFFFFF) || (tbl = table->elements[element]) == NULL) {
tbl = addATableElement(table, &element, status);
// Check for null pointer
if (tbl == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return 0;
if (U_FAILURE(*status)) {
return 0;
}
}
@ -454,10 +450,8 @@ uprv_cnttab_setContraction(CntTable *table, uint32_t element, uint32_t offset, U
if((element == 0xFFFFFF) || (tbl = table->elements[element]) == NULL) {
tbl = addATableElement(table, &element, status);
// Check for null pointer
if (tbl == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return 0;
if (U_FAILURE(*status)) {
return 0;
}
}

View File

@ -148,13 +148,12 @@ uprv_uca_initTempTable(UCATableHeader *image, UColOptionSet *opts, const UCollat
UCOL_SPECIAL_FLAG | (initTag<<24),
UCOL_SPECIAL_FLAG | (supplementaryInitTag << 24),
TRUE); // Do your own mallocs for the structure, array and have linear Latin 1
if (t->mapping == NULL) {
if (U_FAILURE(*status)) {
goto allocation_failure;
}
t->prefixLookup = uhash_open(prefixLookupHash, prefixLookupComp, NULL, status);
// Check for allocation error.
if (t->prefixLookup == NULL) {
goto allocation_failure;
if (U_FAILURE(*status)) {
goto allocation_failure;
}
uhash_setValueDeleter(t->prefixLookup, uhash_freeBlock);
@ -1919,9 +1918,8 @@ uprv_uca_canonicalClosure(tempUCATable *t,
UCollator *tempColl = NULL;
tempUCATable *tempTable = uprv_uca_cloneTempTable(t, status);
// Check for null pointer
if (tempTable == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return 0;
if (U_FAILURE(*status)) {
return 0;
}
UCATableHeader *tempData = uprv_uca_assembleTable(tempTable, status);
@ -1946,9 +1944,8 @@ uprv_uca_canonicalClosure(tempUCATable *t,
/* produce canonical closure */
UCollationElements* colEl = ucol_openElements(tempColl, NULL, 0, status);
// Check for null pointer
if (colEl == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return 0;
if (U_FAILURE(*status)) {
return 0;
}
context.t = t;
context.tempColl = tempColl;

View File

@ -104,10 +104,8 @@ ucol_open_internal(const char *loc,
if(*status == U_MISSING_RESOURCE_ERROR) { /* We didn't find the tailoring data, we fallback to the UCA */
*status = U_USING_DEFAULT_WARNING;
result = ucol_initCollator(UCA->image, result, UCA, status);
// Check for null result
if (result == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
goto clean;
if (U_FAILURE(*status)) {
goto clean;
}
// if we use UCA, real locale is root
ures_close(b);

View File

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (C) 1999-2007, International Business Machines
* Copyright (C) 1999-2008, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
@ -1266,7 +1266,7 @@ public:
virtual UClassID getDynamicClassID(void) const = 0;
private:
static UBool initializeRegistry(void);
static UBool initializeRegistry(UErrorCode &status);
public:
/**

View File

@ -274,8 +274,8 @@ unum_formatDoubleCurrency(const UNumberFormat* fmt,
CurrencyAmount *tempCurrAmnt = new CurrencyAmount(number, currency, *status);
// Check for null pointer.
if (tempCurrAmnt == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return -1;
*status = U_MEMORY_ALLOCATION_ERROR;
return -1;
}
Formattable n(tempCurrAmnt);
((const NumberFormat*)fmt)->format(n, res, fp, *status);