-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): initial normalization 🙀 #9728
Changes from 1 commit
dcb6796
8c4642a
15e6fb6
daa0523
522d2ef
e64f596
736af4b
a577bd2
84b4836
b3de1ff
95ad1c4
bf15feb
79f37f7
9ee183c
93e1c18
9dbf70c
f1b12a1
c4c7361
3723e6b
4afe038
1d9820b
9292410
4cdc2c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -408,7 +408,6 @@ transform_entry::transform_entry(const std::u32string &from, const std::u32strin | |
init(); | ||
} | ||
|
||
// TODO-LDML: How do we return errors from here? | ||
transform_entry::transform_entry( | ||
const std::u32string &from, | ||
const std::u32string &to, | ||
|
@@ -417,13 +416,16 @@ transform_entry::transform_entry( | |
const kmx::kmx_plus &kplus, | ||
bool &valid) | ||
: fFrom(from), fTo(to), fFromPattern(nullptr), fMapFromStrId(mapFrom), fMapToStrId(mapTo) { | ||
valid = false; | ||
if (!valid) | ||
return; // exit early | ||
Comment on lines
+419
to
+420
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is similar to the status pattern from ICU. It means more work on the caller side but I guess I am okay with it! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it makes sure the c'tor can return failure. Could be a factory model, but the caller is using |
||
assert(!fFrom.empty()); // TODO-LDML: should not happen? | ||
assert((fMapFromStrId == 0) == (fMapToStrId == 0)); // we have both or we have neither. | ||
assert(kplus.strs != nullptr); | ||
assert(kplus.vars != nullptr); | ||
assert(kplus.elem != nullptr); | ||
valid = init(); | ||
if(!init()) { | ||
valid = false; | ||
} | ||
|
||
// setup mapFrom | ||
if (fMapFromStrId != 0) { | ||
|
@@ -460,21 +462,21 @@ transform_entry::transform_entry( | |
|
||
bool | ||
transform_entry::init() { | ||
if (!fFrom.empty()) { | ||
// TODO-LDML: if we have mapFrom, may need to do other processing. | ||
const std::u16string patstr = km::kbp::kmx::u32string_to_u16string(fFrom); | ||
UErrorCode status = U_ZERO_ERROR; | ||
/* const */ icu::UnicodeString patustr_raw = icu::UnicodeString(patstr.data(), (int32_t)patstr.length()); | ||
// add '$' to match to end | ||
patustr_raw.append(u'$'); | ||
icu::UnicodeString patustr; | ||
const icu::Normalizer2 *nfd = icu::Normalizer2::getNFDInstance(status); | ||
// NFD normalize on pattern creation | ||
nfd->normalize(patustr_raw, patustr, status); | ||
fFromPattern.reset(icu::RegexPattern::compile(patustr, 0, status)); | ||
return (UASSERT_SUCCESS(status)); | ||
} | ||
return false; // fFrom should not be empty. | ||
if (fFrom.empty()) { | ||
return false; | ||
} | ||
// TODO-LDML: if we have mapFrom, may need to do other processing. | ||
const std::u16string patstr = km::kbp::kmx::u32string_to_u16string(fFrom); | ||
UErrorCode status = U_ZERO_ERROR; | ||
/* const */ icu::UnicodeString patustr_raw = icu::UnicodeString(patstr.data(), (int32_t)patstr.length()); | ||
// add '$' to match to end | ||
patustr_raw.append(u'$'); | ||
icu::UnicodeString patustr; | ||
const icu::Normalizer2 *nfd = icu::Normalizer2::getNFDInstance(status); | ||
// NFD normalize on pattern creation | ||
nfd->normalize(patustr_raw, patustr, status); | ||
fFromPattern.reset(icu::RegexPattern::compile(patustr, 0, status)); | ||
return (UASSERT_SUCCESS(status)); | ||
} | ||
|
||
size_t | ||
|
@@ -813,6 +815,10 @@ transforms::load( | |
const std::u32string toStr = kmx::u16string_to_u32string(kplus.strs->get(element->to)); | ||
KMX_DWORD mapFrom = element->mapFrom; // copy, because of alignment | ||
KMX_DWORD mapTo = element->mapTo; // copy, because of alignment | ||
assert(!fromStr.empty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so we get an earlier assert |
||
if (fromStr.empty()) { | ||
valid = false; | ||
} | ||
newGroup.emplace_back(fromStr, toStr, mapFrom, mapTo, kplus, valid); // creating a transform_entry | ||
assert(valid); | ||
if(!valid) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, if valid came in false we leave with it false.
Only change it from true->false on err, don't set it to true here.