Chromium Code Reviews| Index: third_party/libaddressinput/chromium/cpp/src/rule.cc |
| diff --git a/third_party/libaddressinput/chromium/cpp/src/rule.cc b/third_party/libaddressinput/chromium/cpp/src/rule.cc |
| index 1566f646d15366e093d3a438551f172406edf109..46182ff12f527935dc2c3b1ced7504c92adddc65 100644 |
| --- a/third_party/libaddressinput/chromium/cpp/src/rule.cc |
| +++ b/third_party/libaddressinput/chromium/cpp/src/rule.cc |
| @@ -24,6 +24,7 @@ |
| #include "grit.h" |
| #include "messages.h" |
| +#include "region_data_constants.h" |
| #include "util/json.h" |
| #include "util/string_split.h" |
| @@ -157,6 +158,15 @@ int GetPostalCodeMessageId(const std::string& postal_code_type) { |
| return INVALID_MESSAGE_ID; |
| } |
| +// Parses the default region data into the static Rule object and returns a |
| +// constant reference to this object. Cannot return a copy of the object, |
| +// because Rule objects are not copyable. |
| +const Rule& InitDefaultRule() { |
| + static Rule rule; |
|
Evan Stade
2014/01/06 22:54:19
no static non-pods
Evan Stade
2014/01/06 23:33:17
In lieu of porting LeakyLazyInstance to libaddress
please use gerrit instead
2014/01/06 23:44:35
Done.
please use gerrit instead
2014/01/06 23:44:35
Done.
|
| + rule.ParseSerializedRule(RegionDataConstants::GetDefaultRegionData()); |
| + return rule; |
| +} |
| + |
| } // namespace |
| Rule::Rule() |
| @@ -171,6 +181,16 @@ Rule::Rule() |
| Rule::~Rule() {} |
| +// static |
| +const Rule& Rule::GetDefault() { |
| + // Returns the constant reference to the Rule object from InitDefaultRule(). |
| + // The static object is in InitDefaultRule(), but this function maintains a |
| + // constant static reference to it. The constant static reference avoids |
| + // re-parsing the default region data. |
| + static const Rule& kDefaultRule(InitDefaultRule()); |
| + return kDefaultRule; |
| +} |
| + |
| void Rule::CopyFrom(const Rule& rule) { |
| format_ = rule.format_; |
| required_ = rule.required_; |