aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/i18n/uspoof_conf.cpp
diff options
context:
space:
mode:
authorromankoshelev <romankoshelev@yandex-team.com>2023-08-14 19:51:50 +0300
committerromankoshelev <romankoshelev@yandex-team.com>2023-08-15 01:24:11 +0300
commitcfcd865e05c0d0525ea27d1e153a043b32a85138 (patch)
tree68d3b3b25271e8a4998505897a269ff7ce119b76 /contrib/libs/icu/i18n/uspoof_conf.cpp
parentccb790c507bd5e8ffe2ef9886ce5ee0a7ce22a15 (diff)
downloadydb-cfcd865e05c0d0525ea27d1e153a043b32a85138.tar.gz
Update ICU to 73.2
Diffstat (limited to 'contrib/libs/icu/i18n/uspoof_conf.cpp')
-rw-r--r--contrib/libs/icu/i18n/uspoof_conf.cpp99
1 files changed, 49 insertions, 50 deletions
diff --git a/contrib/libs/icu/i18n/uspoof_conf.cpp b/contrib/libs/icu/i18n/uspoof_conf.cpp
index 04081cabfb..42dba1c037 100644
--- a/contrib/libs/icu/i18n/uspoof_conf.cpp
+++ b/contrib/libs/icu/i18n/uspoof_conf.cpp
@@ -63,36 +63,32 @@ U_NAMESPACE_USE
// at the same time
//
-SPUString::SPUString(UnicodeString *s) {
- fStr = s;
+SPUString::SPUString(LocalPointer<UnicodeString> s) {
+ fStr = std::move(s);
fCharOrStrTableIndex = 0;
}
SPUString::~SPUString() {
- delete fStr;
}
-SPUStringPool::SPUStringPool(UErrorCode &status) : fVec(NULL), fHash(NULL) {
- fVec = new UVector(status);
- if (fVec == NULL) {
- status = U_MEMORY_ALLOCATION_ERROR;
+SPUStringPool::SPUStringPool(UErrorCode &status) : fVec(nullptr), fHash(nullptr) {
+ LocalPointer<UVector> vec(new UVector(status), status);
+ if (U_FAILURE(status)) {
return;
}
+ vec->setDeleter(
+ [](void *obj) {delete (SPUString *)obj;});
+ fVec = vec.orphan();
fHash = uhash_open(uhash_hashUnicodeString, // key hash function
uhash_compareUnicodeString, // Key Comparator
- NULL, // Value Comparator
+ nullptr, // Value Comparator
&status);
}
SPUStringPool::~SPUStringPool() {
- int i;
- for (i=fVec->size()-1; i>=0; i--) {
- SPUString *s = static_cast<SPUString *>(fVec->elementAt(i));
- delete s;
- }
delete fVec;
uhash_close(fHash);
}
@@ -135,18 +131,21 @@ void SPUStringPool::sort(UErrorCode &status) {
SPUString *SPUStringPool::addString(UnicodeString *src, UErrorCode &status) {
+ LocalPointer<UnicodeString> lpSrc(src);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
SPUString *hashedString = static_cast<SPUString *>(uhash_get(fHash, src));
- if (hashedString != NULL) {
- delete src;
- } else {
- hashedString = new SPUString(src);
- if (hashedString == NULL) {
- status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
- }
- uhash_put(fHash, src, hashedString, &status);
- fVec->addElementX(hashedString, status);
+ if (hashedString != nullptr) {
+ return hashedString;
+ }
+ LocalPointer<SPUString> spuStr(new SPUString(std::move(lpSrc)), status);
+ hashedString = spuStr.getAlias();
+ fVec->adoptElement(spuStr.orphan(), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
}
+ uhash_put(fHash, src, hashedString, &status);
return hashedString;
}
@@ -154,43 +153,43 @@ SPUString *SPUStringPool::addString(UnicodeString *src, UErrorCode &status) {
ConfusabledataBuilder::ConfusabledataBuilder(SpoofImpl *spImpl, UErrorCode &status) :
fSpoofImpl(spImpl),
- fInput(NULL),
- fTable(NULL),
- fKeySet(NULL),
- fKeyVec(NULL),
- fValueVec(NULL),
- fStringTable(NULL),
- stringPool(NULL),
- fParseLine(NULL),
- fParseHexNum(NULL),
+ fInput(nullptr),
+ fTable(nullptr),
+ fKeySet(nullptr),
+ fKeyVec(nullptr),
+ fValueVec(nullptr),
+ fStringTable(nullptr),
+ stringPool(nullptr),
+ fParseLine(nullptr),
+ fParseHexNum(nullptr),
fLineNum(0)
{
if (U_FAILURE(status)) {
return;
}
- fTable = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &status);
+ fTable = uhash_open(uhash_hashLong, uhash_compareLong, nullptr, &status);
fKeySet = new UnicodeSet();
- if (fKeySet == NULL) {
+ if (fKeySet == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
fKeyVec = new UVector(status);
- if (fKeyVec == NULL) {
+ if (fKeyVec == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
fValueVec = new UVector(status);
- if (fValueVec == NULL) {
+ if (fValueVec == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
stringPool = new SPUStringPool(status);
- if (stringPool == NULL) {
+ if (stringPool == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
@@ -218,7 +217,7 @@ void ConfusabledataBuilder::buildConfusableData(SpoofImpl * spImpl, const char *
}
ConfusabledataBuilder builder(spImpl, status);
builder.build(confusables, confusablesLen, status);
- if (U_FAILURE(status) && errorType != NULL) {
+ if (U_FAILURE(status) && errorType != nullptr) {
*errorType = USPOOF_SINGLE_SCRIPT_CONFUSABLE;
pe->line = builder.fLineNum;
}
@@ -228,22 +227,22 @@ void ConfusabledataBuilder::buildConfusableData(SpoofImpl * spImpl, const char *
void ConfusabledataBuilder::build(const char * confusables, int32_t confusablesLen,
UErrorCode &status) {
- // Convert the user input data from UTF-8 to UChar (UTF-16)
+ // Convert the user input data from UTF-8 to char16_t (UTF-16)
int32_t inputLen = 0;
if (U_FAILURE(status)) {
return;
}
- u_strFromUTF8(NULL, 0, &inputLen, confusables, confusablesLen, &status);
+ u_strFromUTF8(nullptr, 0, &inputLen, confusables, confusablesLen, &status);
if (status != U_BUFFER_OVERFLOW_ERROR) {
return;
}
status = U_ZERO_ERROR;
- fInput = static_cast<UChar *>(uprv_malloc((inputLen+1) * sizeof(UChar)));
- if (fInput == NULL) {
+ fInput = static_cast<char16_t *>(uprv_malloc((inputLen+1) * sizeof(char16_t)));
+ if (fInput == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
- u_strFromUTF8(fInput, inputLen+1, NULL, confusables, confusablesLen, &status);
+ u_strFromUTF8(fInput, inputLen+1, nullptr, confusables, confusablesLen, &status);
// Regular Expression to parse a line from Confusables.txt. The expression will match
@@ -264,12 +263,12 @@ void ConfusabledataBuilder::build(const char * confusables, int32_t confusablesL
"|^([ \\t]*(?:#.*?)?)$" // OR match empty lines or lines with only a #comment
"|^(.*?)$", -1, US_INV); // OR match any line, which catches illegal lines.
// TODO: Why are we using the regex C API here? C++ would just take UnicodeString...
- fParseLine = uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, &status);
+ fParseLine = uregex_open(pattern.getBuffer(), pattern.length(), 0, nullptr, &status);
// Regular expression for parsing a hex number out of a space-separated list of them.
// Capture group 1 gets the number, with spaces removed.
pattern = UNICODE_STRING_SIMPLE("\\s*([0-9A-F]+)");
- fParseHexNum = uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, &status);
+ fParseHexNum = uregex_open(pattern.getBuffer(), pattern.length(), 0, nullptr, &status);
// Zap any Byte Order Mark at the start of input. Changing it to a space is benign
// given the syntax of the input.
@@ -301,7 +300,7 @@ void ConfusabledataBuilder::build(const char * confusables, int32_t confusablesL
uregex_setText(fParseHexNum, &fInput[mapStringStart], mapStringLength, &status);
UnicodeString *mapString = new UnicodeString();
- if (mapString == NULL) {
+ if (mapString == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
@@ -371,7 +370,7 @@ void ConfusabledataBuilder::build(const char * confusables, int32_t confusablesL
for (UChar32 keyChar=fKeySet->getRangeStart(range);
keyChar <= fKeySet->getRangeEnd(range); keyChar++) {
SPUString *targetMapping = static_cast<SPUString *>(uhash_iget(fTable, keyChar));
- U_ASSERT(targetMapping != NULL);
+ U_ASSERT(targetMapping != nullptr);
// Set an error code if trying to consume a long string. Otherwise,
// codePointAndLengthToKey will abort on a U_ASSERT.
@@ -408,7 +407,7 @@ void ConfusabledataBuilder::build(const char * confusables, int32_t confusablesL
//
void ConfusabledataBuilder::outputData(UErrorCode &status) {
- U_ASSERT(fSpoofImpl->fSpoofData->fDataOwned == TRUE);
+ U_ASSERT(fSpoofImpl->fSpoofData->fDataOwned);
// The Key Table
// While copying the keys to the runtime array,
@@ -460,8 +459,8 @@ void ConfusabledataBuilder::outputData(UErrorCode &status) {
uint32_t stringsLength = fStringTable->length();
// Reserve an extra space so the string will be nul-terminated. This is
// only a convenience, for when debugging; it is not needed otherwise.
- UChar *strings =
- static_cast<UChar *>(fSpoofImpl->fSpoofData->reserveSpace(stringsLength*sizeof(UChar)+2, status));
+ char16_t *strings =
+ static_cast<char16_t *>(fSpoofImpl->fSpoofData->reserveSpace(stringsLength*sizeof(char16_t)+2, status));
if (U_FAILURE(status)) {
return;
}