-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In this commit we added the ParsingOptions from the java version which will make parsing in different ways easier
- Loading branch information
1 parent
5155f58
commit 9d7975a
Showing
5 changed files
with
159 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "i18n/phonenumbers/parsingoptions.h" | ||
|
||
#include "i18n/identifiers/regioncode.h" | ||
|
||
namespace i18n { | ||
namespace phonenumbers { | ||
|
||
ParsingOptions& ParsingOptions::SetDefaultRegion( | ||
i18n_identifiers::RegionCode default_region) { | ||
default_region_ = default_region; | ||
return *this; | ||
} | ||
|
||
ParsingOptions& ParsingOptions::SetKeepRawInput(bool keep_raw_input) { | ||
keep_raw_input_ = keep_raw_input; | ||
return *this; | ||
} | ||
|
||
} // namespace phonenumbers | ||
} // namespace i18n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef I18N_PHONENUMBERS_PARSINGOPTIONS_H_ | ||
#define I18N_PHONENUMBERS_PARSINGOPTIONS_H_ | ||
|
||
#include "i18n/identifiers/regioncode.h" | ||
|
||
namespace i18n { | ||
namespace phonenumbers { | ||
|
||
// Options for parsing a phone number. To be used with the ParseWithOptions | ||
// method. | ||
// Example: | ||
// ParsingOptions().SetDefaultRegion(RegionCode::US()).SetKeepRawInput(true); | ||
class ParsingOptions { | ||
public: | ||
ParsingOptions() = default; | ||
|
||
// Set the value for default_region_. | ||
ParsingOptions& SetDefaultRegion( | ||
i18n_identifiers::RegionCode default_region); | ||
|
||
// Set the value for keep_raw_input_. | ||
ParsingOptions& SetKeepRawInput(bool keep_raw_input); | ||
|
||
private: | ||
friend class PhoneNumberUtil; | ||
|
||
// 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. | ||
i18n_identifiers::RegionCode default_region_ = | ||
i18n_identifiers::RegionCode::ZZ(); | ||
|
||
// 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. | ||
bool keep_raw_input_ = false; | ||
}; | ||
|
||
} // namespace phonenumbers | ||
} // namespace i18n | ||
|
||
#endif // I1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.