Skip to content
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

ICU4C PluralRules - first implementation #222

Merged
merged 6 commits into from
May 20, 2024

Conversation

sven-oly
Copy link
Collaborator

@sven-oly sven-oly commented Apr 8, 2024

No description provided.

input_is_double = true;
cout << "# DOUBLE STRING " << input_double_sample << endl;
} else
if (sample_string.find('c') != std::string::npos) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test for compact decimal should come before the test of a decimal point because 1.2c6 is a valid compact decimal number, but 3.1415926 isn't.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a value can be both a double and a compact. This will need more work to see if ICU4C can handle compact input.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you still want to keep the handling of compact decimal numbers separate from regular floating point. The parsing for both is not the same, for starters.

So you want an if () { ...} else if () ... rather than if () {...} if () {...}

@sffc How do we want to handle compact input number strings for the ICU4C executor for plural rules? Because we have internal code to do so, but it's just not public.

// Convert into an integer, decimal, or compact decimal
input_double_sample = std::stod(sample_string);
input_is_double = true;
cout << "# DOUBLE STRING " << input_double_sample << endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove low level stdout printing statements, or else use a logging library and convert to debug level log line.

update: based on the TODO statements, it seems like this PR is meant to have a followup PR, and the stdout printing is a best approximation of debugging for development purposes. If that is the case, then instead of removing the stdout printing prematurely, add a few TODO comments to remove the stdout printing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly ready for release now. There's a big gap in both Node and CPP implementation, i.e., plural ranges. That should be a separate PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update code, fixing many lint complaints.

executors/cpp/plural_rules.cpp Outdated Show resolved Hide resolved
executors/cpp/plural_rules.cpp Outdated Show resolved Hide resolved
executors/cpp/plural_rules.cpp Outdated Show resolved Hide resolved
executors/cpp/plural_rules.cpp Show resolved Hide resolved
Copy link
Collaborator

@echeran echeran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just need a minor tweak on the conditional logic.

I also would like advice from @sffc on handling compact number input, but LMK if you want to merge without that and treat that as a followup improvement.

input_is_double = true;
cout << "# DOUBLE STRING " << input_double_sample << endl;
} else
if (sample_string.find('c') != std::string::npos) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you still want to keep the handling of compact decimal numbers separate from regular floating point. The parsing for both is not the same, for starters.

So you want an if () { ...} else if () ... rather than if () {...} if () {...}

@sffc How do we want to handle compact input number strings for the ICU4C executor for plural rules? Because we have internal code to do so, but it's just not public.

@sven-oly
Copy link
Collaborator Author

I'm not sure what to do with Compact vs. Decimal. Here are some options:

  1. Mark a compact value as "unsupported".
  2. Change "c" in a numeric string to "e", then treat as a decimal.
  3. Something else?

@sffc, please advise.

@sven-oly
Copy link
Collaborator Author

I'd appreciate more guidance on how to handle compact. Can we submit and then fix?

@sffc
Copy link
Member

sffc commented Apr 19, 2024

Please mark the compact values as "unsupported". I think we established that they are currently supported in ICU4X only.

@sven-oly
Copy link
Collaborator Author

I will set compact to unsupported.

@sven-oly
Copy link
Collaborator Author

PTAL: linted...

@sven-oly
Copy link
Collaborator Author

PTAL so we can add this component to ICU4C.

@sven-oly sven-oly merged commit 059575a into unicode-org:main May 20, 2024
6 checks passed
@sven-oly sven-oly deleted the cpp_plural branch May 30, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants