+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
-* Copyright (C) 1997-2005, International Business Machines
+* Copyright (C) 1997-2012, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* file name: nfrlist.h
-* encoding: US-ASCII
+* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
NFRuleList(uint32_t capacity = 10)
: fStuff(capacity ? (NFRule**)uprv_malloc(capacity * sizeof(NFRule*)) : NULL)
, fCount(0)
- , fCapacity(capacity) {};
+ , fCapacity(capacity) {}
~NFRuleList() {
if (fStuff) {
for(uint32_t i = 0; i < fCount; ++i) {
uprv_free(fStuff);
}
}
- NFRule* operator[](uint32_t index) const { return fStuff[index]; }
+ NFRule* operator[](uint32_t index) const { return fStuff != NULL ? fStuff[index] : NULL; }
NFRule* remove(uint32_t index) {
+ if (fStuff == NULL) {
+ return NULL;
+ }
NFRule* result = fStuff[index];
fCount -= 1;
for (uint32_t i = index; i < fCount; ++i) { // assumes small arrays
fCapacity += 10;
fStuff = (NFRule**)uprv_realloc(fStuff, fCapacity * sizeof(NFRule*)); // assume success
}
- fStuff[fCount++] = thing;
+ if (fStuff != NULL) {
+ fStuff[fCount++] = thing;
+ } else {
+ fCapacity = 0;
+ fCount = 0;
+ }
}
uint32_t size() const { return fCount; }
- NFRule* last() const { return fCount > 0 ? fStuff[fCount-1] : NULL; }
+ NFRule* last() const { return (fCount > 0 && fStuff != NULL) ? fStuff[fCount-1] : NULL; }
NFRule** release() {
add(NULL); // ensure null termination
NFRule** result = fStuff;
fCapacity = 0;
return result;
}
+ void deleteAll() {
+ NFRule** tmp = NULL;
+ int32_t size = fCount;
+ if (size > 0) {
+ tmp = release();
+ for (int32_t i = 0; i < size; i++) {
+ delete tmp[i];
+ }
+ if (tmp) {
+ uprv_free(tmp);
+ }
+ }
+ }
private:
NFRuleList(const NFRuleList &other); // forbid copying of this class