In the C++ break iterator code, change all use of NULL to nullptr.
This is in preparation for follow-on PRs to improve out-of-memory error handling
in Break Iterators, keeping use of nullptr consistent between old and new
or updated code.
const LanguageBreakEngine *
ICULanguageBreakFactory::getEngineFor(UChar32 c) {
- const LanguageBreakEngine *lbe = NULL;
+ const LanguageBreakEngine *lbe = nullptr;
UErrorCode status = U_ZERO_ERROR;
static UMutex gBreakEngineMutex;
int32_t i = fEngines->size();
while (--i >= 0) {
lbe = (const LanguageBreakEngine *)(fEngines->elementAt(i));
- if (lbe != NULL && lbe->handles(c)) {
+ if (lbe != nullptr && lbe->handles(c)) {
return lbe;
}
}
}
status = U_ZERO_ERROR; // fallback to dictionary based
DictionaryMatcher *m = loadDictionaryMatcherFor(code);
- if (m != NULL) {
+ if (m != nullptr) {
switch(code) {
case USCRIPT_THAI:
engine = new ThaiBreakEngine(m, status);
default:
break;
}
- if (engine == NULL) {
+ if (engine == nullptr) {
delete m;
}
else if (U_FAILURE(status)) {
delete engine;
- engine = NULL;
+ engine = nullptr;
}
return engine;
}
}
- return NULL;
+ return nullptr;
}
DictionaryMatcher *
ures_getStringByKeyWithFallback(b, uscript_getShortName(script), &dictnlength, &status);
if (U_FAILURE(status)) {
ures_close(b);
- return NULL;
+ return nullptr;
}
CharString dictnbuf;
CharString ext;
const UChar *extStart = u_memrchr(dictfname, 0x002e, dictnlength); // last dot
- if (extStart != NULL) {
+ if (extStart != nullptr) {
int32_t len = (int32_t)(extStart - dictfname);
ext.appendInvariantChars(UnicodeString(false, extStart + 1, dictnlength - len - 1), status);
dictnlength = len;
const int32_t *indexes = (const int32_t *)data;
const int32_t offset = indexes[DictionaryData::IX_STRING_TRIE_OFFSET];
const int32_t trieType = indexes[DictionaryData::IX_TRIE_TYPE] & DictionaryData::TRIE_TYPE_MASK;
- DictionaryMatcher *m = NULL;
+ DictionaryMatcher *m = nullptr;
if (trieType == DictionaryData::TRIE_TYPE_BYTES) {
const int32_t transform = indexes[DictionaryData::IX_TRANSFORM];
const char *characters = (const char *)(data + offset);
const UChar *characters = (const UChar *)(data + offset);
m = new UCharsDictionaryMatcher(characters, file);
}
- if (m == NULL) {
+ if (m == nullptr) {
// no matcher exists to take ownership - either we are an invalid
// type or memory allocation failed
udata_close(file);
}
return m;
- } else if (dictfname != NULL) {
+ } else if (dictfname != nullptr) {
// we don't have a dictionary matcher.
- // returning NULL here will cause us to fail to find a dictionary break engine, as expected
+ // returning nullptr here will cause us to fail to find a dictionary break engine, as expected
status = U_ZERO_ERROR;
- return NULL;
+ return nullptr;
}
- return NULL;
+ return nullptr;
}
U_NAMESPACE_END
* <p>Create a DictionaryMatcher for the specified script and break type.</p>
* @param script An ISO 15924 script code that identifies the dictionary to be
* created.
- * @return A DictionaryMatcher with the desired characteristics, or NULL.
+ * @return A DictionaryMatcher with the desired characteristics, or nullptr.
*/
virtual DictionaryMatcher *loadDictionaryMatcherFor(UScriptCode script);
};
char ext[4]={'\0'};
CharString actualLocale;
int32_t size;
- const UChar* brkfname = NULL;
+ const UChar* brkfname = nullptr;
UResourceBundle brkRulesStack;
UResourceBundle brkNameStack;
UResourceBundle *brkRules = &brkRulesStack;
UResourceBundle *brkName = &brkNameStack;
- RuleBasedBreakIterator *result = NULL;
+ RuleBasedBreakIterator *result = nullptr;
if (U_FAILURE(status))
- return NULL;
+ return nullptr;
ures_initStackObject(brkRules);
ures_initStackObject(brkName);
UChar* extStart=u_strchr(brkfname, 0x002e);
int len = 0;
- if(extStart!=NULL){
+ if (extStart != nullptr){
len = (int)(extStart-brkfname);
u_UCharsToChars(extStart+1, ext, sizeof(ext)); // nul terminates the buff
u_UCharsToChars(brkfname, fnbuff, len);
UDataMemory* file = udata_open(U_ICUDATA_BRKITR, ext, fnbuff, &status);
if (U_FAILURE(status)) {
ures_close(b);
- return NULL;
+ return nullptr;
}
// Create a RuleBasedBreakIterator
- result = new RuleBasedBreakIterator(file, uprv_strstr(type, "phrase") != NULL, status);
+ result = new RuleBasedBreakIterator(file, uprv_strstr(type, "phrase") != nullptr, status);
// If there is a result, set the valid locale and actual locale, and the kind
- if (U_SUCCESS(status) && result != NULL) {
+ if (U_SUCCESS(status) && result != nullptr) {
U_LOCALE_BASED(locBased, *(BreakIterator*)result);
locBased.setLocaleIDs(ures_getLocaleByType(b, ULOC_VALID_LOCALE, &status),
actualLocale.data());
ures_close(b);
- if (U_FAILURE(status) && result != NULL) { // Sometimes redundant check, but simple
+ if (U_FAILURE(status) && result != nullptr) { // Sometimes redundant check, but simple
delete result;
- return NULL;
+ return nullptr;
}
- if (result == NULL) {
+ if (result == nullptr) {
udata_close(file);
if (U_SUCCESS(status)) {
status = U_MEMORY_ALLOCATION_ERROR;
U_NAMESPACE_END
static icu::UInitOnce gInitOnceBrkiter {};
-static icu::ICULocaleService* gService = NULL;
+static icu::ICULocaleService* gService = nullptr;
#if !UCONFIG_NO_SERVICE
if (gService) {
delete gService;
- gService = NULL;
+ gService = nullptr;
}
gInitOnceBrkiter.reset();
#endif
static inline UBool
hasService(void)
{
- return !gInitOnceBrkiter.isReset() && getService() != NULL;
+ return !gInitOnceBrkiter.isReset() && getService() != nullptr;
}
// -------------------------------------
BreakIterator::registerInstance(BreakIterator* toAdopt, const Locale& locale, UBreakIteratorType kind, UErrorCode& status)
{
ICULocaleService *service = getService();
- if (service == NULL) {
+ if (service == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
}
return service->registerInstance(toAdopt, locale, kind, status);
}
BreakIterator::getAvailableLocales(void)
{
ICULocaleService *service = getService();
- if (service == NULL) {
- return NULL;
+ if (service == nullptr) {
+ return nullptr;
}
return service->getAvailableLocales();
}
BreakIterator::createInstance(const Locale& loc, int32_t kind, UErrorCode& status)
{
if (U_FAILURE(status)) {
- return NULL;
+ return nullptr;
}
#if !UCONFIG_NO_SERVICE
// handleDefault calls), so we don't touch it. YES, A COMMENT
// THIS LONG is a sign of bad code -- so the action item is to
// revisit this in ICU 3.0 and clean it up/fix it/remove it.
- if (U_SUCCESS(status) && (result != NULL) && *actualLoc.getName() != 0) {
+ if (U_SUCCESS(status) && (result != nullptr) && *actualLoc.getName() != 0) {
U_LOCALE_BASED(locBased, *result);
locBased.setLocaleIDs(actualLoc.getName(), actualLoc.getName());
}
{
if (U_FAILURE(status)) {
- return NULL;
+ return nullptr;
}
- BreakIterator *result = NULL;
+ BreakIterator *result = nullptr;
switch (kind) {
case UBRK_CHARACTER:
{
}
if (U_FAILURE(status)) {
- return NULL;
+ return nullptr;
}
return result;
int32_t start = (int32_t)utext_getNativeIndex(text);
if (start != offset) {
offset = start;
- count = dict->matches(text, rangeEnd-start, UPRV_LENGTHOF(cuLengths), cuLengths, cpLengths, NULL, &prefix);
+ count = dict->matches(text, rangeEnd-start, UPRV_LENGTHOF(cuLengths), cuLengths, cpLengths, nullptr, &prefix);
// Dictionary leaves text after longest prefix, not longest word. Back up.
if (count <= 0) {
utext_setNativeIndex(text, start);
UnicodeString inString;
// inputMap[inStringIndex] = corresponding native index from UText inText.
- // If NULL then mapping is 1:1
+ // If nullptr then mapping is 1:1
LocalPointer<UVector32> inputMap;
// if UText has the input string as one contiguous UTF-16 chunk
int32_t count;
utext_setNativeIndex(&fu, ix);
count = fDictionary->matches(&fu, maxWordSize, numCodePts,
- NULL, lengths.getBuffer(), values.getBuffer(), NULL);
+ nullptr, lengths.getBuffer(), values.getBuffer(), nullptr);
// Note: lengths is filled with code point lengths
- // The NULL parameter is the ignored code unit lengths.
+ // The nullptr parameter is the ignored code unit lengths.
// if there are no single character matches found in the dictionary
// starting with this character, treat character as a 1-character word
inline UBool add(const UnicodeString& str, UErrorCode &status) {
if(U_FAILURE(status)) return false;
UnicodeString *t = new UnicodeString(str);
- if(t==NULL) {
+ if(t==nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; return false;
}
return adopt(t, status);
return clone();
}
virtual SimpleFilteredSentenceBreakIterator* clone() const override { return new SimpleFilteredSentenceBreakIterator(*this); }
- virtual UClassID getDynamicClassID(void) const override { return NULL; }
+ virtual UClassID getDynamicClassID(void) const override { return nullptr; }
virtual bool operator==(const BreakIterator& o) const override { if(this==&o) return true; return false; }
/* -- text modifying -- */
#endif
return; // leaves the builder empty, if you try to use it.
}
- LocalUResourceBundlePointer exceptions(ures_getByKeyWithFallback(b.getAlias(), "exceptions", NULL, &subStatus));
+ LocalUResourceBundlePointer exceptions(ures_getByKeyWithFallback(b.getAlias(), "exceptions", nullptr, &subStatus));
if (U_FAILURE(subStatus) || (subStatus == U_USING_DEFAULT_WARNING) ) {
status = subStatus; // copy the failing status
#if FB_DEBUG
#endif
return; // leaves the builder empty, if you try to use it.
}
- LocalUResourceBundlePointer breaks(ures_getByKeyWithFallback(exceptions.getAlias(), "SentenceBreak", NULL, &subStatus));
+ LocalUResourceBundlePointer breaks(ures_getByKeyWithFallback(exceptions.getAlias(), "SentenceBreak", nullptr, &subStatus));
#if FB_DEBUG
{
LocalPointer<UCharsTrieBuilder> builder(new UCharsTrieBuilder(status), status);
LocalPointer<UCharsTrieBuilder> builder2(new UCharsTrieBuilder(status), status);
if(U_FAILURE(status)) {
- return NULL;
+ return nullptr;
}
int32_t revCount = 0;
} else {
FB_TRACE("build",abbr,false,i);
status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
}
partials[n] = 0; // default: not partial
n++;
////if(debug2) u_printf("SUPPRESS- not Added(%d): /%S/ status=%s\n",partials[i], ustrs[i].getTerminatedBuffer(), u_errorName(status));
}
}
- FB_TRACE("AbbrCount",NULL,false, subCount);
+ FB_TRACE("AbbrCount",nullptr,false, subCount);
if(revCount>0) {
backwardsTrie.adoptInstead(builder->build(USTRINGTRIE_BUILD_FAST, status));
if(U_FAILURE(status)) {
- FB_TRACE(u_errorName(status),NULL,false, -1);
- return NULL;
+ FB_TRACE(u_errorName(status),nullptr,false, -1);
+ return nullptr;
}
}
if(fwdCount>0) {
forwardsPartialTrie.adoptInstead(builder2->build(USTRINGTRIE_BUILD_FAST, status));
if(U_FAILURE(status)) {
- FB_TRACE(u_errorName(status),NULL,false, -1);
- return NULL;
+ FB_TRACE(u_errorName(status),nullptr,false, -1);
+ return nullptr;
}
}
FilteredBreakIteratorBuilder *
FilteredBreakIteratorBuilder::createInstance(const Locale& where, UErrorCode& status) {
- if(U_FAILURE(status)) return NULL;
+ if(U_FAILURE(status)) return nullptr;
LocalPointer<FilteredBreakIteratorBuilder> ret(new SimpleFilteredBreakIteratorBuilder(where, status), status);
- return (U_SUCCESS(status))? ret.orphan(): NULL;
+ return (U_SUCCESS(status))? ret.orphan(): nullptr;
}
FilteredBreakIteratorBuilder *
FilteredBreakIteratorBuilder *
FilteredBreakIteratorBuilder::createEmptyInstance(UErrorCode& status) {
- if(U_FAILURE(status)) return NULL;
+ if(U_FAILURE(status)) return nullptr;
LocalPointer<FilteredBreakIteratorBuilder> ret(new SimpleFilteredBreakIteratorBuilder(status), status);
- return (U_SUCCESS(status))? ret.orphan(): NULL;
+ return (U_SUCCESS(status))? ret.orphan(): nullptr;
}
U_NAMESPACE_END
if (U_FAILURE(status)) {
return;
}
- if (compiledRules == NULL || ruleLength < sizeof(RBBIDataHeader)) {
+ if (compiledRules == nullptr || ruleLength < sizeof(RBBIDataHeader)) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
}
BreakIterator::operator=(that);
- if (fLanguageBreakEngines != NULL) {
+ if (fLanguageBreakEngines != nullptr) {
delete fLanguageBreakEngines;
- fLanguageBreakEngines = NULL; // Just rebuild for now
+ fLanguageBreakEngines = nullptr; // Just rebuild for now
}
// TODO: clone fLanguageBreakEngines from "that"
UErrorCode status = U_ZERO_ERROR;
}
fCharIter = &fSCharIter;
- if (that.fCharIter != NULL && that.fCharIter != &that.fSCharIter) {
+ if (that.fCharIter != nullptr && that.fCharIter != &that.fSCharIter) {
// This is a little bit tricky - it will initially appear that
// this->fCharIter is adopted, even if that->fCharIter was
// not adopted. That's ok.
fCharIter = that.fCharIter->clone();
}
fSCharIter = that.fSCharIter;
- if (fCharIter == NULL) {
+ if (fCharIter == nullptr) {
fCharIter = &fSCharIter;
}
- if (fData != NULL) {
+ if (fData != nullptr) {
fData->removeReference();
- fData = NULL;
+ fData = nullptr;
}
- if (that.fData != NULL) {
+ if (that.fData != nullptr) {
fData = that.fData->addReference();
}
return;
}
- utext_openUChars(&fText, NULL, 0, &status);
+ utext_openUChars(&fText, nullptr, 0, &status);
fDictionaryCache = new DictionaryCache(this, status);
fBreakCache = new BreakCache(this, status);
- if (U_SUCCESS(status) && (fDictionaryCache == NULL || fBreakCache == NULL)) {
+ if (U_SUCCESS(status) && (fDictionaryCache == nullptr || fBreakCache == nullptr)) {
status = U_MEMORY_ALLOCATION_ERROR;
}
}
if (that2.fData == fData ||
- (fData != NULL && that2.fData != NULL && *that2.fData == *fData)) {
+ (fData != nullptr && that2.fData != nullptr && *that2.fData == *fData)) {
// The two break iterators are using the same rules.
return true;
}
int32_t
RuleBasedBreakIterator::hashCode(void) const {
int32_t hash = 0;
- if (fData != NULL) {
+ if (fData != nullptr) {
hash = fData->hashCode();
}
return hash;
UErrorCode status = U_ZERO_ERROR;
fBreakCache->reset();
fDictionaryCache->reset();
- if (newText==NULL || newText->startIndex() != 0) {
+ if (newText==nullptr || newText->startIndex() != 0) {
// startIndex !=0 wants to be an error, but there's no way to report it.
// Make the iterator text be an empty string.
- utext_openUChars(&fText, NULL, 0, &status);
+ utext_openUChars(&fText, nullptr, 0, &status);
} else {
utext_openCharacterIterator(&fText, newText, &status);
}
if (U_FAILURE(status)) {
return *this;
}
- if (input == NULL) {
+ if (input == nullptr) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return *this;
}
#endif
// if we're already at the start of the text, return DONE.
- if (fData == NULL || UTEXT_GETNATIVEINDEX(&fText)==0) {
+ if (fData == nullptr || UTEXT_GETNATIVEINDEX(&fText)==0) {
return BreakIterator::DONE;
}
//
//-------------------------------------------------------------------------------
const uint8_t *RuleBasedBreakIterator::getBinaryRules(uint32_t &length) {
- const uint8_t *retPtr = NULL;
+ const uint8_t *retPtr = nullptr;
length = 0;
- if (fData != NULL) {
+ if (fData != nullptr) {
retPtr = (const uint8_t *)fData->fHeader;
length = fData->fHeader->fLength;
}
RuleBasedBreakIterator *RuleBasedBreakIterator::createBufferClone(
void * /*stackBuffer*/, int32_t &bufferSize, UErrorCode &status) {
if (U_FAILURE(status)){
- return NULL;
+ return nullptr;
}
if (bufferSize == 0) {
bufferSize = 1; // preflighting for deprecated functionality
- return NULL;
+ return nullptr;
}
BreakIterator *clonedBI = clone();
- if (clonedBI == NULL) {
+ if (clonedBI == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
} else {
status = U_SAFECLONE_ALLOCATED_WARNING;
static void U_CALLCONV initLanguageFactories() {
UErrorCode status = U_ZERO_ERROR;
- U_ASSERT(gLanguageBreakFactories == NULL);
- gLanguageBreakFactories = new UStack(_deleteFactory, NULL, status);
- if (gLanguageBreakFactories != NULL && U_SUCCESS(status)) {
+ U_ASSERT(gLanguageBreakFactories == nullptr);
+ gLanguageBreakFactories = new UStack(_deleteFactory, nullptr, status);
+ if (gLanguageBreakFactories != nullptr && U_SUCCESS(status)) {
ICULanguageBreakFactory *builtIn = new ICULanguageBreakFactory(status);
gLanguageBreakFactories->push(builtIn, status);
#ifdef U_LOCAL_SERVICE_HOOK
LanguageBreakFactory *extra = (LanguageBreakFactory *)uprv_svc_hook("languageBreakFactory", &status);
- if (extra != NULL) {
+ if (extra != nullptr) {
gLanguageBreakFactories->push(extra, status);
}
#endif
getLanguageBreakEngineFromFactory(UChar32 c)
{
umtx_initOnce(gLanguageBreakFactoriesInitOnce, &initLanguageFactories);
- if (gLanguageBreakFactories == NULL) {
- return NULL;
+ if (gLanguageBreakFactories == nullptr) {
+ return nullptr;
}
int32_t i = gLanguageBreakFactories->size();
- const LanguageBreakEngine *lbe = NULL;
+ const LanguageBreakEngine *lbe = nullptr;
while (--i >= 0) {
LanguageBreakFactory *factory = (LanguageBreakFactory *)(gLanguageBreakFactories->elementAt(i));
lbe = factory->getEngineFor(c);
- if (lbe != NULL) {
+ if (lbe != nullptr) {
break;
}
}
//-------------------------------------------------------------------------------
const LanguageBreakEngine *
RuleBasedBreakIterator::getLanguageBreakEngine(UChar32 c) {
- const LanguageBreakEngine *lbe = NULL;
+ const LanguageBreakEngine *lbe = nullptr;
UErrorCode status = U_ZERO_ERROR;
- if (fLanguageBreakEngines == NULL) {
+ if (fLanguageBreakEngines == nullptr) {
fLanguageBreakEngines = new UStack(status);
- if (fLanguageBreakEngines == NULL || U_FAILURE(status)) {
+ if (fLanguageBreakEngines == nullptr || U_FAILURE(status)) {
delete fLanguageBreakEngines;
fLanguageBreakEngines = 0;
- return NULL;
+ return nullptr;
}
}
lbe = getLanguageBreakEngineFromFactory(c);
// If we got one, use it and push it on our stack.
- if (lbe != NULL) {
+ if (lbe != nullptr) {
fLanguageBreakEngines->push((void *)lbe, status);
// Even if we can't remember it, we can keep looking it up, so
// return it even if the push fails.
// No engine is forthcoming for this character. Add it to the
// reject set. Create the reject break engine if needed.
- if (fUnhandledBreakEngine == NULL) {
+ if (fUnhandledBreakEngine == nullptr) {
fUnhandledBreakEngine = new UnhandledEngine(status);
- if (U_SUCCESS(status) && fUnhandledBreakEngine == NULL) {
+ if (U_SUCCESS(status) && fUnhandledBreakEngine == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
}
if (U_FAILURE(status)) {
delete fUnhandledBreakEngine;
fUnhandledBreakEngine = 0;
- return NULL;
+ return nullptr;
}
}
const UnicodeString&
RuleBasedBreakIterator::getRules() const {
- if (fData != NULL) {
+ if (fData != nullptr) {
return fData->getRuleSourceString();
} else {
umtx_initOnce(gRBBIInitOnce, &rbbiInit);
// Ask the language object if there are any breaks. It will add them to the cache and
// leave the text pointer on the other side of its range, ready to search for the next one.
- if (lbe != NULL) {
+ if (lbe != nullptr) {
foundBreakCount += lbe->findBreaks(text, rangeStart, rangeEnd, fBreaks, fBI->fIsPhraseBreaking, status);
}
//
//-----------------------------------------------------------------------------
void RBBIDataWrapper::init0() {
- fHeader = NULL;
- fForwardTable = NULL;
- fReverseTable = NULL;
- fRuleSource = NULL;
- fRuleStatusTable = NULL;
- fTrie = NULL;
- fUDataMem = NULL;
+ fHeader = nullptr;
+ fForwardTable = nullptr;
+ fReverseTable = nullptr;
+ fRuleSource = nullptr;
+ fRuleStatusTable = nullptr;
+ fTrie = nullptr;
+ fUDataMem = nullptr;
fRefCount = 0;
fDontFreeData = true;
}
}
RBBIDebugPrintf("\n");
- if (table == NULL) {
+ if (table == nullptr) {
RBBIDebugPrintf(" N U L L T A B L E\n\n");
return;
}
ubrk_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData,
UErrorCode *status) {
- if (status == NULL || U_FAILURE(*status)) {
+ if (status == nullptr || U_FAILURE(*status)) {
return 0;
}
- if(ds==NULL || inData==NULL || length<-1 || (length>0 && outData==NULL)) {
+ if(ds==nullptr || inData==nullptr || length<-1 || (length>0 && outData==nullptr)) {
*status=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
fSerialNum = ++gLastSerial;
#endif
fType = t;
- fParent = NULL;
- fLeftChild = NULL;
- fRightChild = NULL;
- fInputSet = NULL;
+ fParent = nullptr;
+ fLeftChild = nullptr;
+ fRightChild = nullptr;
+ fInputSet = nullptr;
fFirstPos = 0;
fLastPos = 0;
fNullable = false;
fSerialNum = ++gLastSerial;
#endif
fType = other.fType;
- fParent = NULL;
- fLeftChild = NULL;
- fRightChild = NULL;
+ fParent = nullptr;
+ fLeftChild = nullptr;
+ fRightChild = nullptr;
fInputSet = other.fInputSet;
fPrecedence = other.fPrecedence;
fText = other.fText;
RBBINode::~RBBINode() {
// printf("deleting node %8x serial %4d\n", this, this->fSerialNum);
delete fInputSet;
- fInputSet = NULL;
+ fInputSet = nullptr;
switch (this->fType) {
case varRef:
default:
delete fLeftChild;
- fLeftChild = NULL;
+ fLeftChild = nullptr;
delete fRightChild;
- fRightChild = NULL;
+ fRightChild = nullptr;
}
} else {
n = new RBBINode(*this);
// Check for null pointer.
- if (n != NULL) {
- if (fLeftChild != NULL) {
+ if (n != nullptr) {
+ if (fLeftChild != nullptr) {
n->fLeftChild = fLeftChild->cloneTree();
n->fLeftChild->fParent = n;
}
- if (fRightChild != NULL) {
+ if (fRightChild != nullptr) {
n->fRightChild = fRightChild->cloneTree();
n->fRightChild->fParent = n;
}
RBBINode *RBBINode::flattenVariables() {
if (fType == varRef) {
RBBINode *retNode = fLeftChild->cloneTree();
- if (retNode != NULL) {
+ if (retNode != nullptr) {
retNode->fRuleRoot = this->fRuleRoot;
retNode->fChainIn = this->fChainIn;
}
return retNode;
}
- if (fLeftChild != NULL) {
+ if (fLeftChild != nullptr) {
fLeftChild = fLeftChild->flattenVariables();
fLeftChild->fParent = this;
}
- if (fRightChild != NULL) {
+ if (fRightChild != nullptr) {
fRightChild = fRightChild->flattenVariables();
fRightChild->fParent = this;
}
void RBBINode::flattenSets() {
U_ASSERT(fType != setRef);
- if (fLeftChild != NULL) {
+ if (fLeftChild != nullptr) {
if (fLeftChild->fType==setRef) {
RBBINode *setRefNode = fLeftChild;
RBBINode *usetNode = setRefNode->fLeftChild;
}
}
- if (fRightChild != NULL) {
+ if (fRightChild != nullptr) {
if (fRightChild->fType==setRef) {
RBBINode *setRefNode = fRightChild;
RBBINode *usetNode = setRefNode->fLeftChild;
if (fType == kind) {
dest->addElement(this, status);
}
- if (fLeftChild != NULL) {
+ if (fLeftChild != nullptr) {
fLeftChild->findNodes(dest, kind, status);
}
- if (fRightChild != NULL) {
+ if (fRightChild != nullptr) {
fRightChild->findNodes(dest, kind, status);
}
}
#ifdef RBBI_DEBUG
static int32_t serial(const RBBINode *node) {
- return (node == NULL? -1 : node->fSerialNum);
+ return (node == nullptr? -1 : node->fSerialNum);
}
"opLParen"
};
- if (node==NULL) {
+ if (node==nullptr) {
RBBIDebugPrintf("%10p", (void *)node);
} else {
RBBIDebugPrintf("%10p %5d %12s %c%c %5d %5d %5d %6d %d ",
printNodeHeader();
}
printNode(node);
- if (node != NULL) {
+ if (node != nullptr) {
// Only dump the definition under a variable reference if asked to.
// Unconditionally dump children of all other node types.
if (node->fType != varRef) {
- if (node->fLeftChild != NULL) {
+ if (node->fLeftChild != nullptr) {
printTree(node->fLeftChild, false);
}
- if (node->fRightChild != NULL) {
+ if (node->fRightChild != nullptr) {
printTree(node->fRightChild, false);
}
}
{
fStatus = &status; // status is checked below
fParseError = parseErr;
- fDebugEnv = NULL;
+ fDebugEnv = nullptr;
#ifdef RBBI_DEBUG
fDebugEnv = getenv("U_RBBIDEBUG");
#endif
- fForwardTree = NULL;
- fReverseTree = NULL;
- fSafeFwdTree = NULL;
- fSafeRevTree = NULL;
+ fForwardTree = nullptr;
+ fReverseTree = nullptr;
+ fSafeFwdTree = nullptr;
+ fSafeRevTree = nullptr;
fDefaultTree = &fForwardTree;
- fForwardTable = NULL;
- fRuleStatusVals = NULL;
+ fForwardTable = nullptr;
+ fRuleStatusVals = nullptr;
fChainRules = false;
fLBCMNoChain = false;
fLookAheadHardBreak = false;
- fUSetNodes = NULL;
- fRuleStatusVals = NULL;
- fScanner = NULL;
- fSetBuilder = NULL;
+ fUSetNodes = nullptr;
+ fRuleStatusVals = nullptr;
+ fScanner = nullptr;
+ fSetBuilder = nullptr;
if (parseErr) {
uprv_memset(parseErr, 0, sizeof(UParseError));
}
int i;
for (i=0; ; i++) {
RBBINode *n = (RBBINode *)fUSetNodes->elementAt(i);
- if (n==NULL) {
+ if (n==nullptr) {
break;
}
delete n;
int32_t i;
if (U_FAILURE(*fStatus)) {
- return NULL;
+ return nullptr;
}
// Remove whitespace from the rules to make it smaller.
#endif
RBBIDataHeader *data = (RBBIDataHeader *)uprv_malloc(totalSize);
- if (data == NULL) {
+ if (data == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
}
uprv_memset(data, 0, totalSize);
fStrippedRules.getBuffer(), fStrippedRules.length(),
0xfffd, nullptr, fStatus);
if (U_FAILURE(*fStatus)) {
- return NULL;
+ return nullptr;
}
return data;
//
RBBIRuleBuilder builder(rules, parseError, status);
if (U_FAILURE(status)) { // status checked here bcos build below doesn't
- return NULL;
+ return nullptr;
}
RBBIDataHeader *data = builder.build(status);
RuleBasedBreakIterator *This = new RuleBasedBreakIterator(data, status);
if (U_FAILURE(status)) {
delete This;
- This = NULL;
+ This = nullptr;
}
- else if(This == NULL) { // test for NULL
+ else if(This == nullptr) { // test for nullptr
status = U_MEMORY_ALLOCATION_ERROR;
}
return This;
// Package up the compiled data into a memory image
// in the run-time format.
//
- RBBIDataHeader *data = flattenData(); // returns NULL if error
+ RBBIDataHeader *data = flattenData(); // returns nullptr if error
if (U_FAILURE(status)) {
return nullptr;
}
fCharNum = 0;
fLastChar = 0;
- fStateTable = NULL;
+ fStateTable = nullptr;
fStack[0] = 0;
fStackPtr = 0;
- fNodeStack[0] = NULL;
+ fNodeStack[0] = nullptr;
fNodeStackPtr = 0;
fReverseRule = false;
fLookAheadRule = false;
fNoChainInRule = false;
- fSymbolTable = NULL;
- fSetTable = NULL;
+ fSymbolTable = nullptr;
+ fSetTable = nullptr;
fRuleNum = 0;
fOptionStart = 0;
}
fSymbolTable = new RBBISymbolTable(this, rb->fRules, *rb->fStatus);
- if (fSymbolTable == NULL) {
+ if (fSymbolTable == nullptr) {
*rb->fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
- fSetTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, rb->fStatus);
+ fSetTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, nullptr, rb->fStatus);
if (U_FAILURE(*rb->fStatus)) {
return;
}
//------------------------------------------------------------------------------
RBBIRuleScanner::~RBBIRuleScanner() {
delete fSymbolTable;
- if (fSetTable != NULL) {
+ if (fSetTable != nullptr) {
uhash_close(fSetTable);
- fSetTable = NULL;
+ fSetTable = nullptr;
}
//------------------------------------------------------------------------------
UBool RBBIRuleScanner::doParseActions(int32_t action)
{
- RBBINode *n = NULL;
+ RBBINode *n = nullptr;
UBool returnVal = true;
//
RBBINode **destRules = (fReverseRule? &fRB->fSafeRevTree : fRB->fDefaultTree);
- if (*destRules != NULL) {
+ if (*destRules != nullptr) {
// This is not the first rule encountered.
// OR previous stuff (from *destRules)
// with the current rule expression (on the Node Stack)
case doEndVariableName:
n = fNodeStack[fNodeStackPtr];
- if (n==NULL || n->fType != RBBINode::varRef) {
+ if (n==nullptr || n->fType != RBBINode::varRef) {
error(U_BRK_INTERNAL_ERROR);
break;
}
case doCheckVarDef:
n = fNodeStack[fNodeStackPtr];
- if (n->fLeftChild == NULL) {
+ if (n->fLeftChild == nullptr) {
error(U_BRK_UNDEFINED_VARIABLE);
returnVal = false;
}
// If so, just use the cached set in the new node.
// delete any set provided by the caller, since we own it.
el = (RBBISetTableEl *)uhash_get(fSetTable, &s);
- if (el != NULL) {
+ if (el != nullptr) {
delete setToAdopt;
node->fLeftChild = el->val;
U_ASSERT(node->fLeftChild->fType == RBBINode::uset);
// Haven't seen this set before.
// If the caller didn't provide us with a prebuilt set,
// create a new UnicodeSet now.
- if (setToAdopt == NULL) {
+ if (setToAdopt == nullptr) {
if (s.compare(kAny, -1) == 0) {
setToAdopt = new UnicodeSet(0x000000, 0x10ffff);
} else {
// This new uset node becomes the child of the caller's setReference node.
//
RBBINode *usetNode = new RBBINode(RBBINode::uset);
- if (usetNode == NULL) {
+ if (usetNode == nullptr) {
error(U_MEMORY_ALLOCATION_ERROR);
return;
}
//
el = (RBBISetTableEl *)uprv_malloc(sizeof(RBBISetTableEl));
UnicodeString *tkey = new UnicodeString(s);
- if (tkey == NULL || el == NULL || setToAdopt == NULL) {
+ if (tkey == nullptr || el == nullptr || setToAdopt == nullptr) {
// Delete to avoid memory leak
delete tkey;
- tkey = NULL;
+ tkey = nullptr;
uprv_free(el);
- el = NULL;
+ el = nullptr;
delete setToAdopt;
- setToAdopt = NULL;
+ setToAdopt = nullptr;
error(U_MEMORY_ALLOCATION_ERROR);
return;
// If there are no forward rules set an error.
//
- if (fRB->fForwardTree == NULL) {
+ if (fRB->fForwardTree == nullptr) {
error(U_BRK_RULE_SYNTAX);
return;
}
//------------------------------------------------------------------------------
RBBINode *RBBIRuleScanner::pushNewNode(RBBINode::NodeType t) {
if (U_FAILURE(*fRB->fStatus)) {
- return NULL;
+ return nullptr;
}
if (fNodeStackPtr >= kStackSize - 1) {
error(U_BRK_RULE_SYNTAX);
RBBIDebugPuts("RBBIRuleScanner::pushNewNode - stack overflow.");
- return NULL;
+ return nullptr;
}
fNodeStackPtr++;
fNodeStack[fNodeStackPtr] = new RBBINode(t);
- if (fNodeStack[fNodeStackPtr] == NULL) {
+ if (fNodeStack[fNodeStackPtr] == nullptr) {
*fRB->fStatus = U_MEMORY_ALLOCATION_ERROR;
}
return fNodeStack[fNodeStackPtr];
startPos = fScanIndex;
UErrorCode localStatus = U_ZERO_ERROR;
uset = new UnicodeSet();
- if (uset == NULL) {
+ if (uset == nullptr) {
localStatus = U_MEMORY_ALLOCATION_ERROR;
} else {
uset->applyPatternIgnoreSpace(fRB->fRules, pos, fSymbolTable, localStatus);
// Verify that the set contains at least one code point.
//
- U_ASSERT(uset!=NULL);
+ U_ASSERT(uset!=nullptr);
if (uset->isEmpty()) {
// This set is empty.
// Make it an error, because it almost certainly is not what the user wanted.
void error(UErrorCode e); // error reporting convenience function.
void fixOpStack(RBBINode::OpPrecedence p);
// a character.
- void findSetFor(const UnicodeString &s, RBBINode *node, UnicodeSet *setToAdopt = NULL);
+ void findSetFor(const UnicodeString &s, RBBINode *node, UnicodeSet *setToAdopt = nullptr);
UChar32 nextCharLL();
#ifdef RBBI_DEBUG
RangeDescriptor *nextRangeDesc;
// Walk through & delete the linked list of RangeDescriptors
- for (nextRangeDesc = fRangeList; nextRangeDesc!=NULL;) {
+ for (nextRangeDesc = fRangeList; nextRangeDesc!=nullptr;) {
RangeDescriptor *r = nextRangeDesc;
nextRangeDesc = r->fNext;
delete r;
// that is in no sets.
//
fRangeList = new RangeDescriptor(*fStatus); // will check for status here
- if (fRangeList == NULL) {
+ if (fRangeList == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
int ni;
for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
- if (usetNode==NULL) {
+ if (usetNode==nullptr) {
break;
}
UnicodeString bofString(u"bof");
for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
- if (usetNode==NULL) {
+ if (usetNode==nullptr) {
break;
}
UnicodeSet *inputSet = usetNode->fInputSet;
void RBBISetBuilder::addValToSet(RBBINode *usetNode, uint32_t val) {
RBBINode *leafNode = new RBBINode(RBBINode::leafChar);
- if (leafNode == NULL) {
+ if (leafNode == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
leafNode->fVal = (unsigned short)val;
- if (usetNode->fLeftChild == NULL) {
+ if (usetNode->fLeftChild == nullptr) {
usetNode->fLeftChild = leafNode;
leafNode->fParent = usetNode;
} else {
// Set up an OR node, with the previous stuff as the left child
// and the new value as the right child.
RBBINode *orNode = new RBBINode(RBBINode::opOr);
- if (orNode == NULL) {
+ if (orNode == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i);
UnicodeString setName = UNICODE_STRING("anon", 4);
RBBINode *setRef = usetNode->fParent;
- if (setRef != NULL) {
+ if (setRef != nullptr) {
RBBINode *varRef = setRef->fParent;
- if (varRef != NULL && varRef->fType == RBBINode::varRef) {
+ if (varRef != nullptr && varRef->fType == RBBINode::varRef) {
setName = varRef->fText;
}
}
UnicodeString setName;
usetNode = (RBBINode *)fRB->fUSetNodes->elementAt(i);
- if (usetNode == NULL) {
+ if (usetNode == nullptr) {
break;
}
RBBIDebugPrintf("%3d ", i);
setName = UNICODE_STRING("anonymous", 9);
setRef = usetNode->fParent;
- if (setRef != NULL) {
+ if (setRef != nullptr) {
varRef = setRef->fParent;
- if (varRef != NULL && varRef->fType == RBBINode::varRef) {
+ if (varRef != nullptr && varRef->fType == RBBINode::varRef) {
setName = varRef->fText;
}
}
RBBIDebugPrintf(" ");
RBBI_DEBUG_printUnicodeString(usetNode->fText);
RBBIDebugPrintf("\n");
- if (usetNode->fLeftChild != NULL) {
+ if (usetNode->fLeftChild != nullptr) {
RBBINode::printTree(usetNode->fLeftChild, true);
}
}
RBBISymbolTable::RBBISymbolTable(RBBIRuleScanner *rs, const UnicodeString &rules, UErrorCode &status)
:fRules(rules), fRuleScanner(rs), ffffString(UChar(0xffff))
{
- fHashTable = NULL;
- fCachedSetLookup = NULL;
+ fHashTable = nullptr;
+ fCachedSetLookup = nullptr;
- fHashTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, &status);
+ fHashTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, nullptr, &status);
// uhash_open checks status
if (U_FAILURE(status)) {
return;
RBBISymbolTable *This = (RBBISymbolTable *)this; // cast off const
el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &s);
- if (el == NULL) {
- return NULL;
+ if (el == nullptr) {
+ return nullptr;
}
varRefNode = el->val;
// The variable refers to something other than just a set.
// return the original source string for the expression
retString = &exprNode->fText;
- This->fCachedSetLookup = NULL;
+ This->fCachedSetLookup = nullptr;
}
return retString;
}
// and we just need to remember what set to return between these two calls.
const UnicodeFunctor *RBBISymbolTable::lookupMatcher(UChar32 ch) const
{
- UnicodeSet *retVal = NULL;
+ UnicodeSet *retVal = nullptr;
RBBISymbolTable *This = (RBBISymbolTable *)this; // cast off const
if (ch == 0xffff) {
retVal = fCachedSetLookup;
//
// RBBISymbolTable::lookupNode Given a key (a variable name), return the
// corresponding RBBI Node. If there is no entry
-// in the table for this name, return NULL.
+// in the table for this name, return nullptr.
//
RBBINode *RBBISymbolTable::lookupNode(const UnicodeString &key) const{
- RBBINode *retNode = NULL;
+ RBBINode *retNode = nullptr;
RBBISymbolTableEntry *el;
el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key);
- if (el != NULL) {
+ if (el != nullptr) {
retNode = el->val;
}
return retNode;
return;
}
e = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key);
- if (e != NULL) {
+ if (e != nullptr) {
err = U_BRK_VARIABLE_REDFINITION;
return;
}
e = new RBBISymbolTableEntry;
- if (e == NULL) {
+ if (e == nullptr) {
err = U_MEMORY_ALLOCATION_ERROR;
return;
}
}
-RBBISymbolTableEntry::RBBISymbolTableEntry() : UMemory(), key(), val(NULL) {}
+RBBISymbolTableEntry::RBBISymbolTableEntry() : UMemory(), key(), val(nullptr) {}
RBBISymbolTableEntry::~RBBISymbolTableEntry() {
// The "val" of a symbol table entry is a variable reference node.
// Unlike other node types, children of variable reference nodes are not
// automatically recursively deleted. We do it manually here.
delete val->fLeftChild;
- val->fLeftChild = NULL;
+ val->fLeftChild = nullptr;
delete val;
"-------------------------------------------------------------------\n");
int32_t pos = UHASH_FIRST;
- const UHashElement *e = NULL;
+ const UHashElement *e = nullptr;
for (;;) {
e = uhash_nextElement(fHashTable, &pos);
- if (e == NULL ) {
+ if (e == nullptr ) {
break;
}
RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer;
pos = -1;
for (;;) {
e = uhash_nextElement(fHashTable, &pos);
- if (e == NULL ) {
+ if (e == nullptr ) {
break;
}
RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer;
// If there were no rules, just return. This situation can easily arise
// for the reverse rules.
- if (fTree==NULL) {
+ if (fTree==nullptr) {
return;
}
RBBINode *bofTop = new RBBINode(RBBINode::opCat);
RBBINode *bofLeaf = new RBBINode(RBBINode::leafChar);
// Delete and exit if memory allocation failed.
- if (bofTop == NULL || bofLeaf == NULL) {
+ if (bofTop == nullptr || bofLeaf == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
delete bofTop;
delete bofLeaf;
//
RBBINode *cn = new RBBINode(RBBINode::opCat);
// Exit if memory allocation failed.
- if (cn == NULL) {
+ if (cn == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
fTree->fParent = cn;
RBBINode *endMarkerNode = cn->fRightChild = new RBBINode(RBBINode::endMark);
// Delete and exit if memory allocation failed.
- if (cn->fRightChild == NULL) {
+ if (cn->fRightChild == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
delete cn;
return;
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::calcNullable(RBBINode *n) {
- if (n == NULL) {
+ if (n == nullptr) {
return;
}
if (n->fType == RBBINode::setRef ||
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::calcFirstPos(RBBINode *n) {
- if (n == NULL) {
+ if (n == nullptr) {
return;
}
if (n->fType == RBBINode::leafChar ||
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::calcLastPos(RBBINode *n) {
- if (n == NULL) {
+ if (n == nullptr) {
return;
}
if (n->fType == RBBINode::leafChar ||
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::calcFollowPos(RBBINode *n) {
- if (n == NULL ||
+ if (n == nullptr ||
n->fType == RBBINode::leafChar ||
n->fType == RBBINode::endMark) {
return;
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::addRuleRootNodes(UVector *dest, RBBINode *node) {
- if (node == NULL || U_FAILURE(*fStatus)) {
+ if (node == nullptr || U_FAILURE(*fStatus)) {
return;
}
U_ASSERT(!dest->hasDeleter());
return;
}
RBBIStateDescriptor *failState;
- // Set it to NULL to avoid uninitialized warning
- RBBIStateDescriptor *initialState = NULL;
+ // Set it to nullptr to avoid uninitialized warning
+ RBBIStateDescriptor *initialState = nullptr;
//
// Add a dummy state 0 - the stop state. Not from Aho.
int lastInputSymbol = fRB->fSetBuilder->getNumCharCategories() - 1;
failState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
- if (failState == NULL) {
+ if (failState == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
goto ExitBuildSTdeleteall;
}
failState->fPositions = new UVector(*fStatus);
- if (failState->fPositions == NULL) {
+ if (failState->fPositions == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
}
- if (failState->fPositions == NULL || U_FAILURE(*fStatus)) {
+ if (failState->fPositions == nullptr || U_FAILURE(*fStatus)) {
goto ExitBuildSTdeleteall;
}
fDStates->addElement(failState, *fStatus);
// 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) {
+ if (initialState == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(*fStatus)) {
goto ExitBuildSTdeleteall;
}
initialState->fPositions = new UVector(*fStatus);
- if (initialState->fPositions == NULL) {
+ if (initialState->fPositions == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(*fStatus)) {
// while there is an unmarked state T in Dstates do begin
for (;;) {
- RBBIStateDescriptor *T = NULL;
+ RBBIStateDescriptor *T = nullptr;
int32_t tx;
for (tx=1; tx<fDStates->size(); tx++) {
RBBIStateDescriptor *temp;
break;
}
}
- if (T == NULL) {
+ if (T == nullptr) {
break;
}
// let U be the set of positions that are in followpos(p)
// for some position p in T
// such that the symbol at position p is a;
- UVector *U = NULL;
+ UVector *U = nullptr;
RBBINode *p;
int32_t px;
for (px=0; px<T->fPositions->size(); px++) {
p = (RBBINode *)T->fPositions->elementAt(px);
if ((p->fType == RBBINode::leafChar) && (p->fVal == a)) {
- if (U == NULL) {
+ if (U == nullptr) {
U = new UVector(*fStatus);
- if (U == NULL) {
+ if (U == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
goto ExitBuildSTdeleteall;
}
// if U is not empty and not in DStates then
int32_t ux = 0;
UBool UinDstates = false;
- if (U != NULL) {
+ if (U != nullptr) {
U_ASSERT(U->size() > 0);
int ix;
for (ix=0; ix<fDStates->size(); ix++) {
if (!UinDstates)
{
RBBIStateDescriptor *newState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
- if (newState == NULL) {
+ if (newState == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(*fStatus)) {
for (n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
UVector *thisStatesTagValues = sd->fTagVals;
- if (thisStatesTagValues == NULL) {
+ if (thisStatesTagValues == nullptr) {
// No tag values are explicitly associated with this state.
// Set the default tag value.
sd->fTagsIdx = 0;
void RBBITableBuilder::sortedAdd(UVector **vector, int32_t val) {
int32_t i;
- if (*vector == NULL) {
+ if (*vector == nullptr) {
*vector = new UVector(*fStatus);
}
- if (*vector == NULL || U_FAILURE(*fStatus)) {
+ if (*vector == nullptr || U_FAILURE(*fStatus)) {
return;
}
UVector *vec = *vector;
void **destLim, **sourceLim;
if (destOriginalSize > destArray.getCapacity()) {
- if (destArray.resize(destOriginalSize) == NULL) {
+ if (destArray.resize(destOriginalSize) == nullptr) {
return;
}
}
destLim = destPtr + destOriginalSize; // destArray.getArrayLimit()?
if (sourceSize > sourceArray.getCapacity()) {
- if (sourceArray.resize(sourceSize) == NULL) {
+ if (sourceArray.resize(sourceSize) == nullptr) {
return;
}
}
//-----------------------------------------------------------------------------
#ifdef RBBI_DEBUG
void RBBITableBuilder::printPosSets(RBBINode *n) {
- if (n==NULL) {
+ if (n==nullptr) {
return;
}
printf("\n");
int32_t numCols;
int32_t rowSize;
- if (fTree == NULL) {
+ if (fTree == nullptr) {
return 0;
}
uint32_t state;
int col;
- if (U_FAILURE(*fStatus) || fTree == NULL) {
+ if (U_FAILURE(*fStatus) || fTree == nullptr) {
return;
}
int32_t i;
for (i=0; i<s->size(); i++) {
const RBBINode *v = static_cast<const RBBINode *>(s->elementAt(i));
- RBBIDebugPrintf("%5d", v==NULL? -1 : v->fSerialNum);
+ RBBIDebugPrintf("%5d", v==nullptr? -1 : v->fSerialNum);
}
RBBIDebugPrintf("\n");
}
fAccepting = 0;
fLookAhead = 0;
fTagsIdx = 0;
- fTagVals = NULL;
- fPositions = NULL;
- fDtran = NULL;
+ fTagVals = nullptr;
+ fPositions = nullptr;
+ fDtran = nullptr;
fDtran = new UVector32(lastInputSymbol+1, *fStatus);
if (U_FAILURE(*fStatus)) {
return;
}
- if (fDtran == NULL) {
+ if (fDtran == nullptr) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
delete fPositions;
delete fDtran;
delete fTagVals;
- fPositions = NULL;
- fDtran = NULL;
- fTagVals = NULL;
+ fPositions = nullptr;
+ fDtran = nullptr;
+ fTagVals = nullptr;
}
U_NAMESPACE_END
public:
#ifdef RBBI_DEBUG
void printSet(UVector *s);
- void printPosSets(RBBINode *n /* = NULL*/);
+ void printPosSets(RBBINode *n /* = nullptr */);
void printStates();
void printRuleStatusTable();
void printReverseTable();
UBreakIterator *uBI = (UBreakIterator *)result;
- if (text != NULL) {
+ if (text != nullptr) {
ubrk_setText(uBI, text, textLength, status);
}
return uBI;
UParseError *parseErr,
UErrorCode *status) {
- if (status == NULL || U_FAILURE(*status)){
+ if (status == nullptr || U_FAILURE(*status)){
return 0;
}
}
UBreakIterator *uBI = (UBreakIterator *)result;
- if (text != NULL) {
+ if (text != nullptr) {
ubrk_setText(uBI, text, textLength, status);
}
return uBI;
UErrorCode * status)
{
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
if (rulesLength < 0) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
LocalPointer<RuleBasedBreakIterator> lpRBBI(new RuleBasedBreakIterator(binaryRules, rulesLength, *status), *status);
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
UBreakIterator *uBI = reinterpret_cast<UBreakIterator *>(lpRBBI.orphan());
- if (text != NULL) {
+ if (text != nullptr) {
ubrk_setText(uBI, text, textLength, status);
}
return uBI;
int32_t *pBufferSize,
UErrorCode *status)
{
- if (status == NULL || U_FAILURE(*status)){
- return NULL;
+ if (status == nullptr || U_FAILURE(*status)){
+ return nullptr;
}
- if (bi == NULL) {
+ if (bi == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
- if (pBufferSize != NULL) {
+ if (pBufferSize != nullptr) {
int32_t inputSize = *pBufferSize;
*pBufferSize = 1;
if (inputSize == 0) {
- return NULL; // preflighting for deprecated functionality
+ return nullptr; // preflighting for deprecated functionality
}
}
BreakIterator *newBI = ((BreakIterator *)bi)->clone();
- if (newBI == NULL) {
+ if (newBI == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
- } else if (pBufferSize != NULL) {
+ } else if (pBufferSize != nullptr) {
*status = U_SAFECLONE_ALLOCATED_WARNING;
}
return (UBreakIterator *)newBI;
ULocDataLocaleType type,
UErrorCode* status)
{
- if (bi == NULL) {
+ if (bi == nullptr) {
if (U_SUCCESS(*status)) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
}
- return NULL;
+ return nullptr;
}
return ((BreakIterator*)bi)->getLocaleID(type, *status);
}
if (U_FAILURE(*status)) {
return 0;
}
- if ((binaryRules == NULL && rulesCapacity > 0) || rulesCapacity < 0) {
+ if ((binaryRules == nullptr && rulesCapacity > 0) || rulesCapacity < 0) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
RuleBasedBreakIterator* rbbi;
- if ((rbbi = dynamic_cast<RuleBasedBreakIterator*>(reinterpret_cast<BreakIterator*>(bi))) == NULL) {
+ if ((rbbi = dynamic_cast<RuleBasedBreakIterator*>(reinterpret_cast<BreakIterator*>(bi))) == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
*status = U_INDEX_OUTOFBOUNDS_ERROR;
return 0;
}
- if (binaryRules != NULL) { // if not preflighting
+ if (binaryRules != nullptr) { // if not preflighting
// Here we know rulesLength <= INT32_MAX and rulesCapacity >= 0, can cast safely
if ((int32_t)rulesLength > rulesCapacity) {
*status = U_BUFFER_OVERFLOW_ERROR;
// 012345678901
status.reset();
- LocalUTextPointer ut(utext_openUTF8(NULL, s1, -1, status));
+ LocalUTextPointer ut(utext_openUTF8(nullptr, s1, -1, status));
wordIter1->setText(ut.getAlias(), status);
TEST_ASSERT_SUCCESS(status);
TEST_ASSERT(pos==UBRK_DONE);
status.reset();
- LocalUTextPointer ut2(utext_openUTF8(NULL, s2, -1, status));
+ LocalUTextPointer ut2(utext_openUTF8(nullptr, s2, -1, status));
TEST_ASSERT_SUCCESS(status);
wordIter1->setText(ut2.getAlias(), status);
TEST_ASSERT_SUCCESS(status);
status.reset();
UnicodeString sEmpty;
- LocalUTextPointer gut2(utext_openUnicodeString(NULL, &sEmpty, status));
+ LocalUTextPointer gut2(utext_openUnicodeString(nullptr, &sEmpty, status));
wordIter1->getUText(gut2.getAlias(), status);
TEST_ASSERT_SUCCESS(status);
status.reset();
UErrorCode status=U_ZERO_ERROR;
RuleBasedBreakIterator* bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
- if (U_FAILURE(status) || bi == NULL) {
+ if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating character break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status);
- if (U_FAILURE(status) || bi == NULL) {
+ if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating Word break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createLineInstance(Locale::getDefault(), status);
- if (U_FAILURE(status) || bi == NULL) {
+ if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating Line break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createSentenceInstance(Locale::getDefault(), status);
- if (U_FAILURE(status) || bi == NULL) {
+ if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating Sentence break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createTitleInstance(Locale::getDefault(), status);
- if (U_FAILURE(status) || bi == NULL) {
+ if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating Title break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
- if (U_FAILURE(status) || bi == NULL) {
+ if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating character break iterator. Status = %s", u_errorName(status));
return; // Skip the rest of these tests.
}
return;
}
RuleBasedBreakIterator *rbbi = dynamic_cast<RuleBasedBreakIterator *>(bi.getAlias());
- if (rbbi == NULL) {
- dataerrln("FAIL: RuleBasedBreakIterator is NULL");
+ if (rbbi == nullptr) {
+ dataerrln("FAIL: RuleBasedBreakIterator is nullptr");
return;
}
uint32_t ruleLength;
const uint8_t *binRules = rbbi->getBinaryRules(ruleLength);
TEST_ASSERT(ruleLength > 0);
- TEST_ASSERT(binRules != NULL);
+ TEST_ASSERT(binRules != nullptr);
// Clone the binary rules, and create a break iterator from that.
// The break iterator does not adopt the rules; we must delete when we are finished with the iterator.
//--------------------------------------------------------------------------------------
RBBITest::RBBITest() {
- fTestParams = NULL;
+ fTestParams = nullptr;
}
static void printStringBreaks(const UnicodeString &ustr, int expected[], int expectedCount) {
UErrorCode status = U_ZERO_ERROR;
- UText *tstr = NULL;
- tstr = utext_openConstUnicodeString(NULL, &ustr, &status);
+ UText *tstr = nullptr;
+ tstr = utext_openConstUnicodeString(nullptr, &ustr, &status);
if (U_FAILURE(status)) {
printf("printStringBreaks, utext_openConstUnicodeString() returns %s\n", u_errorName(status));
return;
UnicodeString thaiStr(thaiWordData);
BreakIterator* bi = BreakIterator::createWordInstance(Locale("th"), status);
- if (U_FAILURE(status) || bi == NULL) {
+ if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Fail at file %s, line %d, status = %s", __FILE__, __LINE__, u_errorName(status));
return;
}
return;
}
// Check for status first for better handling of no data errors.
- TEST_ASSERT(bi != NULL);
- if (bi == NULL) {
+ TEST_ASSERT(bi != nullptr);
+ if (bi == nullptr) {
return;
}
CharString utf8String; // UTF-8 form of text to break.
TestParams(UErrorCode &status) : dataToBreak() {
- bi = NULL;
+ bi = nullptr;
expectedBreaks = new UVector32(status);
srcLine = new UVector32(status);
srcCol = new UVector32(status);
- textToBreak = NULL;
+ textToBreak = nullptr;
textMap = new UVector32(status);
}
return;
}
int32_t utf8Length;
- u_strToUTF8WithSub(NULL, 0, &utf8Length, // Output Buffer, NULL for preflight.
+ u_strToUTF8WithSub(nullptr, 0, &utf8Length, // Output Buffer, nullptr for preflight.
src.getBuffer(), src.length(), // UTF-16 data
- 0xfffd, NULL, // Substitution char, number of subs.
+ 0xfffd, nullptr, // Substitution char, number of subs.
&status);
if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) {
return;
status = U_ZERO_ERROR;
int32_t capacity;
char *buffer = dest.getAppendBuffer(utf8Length, utf8Length, capacity, status);
- u_strToUTF8WithSub(buffer, utf8Length, NULL,
+ u_strToUTF8WithSub(buffer, utf8Length, nullptr,
src.getBuffer(), src.length(),
- 0xfffd, NULL, &status);
+ 0xfffd, nullptr, &status);
dest.append(buffer, utf8Length, status);
}
return;
}
- if (t->bi == NULL) {
+ if (t->bi == nullptr) {
return;
}
//
const char *testDataDirectory = IntlTest::getSourceTestData(status);
char testFileName[1000];
- if (testDataDirectory == NULL || strlen(testDataDirectory) >= sizeof(testFileName)) {
+ if (testDataDirectory == nullptr || strlen(testDataDirectory) >= sizeof(testFileName)) {
dataerrln("Can't open test data. Path too long.");
return;
}
UChar *testFile = ReadAndConvertFile(testFileName, len, "UTF-8", status);
if (status != U_FILE_ACCESS_ERROR) {
TEST_ASSERT_SUCCESS(status);
- TEST_ASSERT(testFile != NULL);
+ TEST_ASSERT(testFile != nullptr);
}
- if (U_FAILURE(status) || testFile == NULL) {
+ if (U_FAILURE(status) || testFile == nullptr) {
return; /* something went wrong, error already output */
}
UnicodeString testFileAsString(true, testFile, len);
if (length<=8) {
char buf[10];
hexNumber.extract (0, length, buf, sizeof(buf), US_INV);
- UChar32 c = (UChar32)strtol(buf, NULL, 16);
+ UChar32 c = (UChar32)strtol(buf, nullptr, 16);
if (c<=0x10ffff) {
testString.append(c);
} else {
RBBICharMonkey::RBBICharMonkey() {
UErrorCode status = U_ZERO_ERROR;
- fText = NULL;
+ fText = nullptr;
fCRLFSet = new UnicodeSet(UNICODE_STRING_SIMPLE("[\\r\\n]"), status);
fControlSet = new UnicodeSet(UNICODE_STRING_SIMPLE("[[\\p{Grapheme_Cluster_Break = Control}]]"), status);
RBBILineMonkey::RBBILineMonkey() :
RBBIMonkeyKind(),
- fSets(NULL),
+ fSets(nullptr),
- fCharBI(NULL),
- fText(NULL),
- fNumberMatcher(NULL)
+ fCharBI(nullptr),
+ fText(nullptr),
+ fNumberMatcher(nullptr)
{
if (U_FAILURE(deferredStatus)) {
paramLength = (int32_t)(sizeof(valString)-2);
}
params.extract(m.start(1, status), paramLength, valString, sizeof(valString));
- val = strtol(valString, NULL, 10);
+ val = strtol(valString, nullptr, 10);
// Delete this parameter from the params string.
m.reset();
// Each option is stripped out of the option string as it is processed.
// All options have been checked. The option string should have been completely emptied..
char buf[100];
- p.extract(buf, sizeof(buf), NULL, status);
+ p.extract(buf, sizeof(buf), nullptr, status);
buf[sizeof(buf)-1] = 0;
errln("Unrecognized or extra parameter: %s\n", buf);
return;
// Verify that the character classes all have at least one member.
for (i=0; i<numCharClasses; i++) {
UnicodeSet *s = (UnicodeSet *)chClasses->elementAt(i);
- if (s == NULL || s->size() == 0) {
+ if (s == nullptr || s->size() == 0) {
errln("Character Class #%d is null or of zero size.", i);
return;
}
memset(forwardBreaks, 0, sizeof(forwardBreaks));
if (useUText) {
UErrorCode status = U_ZERO_ERROR;
- UText *testUText = utext_openReplaceable(NULL, &testText, &status);
+ UText *testUText = utext_openReplaceable(nullptr, &testText, &status);
// testUText = utext_openUnicodeString(testUText, &testText, &status);
bi->setText(testUText, status);
TEST_ASSERT_SUCCESS(status);
// Compare the expected and actual results.
for (i=0; i<=testText.length(); i++) {
- const char *errorType = NULL;
- const char* currentBreakData = NULL;
+ const char *errorType = nullptr;
+ const char* currentBreakData = nullptr;
if (forwardBreaks[i] != expectedBreaks[i]) {
errorType = "next()";
currentBreakData = forwardBreaks;
currentBreakData = precedingBreaks;
}
- if (errorType != NULL) {
+ if (errorType != nullptr) {
// Format a range of the test text that includes the failure as
// a data item that can be included in the rbbi test data file.
// This test triggers an assertion failure in dictbe.cpp
const UChar *crasherString = u"\u3325\u4a16";
UErrorCode status = U_ZERO_ERROR;
- UBreakIterator* iter = ubrk_open(UBRK_WORD, NULL, crasherString, -1, &status);
+ UBreakIterator* iter = ubrk_open(UBRK_WORD, nullptr, crasherString, -1, &status);
if (U_FAILURE(status)) {
dataerrln("%s:%d status = %s", __FILE__, __LINE__, u_errorName(status));
return;
int len;
UChar *testFile = ReadAndConvertFile(testFileName.data(), len, "UTF-8", status);
- if (U_FAILURE(status) || testFile == NULL) {
+ if (U_FAILURE(status) || testFile == nullptr) {
errln("%s:%s %s while opening emoji-test.txt", __FILE__, __LINE__, u_errorName(status));
return;
}
}
CharString hex8;
hex8.appendInvariantChars(hex, status);
- UChar32 c = (UChar32)strtol(hex8.data(), NULL, 16);
+ UChar32 c = (UChar32)strtol(hex8.data(), nullptr, 16);
if (c<=0x10ffff) {
testString.append(c);
} else {