diff options
author | georgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-03 23:21:30 +0000 |
---|---|---|
committer | georgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-03 23:21:30 +0000 |
commit | 69d71c5676b955a891f0ca1c106e0367638c328c (patch) | |
tree | a5e14074ae2d9142d2c78ba5ac25136103d5b2bc /third_party/libphonenumber/cpp/src/re2_cache.h | |
parent | a9481f48c038017efaac888b13f0d592d0975932 (diff) | |
download | chromium_src-69d71c5676b955a891f0ca1c106e0367638c328c.zip chromium_src-69d71c5676b955a891f0ca1c106e0367638c328c.tar.gz chromium_src-69d71c5676b955a891f0ca1c106e0367638c328c.tar.bz2 |
Autofill phone number enhancements and integration of Phone Number Util Library: part 1
Temporarily the whole library is included, until the patch is upstreamed.
BUG=71443
TEST=Unit-tested
Review URL: http://codereview.chromium.org/6803005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84000 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/libphonenumber/cpp/src/re2_cache.h')
-rw-r--r-- | third_party/libphonenumber/cpp/src/re2_cache.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/third_party/libphonenumber/cpp/src/re2_cache.h b/third_party/libphonenumber/cpp/src/re2_cache.h new file mode 100644 index 0000000..ab2e9bb --- /dev/null +++ b/third_party/libphonenumber/cpp/src/re2_cache.h @@ -0,0 +1,83 @@ +// Copyright (C) 2011 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Author: Fredrik Roubert <roubert@google.com> + +// RE2Cache is a simple wrapper around hash_map<> to store RE2 objects. +// +// To get a cached RE2 object for a regexp pattern string, create a ScopedAccess +// object with a pointer to the cache object and the pattern string itself as +// constructor parameters. If an RE2 object corresponding to the pattern string +// doesn't already exist, it will be created by the access object constructor. +// The access object implements operator const RE& and can therefore be passed +// as an argument to any function that expects an RE2 object. +// +// RE2Cache cache; +// RE2Cache::ScopedAccess foo(&cache, "foo"); +// bool match = RE2::FullMatch("foobar", foo); + +#ifndef I18N_PHONENUMBERS_RE2_CACHE_H_ +#define I18N_PHONENUMBERS_RE2_CACHE_H_ + +#ifdef __DEPRECATED +#undef __DEPRECATED // Don't warn for using <hash_map>. +#endif + +#include <cstddef> +#include <hash_map> +#include <string> + +#include "base/scoped_ptr.h" +#include "base/synchronization/lock.h" + +namespace re2 { +class RE2; +} // namespace re2 + +namespace i18n { +namespace phonenumbers { + +using re2::RE2; +using std::string; +using __gnu_cxx::hash_map; + +class RE2Cache { + private: + typedef hash_map<string, const RE2*> CacheImpl; + + public: + explicit RE2Cache(size_t min_items); + ~RE2Cache(); + + class ScopedAccess { + public: + ScopedAccess(RE2Cache* cache, const string& pattern); + operator const RE2&() const { return *regexp_; } + + private: + const RE2* regexp_; + friend class RE2CacheTest_AccessConstructor_Test; + }; + + private: + base::Lock lock_; // protects cache_impl_ + scoped_ptr<CacheImpl> cache_impl_; // protected by lock_ + friend class RE2CacheTest_CacheConstructor_Test; + friend class RE2CacheTest_AccessConstructor_Test; +}; + +} // namespace phonenumbers +} // namespace i18n + +#endif // I18N_PHONENUMBERS_RE2_CACHE_H_ |