} else {
// Case 3: the token is a non-ignorable literal.
- addMatcher(fWarehouse.nextCodePointMatcher(cp));
+ if (auto* ptr = fWarehouse.nextCodePointMatcher(cp, status)) {
+ addMatcher(*ptr);
+ } else {
+ // OOM; unwind the stack
+ return;
+ }
}
fLastTypeOrCp = type != TYPE_CODEPOINT ? type : cp;
}
return fSetupData->ignorables;
}
-NumberParseMatcher& AffixTokenMatcherWarehouse::nextCodePointMatcher(UChar32 cp) {
- return *fCodePoints.create(cp);
+NumberParseMatcher* AffixTokenMatcherWarehouse::nextCodePointMatcher(UChar32 cp, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ auto* result = fCodePoints.create(cp);
+ if (result == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return result;
}
IgnorablesMatcher& ignorables();
- NumberParseMatcher& nextCodePointMatcher(UChar32 cp);
+ NumberParseMatcher* nextCodePointMatcher(UChar32 cp, UErrorCode& status);
private:
// NOTE: The following field may be unsafe to access after construction is done!