Create new class ParseWithOptions#3730
Create new class ParseWithOptions#3730KarolJakubKrawiec wants to merge 13 commits intogoogle:masterfrom
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.
silvio2402
left a comment
There was a problem hiding this comment.
Good! Please also merge the changes from the base branch.
| // 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.
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.
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.
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.
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.
| // 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 No newline at end of file |
There was a problem hiding this comment.
| #endif // I1 | |
| #endif // I18N_PHONENUMBERS_PARSINGOPTIONS_H_ |
| @@ -0,0 +1,42 @@ | |||
| #ifndef I18N_PHONENUMBERS_PARSINGOPTIONS_H_ | |||
There was a problem hiding this comment.
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.
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.
See above comment regarding the comments.
| if(value == false) { | ||
|
|
||
| } |
There was a problem hiding this comment.
Please remove this unneeded if-statement.
| public ParsingOptions withDefaultRegion(String regionCode) { | ||
| return setDefaultRegion(regionCode); | ||
| } |
There was a problem hiding this comment.
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.