mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-05 05:25:34 +00:00
ICU-22641 Change const refs in the class to const pointers
The function may return nullptr, we cannot just deref the return value. Change them to const pointer instead.
This commit is contained in:
parent
e81b8727aa
commit
f7f9dbb88d
4 changed files with 21 additions and 11 deletions
|
@ -64,6 +64,7 @@ U_NAMESPACE_BEGIN
|
|||
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CanonicalIterator)
|
||||
|
||||
|
||||
/**
|
||||
*@param source string to get results for
|
||||
*/
|
||||
|
@ -73,10 +74,10 @@ CanonicalIterator::CanonicalIterator(const UnicodeString &sourceStr, UErrorCode
|
|||
pieces_lengths(nullptr),
|
||||
current(nullptr),
|
||||
current_length(0),
|
||||
nfd(*Normalizer2::getNFDInstance(status)),
|
||||
nfcImpl(*Normalizer2Factory::getNFCImpl(status))
|
||||
nfd(Normalizer2::getNFDInstance(status)),
|
||||
nfcImpl(Normalizer2Factory::getNFCImpl(status))
|
||||
{
|
||||
if(U_SUCCESS(status) && nfcImpl.ensureCanonIterData(status)) {
|
||||
if(U_SUCCESS(status) && nfcImpl->ensureCanonIterData(status)) {
|
||||
setSource(sourceStr, status);
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +173,7 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
|
|||
int32_t i = 0;
|
||||
UnicodeString *list = nullptr;
|
||||
|
||||
nfd.normalize(newSource, source, status);
|
||||
nfd->normalize(newSource, source, status);
|
||||
if(U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
|
@ -219,7 +220,7 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
|
|||
// on the NFD form - see above).
|
||||
for (; i < source.length(); i += U16_LENGTH(cp)) {
|
||||
cp = source.char32At(i);
|
||||
if (nfcImpl.isCanonSegmentStarter(cp)) {
|
||||
if (nfcImpl->isCanonSegmentStarter(cp)) {
|
||||
source.extract(start, i-start, list[list_length++]); // add up to i
|
||||
start = i;
|
||||
}
|
||||
|
@ -390,7 +391,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
|
|||
//UnicodeString *possible = new UnicodeString(*((UnicodeString *)(ne2->value.pointer)));
|
||||
UnicodeString possible(*((UnicodeString *)(ne2->value.pointer)));
|
||||
UnicodeString attempt;
|
||||
nfd.normalize(possible, attempt, status);
|
||||
nfd->normalize(possible, attempt, status);
|
||||
|
||||
// TODO: check if operator == is semanticaly the same as attempt.equals(segment)
|
||||
if (attempt==segment) {
|
||||
|
@ -457,7 +458,7 @@ Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const cha
|
|||
for (int32_t i = 0; i < segLen; i += U16_LENGTH(cp)) {
|
||||
// see if any character is at the start of some decomposition
|
||||
U16_GET(segment, 0, i, segLen, cp);
|
||||
if (!nfcImpl.getCanonStartSet(cp, starts)) {
|
||||
if (!nfcImpl->getCanonStartSet(cp, starts)) {
|
||||
continue;
|
||||
}
|
||||
// if so, see which decompositions match
|
||||
|
@ -518,7 +519,7 @@ Hashtable *CanonicalIterator::extract(Hashtable *fillinResult, UChar32 comp, con
|
|||
UnicodeString temp(comp);
|
||||
int32_t inputLen=temp.length();
|
||||
UnicodeString decompString;
|
||||
nfd.normalize(temp, decompString, status);
|
||||
nfd->normalize(temp, decompString, status);
|
||||
if (U_FAILURE(status)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -582,7 +583,7 @@ Hashtable *CanonicalIterator::extract(Hashtable *fillinResult, UChar32 comp, con
|
|||
// brute force approach
|
||||
// check to make sure result is canonically equivalent
|
||||
UnicodeString trial;
|
||||
nfd.normalize(temp, trial, status);
|
||||
nfd->normalize(temp, trial, status);
|
||||
if(U_FAILURE(status) || trial.compare(segment+segmentPos, segLen - segmentPos) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -183,8 +183,8 @@ private:
|
|||
// transient fields
|
||||
UnicodeString buffer;
|
||||
|
||||
const Normalizer2 &nfd;
|
||||
const Normalizer2Impl &nfcImpl;
|
||||
const Normalizer2 *nfd;
|
||||
const Normalizer2Impl *nfcImpl;
|
||||
|
||||
// we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
|
||||
UnicodeString *getEquivalents(const UnicodeString &segment, int32_t &result_len, UErrorCode &status); //private String[] getEquivalents(String segment)
|
||||
|
|
|
@ -2517,6 +2517,13 @@ void CollationAPITest::TestGapTooSmall() {
|
|||
}
|
||||
}
|
||||
|
||||
void CollationAPITest::TestNFCNull() {
|
||||
IcuTestErrorCode errorCode(*this, "TestNFCNull");
|
||||
RuleBasedCollator coll(
|
||||
u"&†<†\u0f81\u0f81\u0f81\u0f81\u0f81|†", errorCode);
|
||||
errorCode.expectErrorAndReset(U_UNSUPPORTED_ERROR);
|
||||
}
|
||||
|
||||
void CollationAPITest::dump(UnicodeString msg, RuleBasedCollator* c, UErrorCode& status) {
|
||||
const char* bigone = "One";
|
||||
const char* littleone = "one";
|
||||
|
@ -2560,6 +2567,7 @@ void CollationAPITest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
|||
TESTCASE_AUTO(TestIterNumeric);
|
||||
TESTCASE_AUTO(TestBadKeywords);
|
||||
TESTCASE_AUTO(TestGapTooSmall);
|
||||
TESTCASE_AUTO(TestNFCNull);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
|
|
|
@ -174,6 +174,7 @@ public:
|
|||
void TestIterNumeric();
|
||||
void TestBadKeywords();
|
||||
void TestGapTooSmall();
|
||||
void TestNFCNull();
|
||||
|
||||
private:
|
||||
// If this is too small for the test data, just increase it.
|
||||
|
|
Loading…
Add table
Reference in a new issue