-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: master
Are you sure you want to change the base?
Create new class ParseWithOptions #3730
Conversation
a09decd
to
251e95e
Compare
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.
251e95e
to
45cb5e4
Compare
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.
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.
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. |
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.
Can you add " with the keepRawInput option set."?
/** | ||
* 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. | ||
*/ | ||
|
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.
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.
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.
Good job!
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.
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); |
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.
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. |
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.
// 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 |
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.
#endif // I1 | |
#endif // I18N_PHONENUMBERS_PARSINGOPTIONS_H_ |
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.
auto-generated file
@@ -0,0 +1,42 @@ | |||
#ifndef I18N_PHONENUMBERS_PARSINGOPTIONS_H_ |
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.
Please add the license header.
/** | ||
* 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; | ||
} |
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.
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.
/** | ||
* 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; | ||
} |
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.
See above comment regarding the comments.
if(value == false) { | ||
|
||
} |
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.
Please remove this unneeded if-statement.
public ParsingOptions withDefaultRegion(String regionCode) { | ||
return setDefaultRegion(regionCode); | ||
} |
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.
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.
Added java doc comments and deleted unnecessary functions
Created a new class called ParseWithOptions that should allow for easier use of different methods such as keepRawInput or defaultRegion.