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

Create new class ParseWithOptions #3730

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

KarolJakubKrawiec
Copy link

Created a new class called ParseWithOptions that should allow for easier use of different methods such as keepRawInput or defaultRegion.

@KarolJakubKrawiec KarolJakubKrawiec requested a review from a team as a code owner November 27, 2024 13:04
@silvio2402 silvio2402 self-requested a review November 27, 2024 13:06
I have added the new parsing methode ParsingOptions to the OpenSource version.
There is a new class called PrasingOptions. With it we can replace old parsing methodes such as keepRawInput or defaultRegion.
I have added the new parsing methode ParsingOptions to the OpenSource version.
There is a new class called PrasingOptions. With it we can replace old parsing methodes such as keepRawInput or defaultRegion.
We had to switch up the deprecated test cases of parseAndKeepRawInput and replaced them with parseWithOptions. It includes the phonenumber that has to be parsed and the options such as if the raw input should be kept or what the default regioncode is.
Copy link
Collaborator

@silvio2402 silvio2402 left a comment

Choose a reason for hiding this comment

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

Good! Please also merge the changes from the base branch.

@@ -2085,7 +2085,7 @@ public void testMaybeExtractCountryCode() {
public void testParseNationalNumber() throws Exception {
// National prefix attached.
assertEquals(NZ_NUMBER, phoneUtil.parse("033316005", RegionCode.NZ));
// Some fields are not filled in by parse, but only by parseAndKeepRawInput.
// Some fields are not filled in by parse, but only by parseWithOptions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add " with the keepRawInput option set."?

Comment on lines 21 to 27
/**
* Returns the region we are expecting the number to be from. This is ignored if the number being
* parsed is written in international format. In case of national format, the country_code will be
* set to the one of this default region. If the number is guaranteed to start with a '+' followed
* by the country calling code, then RegionCode.ZZ or null can be supplied.
*/

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you move the javadoc above getDefaultRegion?

I rewrote some comments because they didnt make sense and were misplaced
In this commit we added the ParsingOptions from the java version which will make parsing in different ways easier
We created a new function that allows the user for customized parsing. You can choose based on what you want the numbers to be parsed.
Copy link
Collaborator

@silvio2402 silvio2402 left a comment

Choose a reason for hiding this comment

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

Good job!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this auto-generated file.

// Options for parsing a phone number. To be used with the ParseWithOptions
// method.
// Example:
// ParsingOptions().SetDefaultRegion(RegionCode::US()).SetKeepRawInput(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the example to use a string for the region code.

// number being parsed is written in international format. In case of national
// format, the country_code will be set to the one of this default region. If
// the number is guaranteed to start with a '+' followed by the country
// calling code, then RegionCode.ZZ or null can be supplied.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// calling code, then RegionCode.ZZ or null can be supplied.
// calling code, then "ZZ" or null can be supplied.

} // namespace phonenumbers
} // namespace i18n

#endif // I1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#endif // I1
#endif // I18N_PHONENUMBERS_PARSINGOPTIONS_H_

Copy link
Collaborator

Choose a reason for hiding this comment

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

auto-generated file

@@ -0,0 +1,42 @@
#ifndef I18N_PHONENUMBERS_PARSINGOPTIONS_H_
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add the license header.

Comment on lines 22 to 36
/**
* Returns the region we are expecting the number to be from. This is ignored if the number being
* parsed is written in international format. In case of national format, the country_code will be
* set to the one of this default region. If the number is guaranteed to start with a '+' followed
* by the country calling code, then RegionCode.ZZ or null can be supplied.
*/
private boolean hasDefaultRegion;
private String defaultRegion_ = null;
public boolean hasDefaultRegion() { return hasDefaultRegion; }
public String getDefaultRegion() { return defaultRegion_; }
public ParsingOptions setDefaultRegion(String value) {
hasDefaultRegion = (value != null);
defaultRegion_ = value;
return this;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please rephrase the comment to not say "returns" and move the comment above the field that holds the value (in this case defaultRegion_). Then add JavaDoc comments to each public function. The function comments should all have a link to the field from before.

Comment on lines 38 to 53
/**
* Returns whether the raw input should be kept in the PhoneNumber object. If true, the raw_input
* field and country_code_source fields will be populated.
*/
private boolean hasKeepRawInput;
private boolean keepRawInput_ = false;
public boolean hasKeepRawInput() { return hasKeepRawInput; }
public boolean isKeepRawInput() { return keepRawInput_; }
public ParsingOptions setKeepRawInput(boolean value) {
if(value == false) {

}
hasKeepRawInput = true;
keepRawInput_ = value;
return this;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above comment regarding the comments.

Comment on lines 47 to 49
if(value == false) {

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this unneeded if-statement.

Comment on lines 55 to 57
public ParsingOptions withDefaultRegion(String regionCode) {
return setDefaultRegion(regionCode);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we aren't using a Builder here creating a ParsingOptions object is pretty short. Hence I'd say we don't need this function here.

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.

2 participants