OLD | NEW |
| (Empty) |
1 Index: src/regexp_cache.cc | |
2 =================================================================== | |
3 --- src/regexp_cache.cc (revision 277) | |
4 +++ src/regexp_cache.cc (working copy) | |
5 @@ -26,35 +26,17 @@ | |
6 | |
7 using std::string; | |
8 | |
9 -#ifdef USE_HASH_MAP | |
10 - | |
11 -// A basic text book string hash function implementation, this one taken from | |
12 -// The Practice of Programming (Kernighan and Pike 1999). It could be a good | |
13 -// idea in the future to evaluate how well it actually performs and possibly | |
14 -// switch to another hash function better suited to this particular use case. | |
15 -namespace __gnu_cxx { | |
16 -template<> struct hash<string> { | |
17 - enum { MULTIPLIER = 31 }; | |
18 - size_t operator()(const string& key) const { | |
19 - size_t h = 0; | |
20 - for (const char* p = key.c_str(); *p != '\0'; ++p) { | |
21 - h *= MULTIPLIER; | |
22 - h += *p; | |
23 - } | |
24 - return h; | |
25 - } | |
26 -}; | |
27 -} // namespace __gnu_cxx | |
28 - | |
29 -#endif | |
30 - | |
31 namespace i18n { | |
32 namespace phonenumbers { | |
33 | |
34 using base::AutoLock; | |
35 | |
36 RegExpCache::RegExpCache(size_t min_items) | |
37 +#ifdef USE_TR1_UNORDERED_MAP | |
38 : cache_impl_(new CacheImpl(min_items)) {} | |
39 +#else // USE_TR1_UNORDERED_MAP | |
40 + : cache_impl_(new CacheImpl()) {} | |
41 +#endif // USE_TR1_UNORDERED_MAP | |
42 | |
43 RegExpCache::~RegExpCache() { | |
44 AutoLock l(lock_); | |
45 Index: src/phonenumberutil_test.cc | |
46 =================================================================== | |
47 --- src/phonenumberutil_test.cc (revision 277) | |
48 +++ src/phonenumberutil_test.cc (working copy) | |
49 @@ -1145,11 +1145,11 @@ | |
50 ExtractPossibleNumber("Tel:+800-345-600", &extracted_number); | |
51 EXPECT_EQ("+800-345-600", extracted_number); | |
52 // Should recognise wide digits as possible start values. | |
53 - ExtractPossibleNumber("023", &extracted_number); | |
54 - EXPECT_EQ("023", extracted_number); | |
55 + ExtractPossibleNumber("\xEF\xBC\x90\xEF\xBC\x92\xEF\xBC\x93", &extracted_numb
er); | |
56 + EXPECT_EQ("\xEF\xBC\x90\xEF\xBC\x92\xEF\xBC\x93", extracted_number); | |
57 // Dashes are not possible start values and should be removed. | |
58 - ExtractPossibleNumber("Num-123", &extracted_number); | |
59 - EXPECT_EQ("123", extracted_number); | |
60 + ExtractPossibleNumber("Num-\xEF\xBC\x91\xEF\xBC\x92\xEF\xBC\x93", &extracted_
number); | |
61 + EXPECT_EQ("\xEF\xBC\x91\xEF\xBC\x92\xEF\xBC\x93", extracted_number); | |
62 // If not possible number present, return empty string. | |
63 ExtractPossibleNumber("Num-....", &extracted_number); | |
64 EXPECT_EQ("", extracted_number); | |
65 @@ -1163,7 +1163,7 @@ | |
66 ExtractPossibleNumber("(650) 253-0000.", &extracted_number); | |
67 EXPECT_EQ("650) 253-0000", extracted_number); | |
68 // This case has a trailing RTL char. | |
69 - ExtractPossibleNumber("(650) 253-0000", &extracted_number); | |
70 + ExtractPossibleNumber("(650) 253-0000\xE2\x80\x8F", &extracted_number); | |
71 EXPECT_EQ("650) 253-0000", extracted_number); | |
72 } | |
73 | |
74 @@ -1207,7 +1207,7 @@ | |
75 // This number is no longer valid. | |
76 EXPECT_FALSE(phone_util_.IsValidNumber(bs_number)); | |
77 | |
78 - // La Mayotte and Réunion use 'leadingDigits' to differentiate them. | |
79 + // La Mayotte and R\xC3\xA9union use 'leadingDigits' to differentiate them. | |
80 PhoneNumber re_number; | |
81 re_number.set_country_code(262); | |
82 re_number.set_national_number(262123456ULL); | |
83 @@ -1675,13 +1675,13 @@ | |
84 EXPECT_TRUE(IsViablePhoneNumber("0800-4-PIZZA")); | |
85 // Only one or two digits before possible punctuation followed by more digits
. | |
86 // The punctuation used here is the unicode character u+3000. | |
87 - EXPECT_TRUE(IsViablePhoneNumber("1 34")); | |
88 - EXPECT_FALSE(IsViablePhoneNumber("1 3+4")); | |
89 + EXPECT_TRUE(IsViablePhoneNumber("1\xE3\x80\x80" "34")); | |
90 + EXPECT_FALSE(IsViablePhoneNumber("1\xE3\x80\x80" "3+4")); | |
91 // Unicode variants of possible starting character and other allowed | |
92 // punctuation/digits. | |
93 - EXPECT_TRUE(IsViablePhoneNumber("(1) 3456789")); | |
94 + EXPECT_TRUE(IsViablePhoneNumber("\xEF\xBC\x88" "1\xEF\xBC\x89\xE3\x80\x80" "3
456789")); | |
95 // Testing a leading + is okay. | |
96 - EXPECT_TRUE(IsViablePhoneNumber("+1) 3456789")); | |
97 + EXPECT_TRUE(IsViablePhoneNumber("+1\xEF\xBC\x89\xE3\x80\x80" "3456789")); | |
98 } | |
99 | |
100 TEST_F(PhoneNumberUtilTest, ConvertAlphaCharactersInNumber) { | |
101 @@ -1692,8 +1692,8 @@ | |
102 EXPECT_EQ(kExpectedOutput, input); | |
103 | |
104 // Try with some non-ASCII characters. | |
105 - input.assign("1 (800) ABC-DEF"); | |
106 - static const string kExpectedFullwidthOutput = "1 (800) 222-333"; | |
107 + input.assign("1\xE3\x80\x80\xEF\xBC\x88" "800) ABC-DEF"); | |
108 + static const string kExpectedFullwidthOutput = "1\xE3\x80\x80\xEF\xBC\x88" "8
00) 222-333"; | |
109 phone_util_.ConvertAlphaCharactersInNumber(&input); | |
110 EXPECT_EQ(kExpectedFullwidthOutput, input); | |
111 } | |
112 @@ -1717,13 +1717,13 @@ | |
113 TEST_F(PhoneNumberUtilTest, NormaliseOtherDigits) { | |
114 // The first digit is a full-width 2, the last digit is an Arabic-indic digit | |
115 // 5. | |
116 - string input_number("25٥"); | |
117 + string input_number("\xEF\xBC\x92" "5\xD9\xA5"); | |
118 Normalize(&input_number); | |
119 static const string kExpectedOutput("255"); | |
120 EXPECT_EQ(kExpectedOutput, input_number) | |
121 << "Conversion did not correctly replace non-latin digits"; | |
122 // The first digit is an Eastern-Arabic 5, the latter an Eastern-Arabic 0. | |
123 - string eastern_arabic_input_number("۵2۰"); | |
124 + string eastern_arabic_input_number("\xDB\xB5" "2\xDB\xB0"); | |
125 Normalize(&eastern_arabic_input_number); | |
126 static const string kExpectedOutput2("520"); | |
127 EXPECT_EQ(kExpectedOutput2, eastern_arabic_input_number) | |
128 @@ -2379,21 +2379,21 @@ | |
129 // Using a full-width plus sign. | |
130 test_number.Clear(); | |
131 EXPECT_EQ(PhoneNumberUtil::NO_PARSING_ERROR, | |
132 - phone_util_.Parse("+1 (650) 333-6000", | |
133 + phone_util_.Parse("\xEF\xBC\x8B" "1 (650) 333-6000", | |
134 RegionCode::SG(), &test_number)); | |
135 EXPECT_EQ(us_number, test_number); | |
136 // The whole number, including punctuation, is here represented in full-width | |
137 // form. | |
138 test_number.Clear(); | |
139 EXPECT_EQ(PhoneNumberUtil::NO_PARSING_ERROR, | |
140 - phone_util_.Parse("+1 (650) 333-6000", | |
141 + phone_util_.Parse("\xEF\xBC\x8B\xEF\xBC\x91\xE3\x80\x80\xEF\xBC\x88
\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90\xEF\xBC\x89\xE3\x80\x80\xEF\xBC\x93\xEF\xBC
\x93\xEF\xBC\x93\xEF\xBC\x8D\xEF\xBC\x96\xEF\xBC\x90\xEF\xBC\x90\xEF\xBC\x90", | |
142 RegionCode::SG(), &test_number)); | |
143 EXPECT_EQ(us_number, test_number); | |
144 | |
145 // Using the U+30FC dash. | |
146 test_number.Clear(); | |
147 EXPECT_EQ(PhoneNumberUtil::NO_PARSING_ERROR, | |
148 - phone_util_.Parse("+1 (650) 333ー6000", | |
149 + phone_util_.Parse("\xEF\xBC\x8B\xEF\xBC\x91\xE3\x80\x80\xEF\xBC\x88
\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90\xEF\xBC\x89\xE3\x80\x80\xEF\xBC\x93\xEF\xBC
\x93\xEF\xBC\x93\xE3\x83\xBC\xEF\xBC\x96\xEF\xBC\x90\xEF\xBC\x90\xEF\xBC\x90", | |
150 RegionCode::SG(), &test_number)); | |
151 EXPECT_EQ(us_number, test_number); | |
152 } | |
153 @@ -2633,7 +2633,7 @@ | |
154 // Test with full-width plus. | |
155 result_proto.Clear(); | |
156 EXPECT_EQ(PhoneNumberUtil::NO_PARSING_ERROR, | |
157 - phone_util_.Parse("+64 3 331 6005", RegionCode::GetUnknown(), | |
158 + phone_util_.Parse("\xEF\xBC\x8B" "64 3 331 6005", RegionCode::GetUn
known(), | |
159 &result_proto)); | |
160 EXPECT_EQ(nz_number, result_proto); | |
161 // Test with normal plus but leading characters that need to be stripped. | |
162 @@ -2792,7 +2792,7 @@ | |
163 EXPECT_EQ(us_with_extension, test_number); | |
164 test_number.Clear(); | |
165 EXPECT_EQ(PhoneNumberUtil::NO_PARSING_ERROR, | |
166 - phone_util_.Parse("(800) 901-3355 ,extensión 7246433", | |
167 + phone_util_.Parse("(800) 901-3355 ,extensi\xC3\xB3n 7246433", | |
168 RegionCode::US(), | |
169 &test_number)); | |
170 EXPECT_EQ(us_with_extension, test_number); | |
171 @@ -2800,7 +2800,7 @@ | |
172 // Repeat with the small letter o with acute accent created by combining | |
173 // characters. | |
174 EXPECT_EQ(PhoneNumberUtil::NO_PARSING_ERROR, | |
175 - phone_util_.Parse("(800) 901-3355 ,extensión 7246433", | |
176 + phone_util_.Parse("(800) 901-3355 ,extensio\xCC\x81n 7246433", | |
177 RegionCode::US(), | |
178 &test_number)); | |
179 EXPECT_EQ(us_with_extension, test_number); | |
180 Index: src/regexp_cache.h | |
181 =================================================================== | |
182 --- src/regexp_cache.h (revision 277) | |
183 +++ src/regexp_cache.h (working copy) | |
184 @@ -37,10 +37,7 @@ | |
185 #ifdef USE_TR1_UNORDERED_MAP | |
186 # include <tr1/unordered_map> | |
187 #elif defined(USE_HASH_MAP) | |
188 -# ifndef __DEPRECATED | |
189 -# define __DEPRECATED | |
190 -# endif | |
191 -# include <hash_map> | |
192 +# include "base/hash_tables.h" | |
193 #else | |
194 # error STL map type unsupported on this platform! | |
195 #endif | |
196 @@ -57,7 +54,7 @@ | |
197 #ifdef USE_TR1_UNORDERED_MAP | |
198 typedef std::tr1::unordered_map<string, const RegExp*> CacheImpl; | |
199 #elif defined(USE_HASH_MAP) | |
200 - typedef std::hash_map<string, const RegExp*> CacheImpl; | |
201 + typedef base::hash_map<string, const RegExp*> CacheImpl; | |
202 #endif | |
203 | |
204 public: | |
205 Index: src/phonenumberutil.cc | |
206 =================================================================== | |
207 --- src/phonenumberutil.cc (revision 277) | |
208 +++ src/phonenumberutil.cc (working copy) | |
209 @@ -33,7 +33,7 @@ | |
210 #include <unicode/utf8.h> | |
211 | |
212 #include "base/logging.h" | |
213 -#include "base/singleton.h" | |
214 +#include "base/memory/singleton.h" | |
215 #include "default_logger.h" | |
216 #include "encoding_utils.h" | |
217 #include "metadata.h" | |
218 @@ -62,7 +62,7 @@ | |
219 using google::protobuf::RepeatedPtrField; | |
220 | |
221 // static | |
222 -const char PhoneNumberUtil::kPlusChars[] = "++"; | |
223 +const char PhoneNumberUtil::kPlusChars[] = "+\xEF\xBC\x8B"; | |
224 // To find out the unicode code-point of the characters below in vim, highlight | |
225 // the character and type 'ga'. Note that the - is used to express ranges of | |
226 // full-width punctuation below, as well as being present in the expression | |
227 @@ -70,7 +70,7 @@ | |
228 // unicode character. | |
229 // static | |
230 const char PhoneNumberUtil::kValidPunctuation[] = | |
231 - "-x‐-―−ー--/ ()()[].\\[\\]/~⁓∼"; | |
232 + "-x\xE2\x80\x90-\xE2\x80\x95\xE2\x88\x92\xE3\x83\xBC\xEF\xBC\x8D-\xEF\xBC\x
8F \xC2\xA0\xE2\x80\x8B\xE2\x81\xA0\xE3\x80\x80()\xEF\xBC\x88\xEF\xBC\x89\xEF\xB
C\xBB\xEF\xBC\xBD.\\[\\]/~\xE2\x81\x93\xE2\x88\xBC"; | |
233 | |
234 namespace { | |
235 | |
236 @@ -450,35 +450,35 @@ | |
237 all_plus_number_grouping_symbols->insert( | |
238 make_pair(ToUnicodeCodepoint("-"), '-')); | |
239 all_plus_number_grouping_symbols->insert( | |
240 - make_pair(ToUnicodeCodepoint("-"), '-')); | |
241 + make_pair(ToUnicodeCodepoint("\xEF\xBC\x8D"), '-')); | |
242 all_plus_number_grouping_symbols->insert( | |
243 - make_pair(ToUnicodeCodepoint("‐"), '-')); | |
244 + make_pair(ToUnicodeCodepoint("\xE2\x80\x90"), '-')); | |
245 all_plus_number_grouping_symbols->insert( | |
246 - make_pair(ToUnicodeCodepoint("‑"), '-')); | |
247 + make_pair(ToUnicodeCodepoint("\xE2\x80\x91"), '-')); | |
248 all_plus_number_grouping_symbols->insert( | |
249 - make_pair(ToUnicodeCodepoint("‒"), '-')); | |
250 + make_pair(ToUnicodeCodepoint("\xE2\x80\x92"), '-')); | |
251 all_plus_number_grouping_symbols->insert( | |
252 - make_pair(ToUnicodeCodepoint("–"), '-')); | |
253 + make_pair(ToUnicodeCodepoint("\xE2\x80\x93"), '-')); | |
254 all_plus_number_grouping_symbols->insert( | |
255 - make_pair(ToUnicodeCodepoint("—"), '-')); | |
256 + make_pair(ToUnicodeCodepoint("\xE2\x80\x94"), '-')); | |
257 all_plus_number_grouping_symbols->insert( | |
258 - make_pair(ToUnicodeCodepoint("―"), '-')); | |
259 + make_pair(ToUnicodeCodepoint("\xE2\x80\x95"), '-')); | |
260 all_plus_number_grouping_symbols->insert( | |
261 - make_pair(ToUnicodeCodepoint("−"), '-')); | |
262 + make_pair(ToUnicodeCodepoint("\xE2\x88\x92"), '-')); | |
263 all_plus_number_grouping_symbols->insert( | |
264 make_pair(ToUnicodeCodepoint("/"), '/')); | |
265 all_plus_number_grouping_symbols->insert( | |
266 - make_pair(ToUnicodeCodepoint("/"), '/')); | |
267 + make_pair(ToUnicodeCodepoint("\xEF\xBC\x8F"), '/')); | |
268 all_plus_number_grouping_symbols->insert( | |
269 make_pair(ToUnicodeCodepoint(" "), ' ')); | |
270 all_plus_number_grouping_symbols->insert( | |
271 - make_pair(ToUnicodeCodepoint(" "), ' ')); | |
272 + make_pair(ToUnicodeCodepoint("\xE3\x80\x80"), ' ')); | |
273 all_plus_number_grouping_symbols->insert( | |
274 - make_pair(ToUnicodeCodepoint(""), ' ')); | |
275 + make_pair(ToUnicodeCodepoint("\xE2\x81\xA0"), ' ')); | |
276 all_plus_number_grouping_symbols->insert( | |
277 make_pair(ToUnicodeCodepoint("."), '.')); | |
278 all_plus_number_grouping_symbols->insert( | |
279 - make_pair(ToUnicodeCodepoint("."), '.')); | |
280 + make_pair(ToUnicodeCodepoint("\xEF\xBC\x8E"), '.')); | |
281 // Only the upper-case letters are added here - the lower-case versions are | |
282 // added programmatically. | |
283 alpha_mappings->insert(make_pair(ToUnicodeCodepoint("A"), '2')); | |
284 @@ -684,15 +684,13 @@ | |
285 // Public wrapper function to get a PhoneNumberUtil instance with the default | |
286 // metadata file. | |
287 // static | |
288 -#ifdef USE_GOOGLE_BASE | |
289 PhoneNumberUtil* PhoneNumberUtil::GetInstance() { | |
290 return Singleton<PhoneNumberUtil>::get(); | |
291 } | |
292 -#endif | |
293 | |
294 void PhoneNumberUtil::CreateRegularExpressions() const { | |
295 unique_international_prefix.reset(RegExp::Create( | |
296 - "[\\d]+(?:[~⁓∼~][\\d]+)?")); | |
297 + "[\\d]+(?:[~\xE2\x81\x93\xE2\x88\xBC\xEF\xBD\x9E][\\d]+)?")); | |
298 // The first_group_capturing_pattern was originally set to $1 but there are | |
299 // some countries for which the first group is not used in the national | |
300 // pattern (e.g. Argentina) so the $1 group does not match correctly. | |
301 @@ -713,16 +711,16 @@ | |
302 StrCat("[", kPlusChars, "]*(?:[", kValidPunctuation, "]*[", kDigits, | |
303 "]){3,}[", kValidAlpha, kValidPunctuation, kDigits, "]*"))); | |
304 // Canonical-equivalence doesn't seem to be an option with RE2, so we allow | |
305 - // two options for representing the ó - the character itself, and one in the | |
306 + // two options for representing the \xC3\xB3 - the character itself, and one
in the | |
307 // unicode decomposed form with the combining acute accent. Note that there | |
308 // are currently three capturing groups for the extension itself - if this | |
309 // number is changed, MaybeStripExtension needs to be updated. | |
310 const string capturing_extn_digits = StrCat("([", kDigits, "]{1,7})"); | |
311 known_extn_patterns.reset(new string( | |
312 StrCat(kRfc3966ExtnPrefix, capturing_extn_digits, "|" | |
313 - "[ \\t,]*(?:ext(?:ensi(?:ó?|ó))?n?|extn?|[,xx##~~]|" | |
314 - "int|int|anexo)" | |
315 - "[:\\..]?[ \\t,-]*", capturing_extn_digits, "#?|" | |
316 + "[ \xC2\xA0\\t,]*(?:ext(?:ensi(?:o\xCC\x81?|\xC3\xB3))?n?|\xEF\xBD
\x85\xEF\xBD\x98\xEF\xBD\x94\xEF\xBD\x8E?|[,x\xEF\xBD\x98#\xEF\xBC\x83~\xEF\xBD\
x9E]|" | |
317 + "int|\xEF\xBD\x89\xEF\xBD\x8E\xEF\xBD\x94|anexo)" | |
318 + "[:\\.\xEF\xBC\x8E]?[ \xC2\xA0\\t,-]*", capturing_extn_digits, "#?
|" | |
319 "[- ]+([", kDigits, "]{1,5})#"))); | |
320 extn_pattern.reset(RegExp::Create( | |
321 StrCat("(?i)(?:", *known_extn_patterns, ")$"))); | |
322 @@ -828,7 +826,7 @@ | |
323 // Note here that all NANPA formatting rules are contained by US, so we use | |
324 // that to format NANPA numbers. The same applies to Russian Fed regions - | |
325 // rules are contained by Russia. French Indian Ocean country rules are | |
326 - // contained by Réunion. | |
327 + // contained by R\xC3\xA9union. | |
328 string region_code; | |
329 GetRegionCodeForCountryCode(country_calling_code, ®ion_code); | |
330 if (!HasValidRegionCode(region_code, country_calling_code, | |
331 @@ -987,7 +985,7 @@ | |
332 // For regions that share a country calling code, the country calling code | |
333 // need not be dialled. This also applies when dialling within a region, so | |
334 // this if clause covers both these cases. | |
335 - // Technically this is the case for dialling from la Réunion to other | |
336 + // Technically this is the case for dialling from la R\xC3\xA9union to othe
r | |
337 // overseas departments of France (French Guiana, Martinique, Guadeloupe), | |
338 // but not vice versa - so we don't cover this edge case for now and for | |
339 // those cases return the version including country calling code. | |
340 Index: src/logger.h | |
341 =================================================================== | |
342 --- src/logger.h (revision 277) | |
343 +++ src/logger.h (working copy) | |
344 @@ -20,7 +20,7 @@ | |
345 #include <cstdio> | |
346 #include <string> | |
347 | |
348 -#include <base/scoped_ptr.h> | |
349 +#include "base/scoped_ptr.h" | |
350 | |
351 namespace i18n { | |
352 namespace phonenumbers { | |
353 Index: src/regexp_adapter_test.cc | |
354 =================================================================== | |
355 --- src/regexp_adapter_test.cc (revision 277) | |
356 +++ src/regexp_adapter_test.cc (working copy) | |
357 @@ -186,12 +186,12 @@ | |
358 } | |
359 | |
360 TEST(RegExpAdapter, TestUtf8) { | |
361 - const scoped_ptr<const RegExp> reg_exp(RegExp::Create("℡⊏([α-ω]*)⊐")); | |
362 + const scoped_ptr<const RegExp> reg_exp(RegExp::Create("\xE2\x84\xA1\xE2\x8A\x
8F([\xCE\xB1-\xCF\x89]*)\xE2\x8A\x90")); | |
363 string matched; | |
364 | |
365 - EXPECT_FALSE(reg_exp->Match("℡⊏123⊐", true, &matched)); | |
366 - EXPECT_TRUE(reg_exp->Match("℡⊏αβ⊐", true, &matched)); | |
367 - EXPECT_EQ("αβ", matched); | |
368 + EXPECT_FALSE(reg_exp->Match("\xE2\x84\xA1\xE2\x8A\x8F" "123\xE2\x8A\x90", tru
e, &matched)); | |
369 + EXPECT_TRUE(reg_exp->Match("\xE2\x84\xA1\xE2\x8A\x8F\xCE\xB1\xCE\xB2\xE2\x8A\
x90", true, &matched)); | |
370 + EXPECT_EQ("\xCE\xB1\xCE\xB2", matched); | |
371 } | |
372 | |
373 } // namespace phonenumbers | |
374 Index: src/phonenumberutil.h | |
375 =================================================================== | |
376 --- src/phonenumberutil.h (revision 277) | |
377 +++ src/phonenumberutil.h (working copy) | |
378 @@ -29,7 +29,7 @@ | |
379 | |
380 #include "base/basictypes.h" | |
381 #include "base/scoped_ptr.h" | |
382 -#include "base/singleton.h" | |
383 +#include "base/memory/singleton.h" | |
384 #include "phonenumber.pb.h" | |
385 | |
386 class TelephoneNumber; | |
387 @@ -57,20 +57,15 @@ | |
388 // codes can be found here: | |
389 // http://www.iso.org/iso/english_country_names_and_code_elements | |
390 | |
391 -#ifdef USE_GOOGLE_BASE | |
392 class PhoneNumberUtil { | |
393 friend struct DefaultSingletonTraits<PhoneNumberUtil>; | |
394 -#else | |
395 -class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { | |
396 - friend class Singleton<PhoneNumberUtil>; | |
397 -#endif | |
398 friend class PhoneNumberUtilTest; | |
399 public: | |
400 ~PhoneNumberUtil(); | |
401 | |
402 // INTERNATIONAL and NATIONAL formats are consistent with the definition | |
403 // in ITU-T Recommendation E. 123. For example, the number of the Google | |
404 - // Zürich office will be written as "+41 44 668 1800" in INTERNATIONAL | |
405 + // Zurich office will be written as "+41 44 668 1800" in INTERNATIONAL | |
406 // format, and as "044 668 1800" in NATIONAL format. E164 format is as per | |
407 // INTERNATIONAL format but with no formatting applied e.g. +41446681800. | |
408 // RFC3966 is as per INTERNATIONAL format, but with all spaces and other | |
409 @@ -147,9 +142,7 @@ | |
410 // | |
411 // The PhoneNumberUtil is implemented as a singleton. Therefore, calling | |
412 // getInstance multiple times will only result in one instance being created. | |
413 -#ifdef USE_GOOGLE_BASE | |
414 static PhoneNumberUtil* GetInstance(); | |
415 -#endif | |
416 | |
417 // Initialisation helper function used to populate the regular expressions in | |
418 // a defined order. | |
419 Index: src/default_logger.h | |
420 =================================================================== | |
421 --- src/default_logger.h (revision 277) | |
422 +++ src/default_logger.h (working copy) | |
423 @@ -45,7 +45,11 @@ | |
424 struct ConvertToString<int> { | |
425 static inline string DoWork(const int& n) { | |
426 char buffer[16]; | |
427 +#if defined(OS_WIN) | |
428 + _itoa_s(n, buffer, sizeof(buffer), 10); | |
429 +#else | |
430 std::snprintf(buffer, sizeof(buffer), "%d", n); | |
431 +#endif | |
432 return string(buffer); | |
433 } | |
434 }; | |
435 @@ -77,19 +81,6 @@ | |
436 namespace i18n { | |
437 namespace phonenumbers { | |
438 | |
439 -inline LoggerHandler VLOG(int n) { | |
440 - Logger* const logger_impl = Logger::mutable_logger_impl(); | |
441 - if (logger_impl->level() < n) { | |
442 - return LoggerHandler(NULL); | |
443 - } | |
444 - logger_impl->WriteLevel(); | |
445 - return LoggerHandler(logger_impl); | |
446 -} | |
447 - | |
448 -inline LoggerHandler LOG(int n) { | |
449 - return VLOG(n); | |
450 -} | |
451 - | |
452 // Default logger implementation used by PhoneNumberUtil class. It outputs the | |
453 // messages to the standard output. | |
454 class StdoutLogger : public Logger { | |
455 Index: src/base/string_piece.cc | |
456 =================================================================== | |
457 --- src/base/string_piece.cc (revision 277) | |
458 +++ src/base/string_piece.cc (working copy) | |
459 @@ -1,219 +0,0 @@ | |
460 -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
461 -// Use of this source code is governed by a BSD-style license that can be | |
462 -// found in the LICENSE file. | |
463 -// Copied from strings/stringpiece.cc with modifications | |
464 - | |
465 -#include <algorithm> | |
466 -#include <ostream> | |
467 - | |
468 -#include "base/string_piece.h" | |
469 - | |
470 -namespace base { | |
471 - | |
472 -typedef StringPiece::size_type size_type; | |
473 - | |
474 -std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { | |
475 - o.write(piece.data(), static_cast<std::streamsize>(piece.size())); | |
476 - return o; | |
477 -} | |
478 - | |
479 -bool operator==(const StringPiece& x, const StringPiece& y) { | |
480 - if (x.size() != y.size()) | |
481 - return false; | |
482 - | |
483 - return StringPiece::wordmemcmp(x.data(), y.data(), x.size()) == 0; | |
484 -} | |
485 - | |
486 -void StringPiece::CopyToString(std::string* target) const { | |
487 - target->assign(!empty() ? data() : "", size()); | |
488 -} | |
489 - | |
490 -void StringPiece::AppendToString(std::string* target) const { | |
491 - if (!empty()) | |
492 - target->append(data(), size()); | |
493 -} | |
494 - | |
495 -size_type StringPiece::copy(char* buf, size_type n, size_type pos) const { | |
496 - size_type ret = std::min(length_ - pos, n); | |
497 - memcpy(buf, ptr_ + pos, ret); | |
498 - return ret; | |
499 -} | |
500 - | |
501 -size_type StringPiece::find(const StringPiece& s, size_type pos) const { | |
502 - if (pos > length_) | |
503 - return npos; | |
504 - | |
505 - const char* result = std::search(ptr_ + pos, ptr_ + length_, | |
506 - s.ptr_, s.ptr_ + s.length_); | |
507 - const size_type xpos = result - ptr_; | |
508 - return xpos + s.length_ <= length_ ? xpos : npos; | |
509 -} | |
510 - | |
511 -size_type StringPiece::find(char c, size_type pos) const { | |
512 - if (pos >= length_) | |
513 - return npos; | |
514 - | |
515 - const char* result = std::find(ptr_ + pos, ptr_ + length_, c); | |
516 - return result != ptr_ + length_ ? static_cast<size_t>(result - ptr_) : npos; | |
517 -} | |
518 - | |
519 -size_type StringPiece::rfind(const StringPiece& s, size_type pos) const { | |
520 - if (length_ < s.length_) | |
521 - return npos; | |
522 - | |
523 - if (s.empty()) | |
524 - return std::min(length_, pos); | |
525 - | |
526 - const char* last = ptr_ + std::min(length_ - s.length_, pos) + s.length_; | |
527 - const char* result = std::find_end(ptr_, last, s.ptr_, s.ptr_ + s.length_); | |
528 - return result != last ? static_cast<size_t>(result - ptr_) : npos; | |
529 -} | |
530 - | |
531 -size_type StringPiece::rfind(char c, size_type pos) const { | |
532 - if (length_ == 0) | |
533 - return npos; | |
534 - | |
535 - for (size_type i = std::min(pos, length_ - 1); ; --i) { | |
536 - if (ptr_[i] == c) | |
537 - return i; | |
538 - if (i == 0) | |
539 - break; | |
540 - } | |
541 - return npos; | |
542 -} | |
543 - | |
544 -// For each character in characters_wanted, sets the index corresponding | |
545 -// to the ASCII code of that character to 1 in table. This is used by | |
546 -// the find_.*_of methods below to tell whether or not a character is in | |
547 -// the lookup table in constant time. | |
548 -// The argument `table' must be an array that is large enough to hold all | |
549 -// the possible values of an unsigned char. Thus it should be be declared | |
550 -// as follows: | |
551 -// bool table[UCHAR_MAX + 1] | |
552 -static inline void BuildLookupTable(const StringPiece& characters_wanted, | |
553 - bool* table) { | |
554 - const size_type length = characters_wanted.length(); | |
555 - const char* const data = characters_wanted.data(); | |
556 - for (size_type i = 0; i < length; ++i) { | |
557 - table[static_cast<unsigned char>(data[i])] = true; | |
558 - } | |
559 -} | |
560 - | |
561 -size_type StringPiece::find_first_of(const StringPiece& s, | |
562 - size_type pos) const { | |
563 - if (length_ == 0 || s.length_ == 0) | |
564 - return npos; | |
565 - | |
566 - // Avoid the cost of BuildLookupTable() for a single-character search. | |
567 - if (s.length_ == 1) | |
568 - return find_first_of(s.ptr_[0], pos); | |
569 - | |
570 - bool lookup[UCHAR_MAX + 1] = { false }; | |
571 - BuildLookupTable(s, lookup); | |
572 - for (size_type i = pos; i < length_; ++i) { | |
573 - if (lookup[static_cast<unsigned char>(ptr_[i])]) { | |
574 - return i; | |
575 - } | |
576 - } | |
577 - return npos; | |
578 -} | |
579 - | |
580 -size_type StringPiece::find_first_not_of(const StringPiece& s, | |
581 - size_type pos) const { | |
582 - if (length_ == 0) | |
583 - return npos; | |
584 - | |
585 - if (s.length_ == 0) | |
586 - return 0; | |
587 - | |
588 - // Avoid the cost of BuildLookupTable() for a single-character search. | |
589 - if (s.length_ == 1) | |
590 - return find_first_not_of(s.ptr_[0], pos); | |
591 - | |
592 - bool lookup[UCHAR_MAX + 1] = { false }; | |
593 - BuildLookupTable(s, lookup); | |
594 - for (size_type i = pos; i < length_; ++i) { | |
595 - if (!lookup[static_cast<unsigned char>(ptr_[i])]) { | |
596 - return i; | |
597 - } | |
598 - } | |
599 - return npos; | |
600 -} | |
601 - | |
602 -size_type StringPiece::find_first_not_of(char c, size_type pos) const { | |
603 - if (length_ == 0) | |
604 - return npos; | |
605 - | |
606 - for (; pos < length_; ++pos) { | |
607 - if (ptr_[pos] != c) { | |
608 - return pos; | |
609 - } | |
610 - } | |
611 - return npos; | |
612 -} | |
613 - | |
614 -size_type StringPiece::find_last_of(const StringPiece& s, size_type pos) const
{ | |
615 - if (length_ == 0 || s.length_ == 0) | |
616 - return npos; | |
617 - | |
618 - // Avoid the cost of BuildLookupTable() for a single-character search. | |
619 - if (s.length_ == 1) | |
620 - return find_last_of(s.ptr_[0], pos); | |
621 - | |
622 - bool lookup[UCHAR_MAX + 1] = { false }; | |
623 - BuildLookupTable(s, lookup); | |
624 - for (size_type i = std::min(pos, length_ - 1); ; --i) { | |
625 - if (lookup[static_cast<unsigned char>(ptr_[i])]) | |
626 - return i; | |
627 - if (i == 0) | |
628 - break; | |
629 - } | |
630 - return npos; | |
631 -} | |
632 - | |
633 -size_type StringPiece::find_last_not_of(const StringPiece& s, | |
634 - size_type pos) const { | |
635 - if (length_ == 0) | |
636 - return npos; | |
637 - | |
638 - size_type i = std::min(pos, length_ - 1); | |
639 - if (s.length_ == 0) | |
640 - return i; | |
641 - | |
642 - // Avoid the cost of BuildLookupTable() for a single-character search. | |
643 - if (s.length_ == 1) | |
644 - return find_last_not_of(s.ptr_[0], pos); | |
645 - | |
646 - bool lookup[UCHAR_MAX + 1] = { false }; | |
647 - BuildLookupTable(s, lookup); | |
648 - for (; ; --i) { | |
649 - if (!lookup[static_cast<unsigned char>(ptr_[i])]) | |
650 - return i; | |
651 - if (i == 0) | |
652 - break; | |
653 - } | |
654 - return npos; | |
655 -} | |
656 - | |
657 -size_type StringPiece::find_last_not_of(char c, size_type pos) const { | |
658 - if (length_ == 0) | |
659 - return npos; | |
660 - | |
661 - for (size_type i = std::min(pos, length_ - 1); ; --i) { | |
662 - if (ptr_[i] != c) | |
663 - return i; | |
664 - if (i == 0) | |
665 - break; | |
666 - } | |
667 - return npos; | |
668 -} | |
669 - | |
670 -StringPiece StringPiece::substr(size_type pos, size_type n) const { | |
671 - if (pos > length_) pos = length_; | |
672 - if (n > length_ - pos) n = length_ - pos; | |
673 - return StringPiece(ptr_ + pos, n); | |
674 -} | |
675 - | |
676 -const StringPiece::size_type StringPiece::npos = size_type(-1); | |
677 - | |
678 -} // namespace base | |
679 Index: src/base/synchronization/lock.h | |
680 =================================================================== | |
681 --- src/base/synchronization/lock.h (revision 277) | |
682 +++ src/base/synchronization/lock.h (working copy) | |
683 @@ -1,27 +0,0 @@ | |
684 -// Copyright (C) 2011 Google Inc. | |
685 -// | |
686 -// Licensed under the Apache License, Version 2.0 (the "License"); | |
687 -// you may not use this file except in compliance with the License. | |
688 -// You may obtain a copy of the License at | |
689 -// | |
690 -// http://www.apache.org/licenses/LICENSE-2.0 | |
691 -// | |
692 -// Unless required by applicable law or agreed to in writing, software | |
693 -// distributed under the License is distributed on an "AS IS" BASIS, | |
694 -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
695 -// See the License for the specific language governing permissions and | |
696 -// limitations under the License. | |
697 - | |
698 -// Author: Philippe Liard | |
699 - | |
700 -#ifndef I18N_PHONENUMBERS_BASE_SYNCHRONIZATION_LOCK_H_ | |
701 -#define I18N_PHONENUMBERS_BASE_SYNCHRONIZATION_LOCK_H_ | |
702 - | |
703 -#include <boost/thread/mutex.hpp> | |
704 - | |
705 -namespace base { | |
706 - typedef boost::mutex Lock; | |
707 - typedef boost::mutex::scoped_lock AutoLock; | |
708 -} | |
709 - | |
710 -#endif // I18N_PHONENUMBERS_BASE_SYNCHRONIZATION_LOCK_H_ | |
711 Index: src/base/string_piece.h | |
712 =================================================================== | |
713 --- src/base/string_piece.h (revision 277) | |
714 +++ src/base/string_piece.h (working copy) | |
715 @@ -1,192 +0,0 @@ | |
716 -// Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
717 -// Use of this source code is governed by a BSD-style license that can be | |
718 -// found in the LICENSE file. | |
719 -// Copied from strings/stringpiece.h with modifications | |
720 -// | |
721 -// A string-like object that points to a sized piece of memory. | |
722 -// | |
723 -// Functions or methods may use const StringPiece& parameters to accept either | |
724 -// a "const char*" or a "string" value that will be implicitly converted to | |
725 -// a StringPiece. The implicit conversion means that it is often appropriate | |
726 -// to include this .h file in other files rather than forward-declaring | |
727 -// StringPiece as would be appropriate for most other Google classes. | |
728 -// | |
729 -// Systematic usage of StringPiece is encouraged as it will reduce unnecessary | |
730 -// conversions from "const char*" to "string" and back again. | |
731 -// | |
732 - | |
733 -#ifndef BASE_STRING_PIECE_H_ | |
734 -#define BASE_STRING_PIECE_H_ | |
735 -#pragma once | |
736 - | |
737 -#include <string> | |
738 - | |
739 -#include "base/basictypes.h" | |
740 - | |
741 -namespace base { | |
742 - | |
743 -class StringPiece { | |
744 - public: | |
745 - // standard STL container boilerplate | |
746 - typedef size_t size_type; | |
747 - typedef char value_type; | |
748 - typedef const char* pointer; | |
749 - typedef const char& reference; | |
750 - typedef const char& const_reference; | |
751 - typedef ptrdiff_t difference_type; | |
752 - typedef const char* const_iterator; | |
753 - typedef const char* iterator; | |
754 - typedef std::reverse_iterator<const_iterator> const_reverse_iterator; | |
755 - typedef std::reverse_iterator<iterator> reverse_iterator; | |
756 - | |
757 - static const size_type npos; | |
758 - | |
759 - public: | |
760 - // We provide non-explicit singleton constructors so users can pass | |
761 - // in a "const char*" or a "string" wherever a "StringPiece" is | |
762 - // expected. | |
763 - StringPiece() : ptr_(NULL), length_(0) { } | |
764 - StringPiece(const char* str) | |
765 - : ptr_(str), length_((str == NULL) ? 0 : strlen(str)) { } | |
766 - StringPiece(const std::string& str) | |
767 - : ptr_(str.data()), length_(str.size()) { } | |
768 - StringPiece(const char* offset, size_type len) | |
769 - : ptr_(offset), length_(len) { } | |
770 - | |
771 - // data() may return a pointer to a buffer with embedded NULs, and the | |
772 - // returned buffer may or may not be null terminated. Therefore it is | |
773 - // typically a mistake to pass data() to a routine that expects a NUL | |
774 - // terminated string. | |
775 - const char* data() const { return ptr_; } | |
776 - size_type size() const { return length_; } | |
777 - size_type length() const { return length_; } | |
778 - bool empty() const { return length_ == 0; } | |
779 - | |
780 - void clear() { | |
781 - ptr_ = NULL; | |
782 - length_ = 0; | |
783 - } | |
784 - void set(const char* data, size_type len) { | |
785 - ptr_ = data; | |
786 - length_ = len; | |
787 - } | |
788 - void set(const char* str) { | |
789 - ptr_ = str; | |
790 - length_ = str ? strlen(str) : 0; | |
791 - } | |
792 - void set(const void* data, size_type len) { | |
793 - ptr_ = reinterpret_cast<const char*>(data); | |
794 - length_ = len; | |
795 - } | |
796 - | |
797 - char operator[](size_type i) const { return ptr_[i]; } | |
798 - | |
799 - void remove_prefix(size_type n) { | |
800 - ptr_ += n; | |
801 - length_ -= n; | |
802 - } | |
803 - | |
804 - void remove_suffix(size_type n) { | |
805 - length_ -= n; | |
806 - } | |
807 - | |
808 - int compare(const StringPiece& x) const { | |
809 - int r = wordmemcmp( | |
810 - ptr_, x.ptr_, (length_ < x.length_ ? length_ : x.length_)); | |
811 - if (r == 0) { | |
812 - if (length_ < x.length_) r = -1; | |
813 - else if (length_ > x.length_) r = +1; | |
814 - } | |
815 - return r; | |
816 - } | |
817 - | |
818 - std::string as_string() const { | |
819 - // std::string doesn't like to take a NULL pointer even with a 0 size. | |
820 - return std::string(!empty() ? data() : "", size()); | |
821 - } | |
822 - | |
823 - void CopyToString(std::string* target) const; | |
824 - void AppendToString(std::string* target) const; | |
825 - | |
826 - // Does "this" start with "x" | |
827 - bool starts_with(const StringPiece& x) const { | |
828 - return ((length_ >= x.length_) && | |
829 - (wordmemcmp(ptr_, x.ptr_, x.length_) == 0)); | |
830 - } | |
831 - | |
832 - // Does "this" end with "x" | |
833 - bool ends_with(const StringPiece& x) const { | |
834 - return ((length_ >= x.length_) && | |
835 - (wordmemcmp(ptr_ + (length_-x.length_), x.ptr_, x.length_) == 0)); | |
836 - } | |
837 - | |
838 - iterator begin() const { return ptr_; } | |
839 - iterator end() const { return ptr_ + length_; } | |
840 - const_reverse_iterator rbegin() const { | |
841 - return const_reverse_iterator(ptr_ + length_); | |
842 - } | |
843 - const_reverse_iterator rend() const { | |
844 - return const_reverse_iterator(ptr_); | |
845 - } | |
846 - | |
847 - size_type max_size() const { return length_; } | |
848 - size_type capacity() const { return length_; } | |
849 - | |
850 - size_type copy(char* buf, size_type n, size_type pos = 0) const; | |
851 - | |
852 - size_type find(const StringPiece& s, size_type pos = 0) const; | |
853 - size_type find(char c, size_type pos = 0) const; | |
854 - size_type rfind(const StringPiece& s, size_type pos = npos) const; | |
855 - size_type rfind(char c, size_type pos = npos) const; | |
856 - | |
857 - size_type find_first_of(const StringPiece& s, size_type pos = 0) const; | |
858 - size_type find_first_of(char c, size_type pos = 0) const { | |
859 - return find(c, pos); | |
860 - } | |
861 - size_type find_first_not_of(const StringPiece& s, size_type pos = 0) const; | |
862 - size_type find_first_not_of(char c, size_type pos = 0) const; | |
863 - size_type find_last_of(const StringPiece& s, size_type pos = npos) const; | |
864 - size_type find_last_of(char c, size_type pos = npos) const { | |
865 - return rfind(c, pos); | |
866 - } | |
867 - size_type find_last_not_of(const StringPiece& s, size_type pos = npos) const; | |
868 - size_type find_last_not_of(char c, size_type pos = npos) const; | |
869 - | |
870 - StringPiece substr(size_type pos, size_type n = npos) const; | |
871 - | |
872 - static int wordmemcmp(const char* p, const char* p2, size_type N) { | |
873 - return memcmp(p, p2, N); | |
874 - } | |
875 - | |
876 - private: | |
877 - const char* ptr_; | |
878 - size_type length_; | |
879 -}; | |
880 - | |
881 -bool operator==(const StringPiece& x, const StringPiece& y); | |
882 - | |
883 -inline bool operator!=(const StringPiece& x, const StringPiece& y) { | |
884 - return !(x == y); | |
885 -} | |
886 - | |
887 -inline bool operator<(const StringPiece& x, const StringPiece& y) { | |
888 - const int r = StringPiece::wordmemcmp( | |
889 - x.data(), y.data(), (x.size() < y.size() ? x.size() : y.size())); | |
890 - return ((r < 0) || ((r == 0) && (x.size() < y.size()))); | |
891 -} | |
892 - | |
893 -inline bool operator>(const StringPiece& x, const StringPiece& y) { | |
894 - return y < x; | |
895 -} | |
896 - | |
897 -inline bool operator<=(const StringPiece& x, const StringPiece& y) { | |
898 - return !(x > y); | |
899 -} | |
900 - | |
901 -inline bool operator>=(const StringPiece& x, const StringPiece& y) { | |
902 - return !(x < y); | |
903 -} | |
904 - | |
905 -} // namespace base | |
906 - | |
907 -#endif // BASE_STRING_PIECE_H_ | |
908 Index: src/base/scoped_ptr.h | |
909 =================================================================== | |
910 --- src/base/scoped_ptr.h (revision 277) | |
911 +++ src/base/scoped_ptr.h (working copy) | |
912 @@ -1,24 +0,0 @@ | |
913 -// Copyright (C) 2011 Google Inc. | |
914 -// | |
915 -// Licensed under the Apache License, Version 2.0 (the "License"); | |
916 -// you may not use this file except in compliance with the License. | |
917 -// You may obtain a copy of the License at | |
918 -// | |
919 -// http://www.apache.org/licenses/LICENSE-2.0 | |
920 -// | |
921 -// Unless required by applicable law or agreed to in writing, software | |
922 -// distributed under the License is distributed on an "AS IS" BASIS, | |
923 -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
924 -// See the License for the specific language governing permissions and | |
925 -// limitations under the License. | |
926 - | |
927 -// Author: Philippe Liard | |
928 - | |
929 -#ifndef I18N_PHONENUMBERS_BASE_SCOPED_PTR_H_ | |
930 -#define I18N_PHONENUMBERS_BASE_SCOPED_PTR_H_ | |
931 - | |
932 -#include <boost/scoped_ptr.hpp> | |
933 - | |
934 -using boost::scoped_ptr; | |
935 - | |
936 -#endif // I18N_PHONENUMBERS_BASE_SCOPED_PTR_H_ | |
937 Index: src/base/singleton.h | |
938 =================================================================== | |
939 --- src/base/singleton.h (revision 277) | |
940 +++ src/base/singleton.h (working copy) | |
941 @@ -1,52 +0,0 @@ | |
942 -// Copyright (C) 2011 Google Inc. | |
943 -// | |
944 -// Licensed under the Apache License, Version 2.0 (the "License"); | |
945 -// you may not use this file except in compliance with the License. | |
946 -// You may obtain a copy of the License at | |
947 -// | |
948 -// http://www.apache.org/licenses/LICENSE-2.0 | |
949 -// | |
950 -// Unless required by applicable law or agreed to in writing, software | |
951 -// distributed under the License is distributed on an "AS IS" BASIS, | |
952 -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
953 -// See the License for the specific language governing permissions and | |
954 -// limitations under the License. | |
955 - | |
956 -// Author: Philippe Liard | |
957 - | |
958 -#ifndef I18N_PHONENUMBERS_BASE_SINGLETON_H_ | |
959 -#define I18N_PHONENUMBERS_BASE_SINGLETON_H_ | |
960 - | |
961 -#include <boost/scoped_ptr.hpp> | |
962 -#include <boost/thread/once.hpp> | |
963 -#include <boost/utility.hpp> | |
964 - | |
965 -namespace i18n { | |
966 -namespace phonenumbers { | |
967 - | |
968 -template <class T> | |
969 -class Singleton : private boost::noncopyable { | |
970 - public: | |
971 - virtual ~Singleton() {} | |
972 - | |
973 - static T* GetInstance() { | |
974 - boost::call_once(Init, flag); | |
975 - return instance.get(); | |
976 - } | |
977 - | |
978 - private: | |
979 - static void Init() { | |
980 - instance.reset(new T()); | |
981 - } | |
982 - | |
983 - static boost::scoped_ptr<T> instance; | |
984 - static boost::once_flag flag; | |
985 -}; | |
986 - | |
987 -template <class T> boost::scoped_ptr<T> Singleton<T>::instance; | |
988 -template <class T> boost::once_flag Singleton<T>::flag = BOOST_ONCE_INIT; | |
989 - | |
990 -} // namespace phonenumbers | |
991 -} // namespace i18n | |
992 - | |
993 -#endif // I18N_PHONENUMBERS_BASE_SINGLETON_H_ | |
994 Index: src/base/basictypes.h | |
995 =================================================================== | |
996 --- src/base/basictypes.h (revision 277) | |
997 +++ src/base/basictypes.h (working copy) | |
998 @@ -1,380 +0,0 @@ | |
999 -// Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
1000 -// Use of this source code is governed by a BSD-style license that can be | |
1001 -// found in the LICENSE file. | |
1002 - | |
1003 -#ifndef BASE_BASICTYPES_H_ | |
1004 -#define BASE_BASICTYPES_H_ | |
1005 -#pragma once | |
1006 - | |
1007 -#include <limits.h> // So we can set the bounds of our types | |
1008 -#include <stddef.h> // For size_t | |
1009 -#include <string.h> // for memcpy | |
1010 - | |
1011 -#ifndef COMPILER_MSVC | |
1012 -// stdint.h is part of C99 but MSVC doesn't have it. | |
1013 -#include <stdint.h> // For intptr_t. | |
1014 -#endif | |
1015 - | |
1016 -#ifdef INT64_MAX | |
1017 - | |
1018 -// INT64_MAX is defined if C99 stdint.h is included; use the | |
1019 -// native types if available. | |
1020 -typedef int8_t int8; | |
1021 -typedef int16_t int16; | |
1022 -typedef int32_t int32; | |
1023 -typedef int64_t int64; | |
1024 -typedef uint8_t uint8; | |
1025 -typedef uint16_t uint16; | |
1026 -typedef uint32_t uint32; | |
1027 -typedef uint64_t uint64; | |
1028 - | |
1029 -const uint8 kuint8max = UINT8_MAX; | |
1030 -const uint16 kuint16max = UINT16_MAX; | |
1031 -const uint32 kuint32max = UINT32_MAX; | |
1032 -const uint64 kuint64max = UINT64_MAX; | |
1033 -const int8 kint8min = INT8_MIN; | |
1034 -const int8 kint8max = INT8_MAX; | |
1035 -const int16 kint16min = INT16_MIN; | |
1036 -const int16 kint16max = INT16_MAX; | |
1037 -const int32 kint32min = INT32_MIN; | |
1038 -const int32 kint32max = INT32_MAX; | |
1039 -const int64 kint64min = INT64_MIN; | |
1040 -const int64 kint64max = INT64_MAX; | |
1041 - | |
1042 -#else // !INT64_MAX | |
1043 - | |
1044 -typedef signed char int8; | |
1045 -typedef short int16; | |
1046 -// TODO: Remove these type guards. These are to avoid conflicts with | |
1047 -// obsolete/protypes.h in the Gecko SDK. | |
1048 -#ifndef _INT32 | |
1049 -#define _INT32 | |
1050 -typedef int int32; | |
1051 -#endif | |
1052 - | |
1053 -// The NSPR system headers define 64-bit as |long| when possible. In order to | |
1054 -// not have typedef mismatches, we do the same on LP64. | |
1055 -#if __LP64__ | |
1056 -typedef long int64; | |
1057 -#else | |
1058 -typedef long long int64; | |
1059 -#endif | |
1060 - | |
1061 -// NOTE: unsigned types are DANGEROUS in loops and other arithmetical | |
1062 -// places. Use the signed types unless your variable represents a bit | |
1063 -// pattern (eg a hash value) or you really need the extra bit. Do NOT | |
1064 -// use 'unsigned' to express "this value should always be positive"; | |
1065 -// use assertions for this. | |
1066 - | |
1067 -typedef unsigned char uint8; | |
1068 -typedef unsigned short uint16; | |
1069 -// TODO: Remove these type guards. These are to avoid conflicts with | |
1070 -// obsolete/protypes.h in the Gecko SDK. | |
1071 -#ifndef _UINT32 | |
1072 -#define _UINT32 | |
1073 -typedef unsigned int uint32; | |
1074 -#endif | |
1075 - | |
1076 -// See the comment above about NSPR and 64-bit. | |
1077 -#if __LP64__ | |
1078 -typedef unsigned long uint64; | |
1079 -#else | |
1080 -typedef unsigned long long uint64; | |
1081 -#endif | |
1082 - | |
1083 -#endif // !INT64_MAX | |
1084 - | |
1085 -typedef signed char schar; | |
1086 - | |
1087 -// A type to represent a Unicode code-point value. As of Unicode 4.0, | |
1088 -// such values require up to 21 bits. | |
1089 -// (For type-checking on pointers, make this explicitly signed, | |
1090 -// and it should always be the signed version of whatever int32 is.) | |
1091 -typedef signed int char32; | |
1092 - | |
1093 -// A macro to disallow the copy constructor and operator= functions | |
1094 -// This should be used in the private: declarations for a class | |
1095 -#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | |
1096 - TypeName(const TypeName&); \ | |
1097 - void operator=(const TypeName&) | |
1098 - | |
1099 -// An older, deprecated, politically incorrect name for the above. | |
1100 -// NOTE: The usage of this macro was baned from our code base, but some | |
1101 -// third_party libraries are yet using it. | |
1102 -// TODO(tfarina): Figure out how to fix the usage of this macro in the | |
1103 -// third_party libraries and get rid of it. | |
1104 -#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName) | |
1105 - | |
1106 -// A macro to disallow all the implicit constructors, namely the | |
1107 -// default constructor, copy constructor and operator= functions. | |
1108 -// | |
1109 -// This should be used in the private: declarations for a class | |
1110 -// that wants to prevent anyone from instantiating it. This is | |
1111 -// especially useful for classes containing only static methods. | |
1112 -#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | |
1113 - TypeName(); \ | |
1114 - DISALLOW_COPY_AND_ASSIGN(TypeName) | |
1115 - | |
1116 -// The arraysize(arr) macro returns the # of elements in an array arr. | |
1117 -// The expression is a compile-time constant, and therefore can be | |
1118 -// used in defining new arrays, for example. If you use arraysize on | |
1119 -// a pointer by mistake, you will get a compile-time error. | |
1120 -// | |
1121 -// One caveat is that arraysize() doesn't accept any array of an | |
1122 -// anonymous type or a type defined inside a function. In these rare | |
1123 -// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is | |
1124 -// due to a limitation in C++'s template system. The limitation might | |
1125 -// eventually be removed, but it hasn't happened yet. | |
1126 - | |
1127 -// This template function declaration is used in defining arraysize. | |
1128 -// Note that the function doesn't need an implementation, as we only | |
1129 -// use its type. | |
1130 -template <typename T, size_t N> | |
1131 -char (&ArraySizeHelper(T (&array)[N]))[N]; | |
1132 - | |
1133 -// That gcc wants both of these prototypes seems mysterious. VC, for | |
1134 -// its part, can't decide which to use (another mystery). Matching of | |
1135 -// template overloads: the final frontier. | |
1136 -#ifndef _MSC_VER | |
1137 -template <typename T, size_t N> | |
1138 -char (&ArraySizeHelper(const T (&array)[N]))[N]; | |
1139 -#endif | |
1140 - | |
1141 -#define arraysize(array) (sizeof(ArraySizeHelper(array))) | |
1142 - | |
1143 -// ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, | |
1144 -// but can be used on anonymous types or types defined inside | |
1145 -// functions. It's less safe than arraysize as it accepts some | |
1146 -// (although not all) pointers. Therefore, you should use arraysize | |
1147 -// whenever possible. | |
1148 -// | |
1149 -// The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type | |
1150 -// size_t. | |
1151 -// | |
1152 -// ARRAYSIZE_UNSAFE catches a few type errors. If you see a compiler error | |
1153 -// | |
1154 -// "warning: division by zero in ..." | |
1155 -// | |
1156 -// when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer. | |
1157 -// You should only use ARRAYSIZE_UNSAFE on statically allocated arrays. | |
1158 -// | |
1159 -// The following comments are on the implementation details, and can | |
1160 -// be ignored by the users. | |
1161 -// | |
1162 -// ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in | |
1163 -// the array) and sizeof(*(arr)) (the # of bytes in one array | |
1164 -// element). If the former is divisible by the latter, perhaps arr is | |
1165 -// indeed an array, in which case the division result is the # of | |
1166 -// elements in the array. Otherwise, arr cannot possibly be an array, | |
1167 -// and we generate a compiler error to prevent the code from | |
1168 -// compiling. | |
1169 -// | |
1170 -// Since the size of bool is implementation-defined, we need to cast | |
1171 -// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final | |
1172 -// result has type size_t. | |
1173 -// | |
1174 -// This macro is not perfect as it wrongfully accepts certain | |
1175 -// pointers, namely where the pointer size is divisible by the pointee | |
1176 -// size. Since all our code has to go through a 32-bit compiler, | |
1177 -// where a pointer is 4 bytes, this means all pointers to a type whose | |
1178 -// size is 3 or greater than 4 will be (righteously) rejected. | |
1179 - | |
1180 -#define ARRAYSIZE_UNSAFE(a) \ | |
1181 - ((sizeof(a) / sizeof(*(a))) / \ | |
1182 - static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) | |
1183 - | |
1184 - | |
1185 -// Use implicit_cast as a safe version of static_cast or const_cast | |
1186 -// for upcasting in the type hierarchy (i.e. casting a pointer to Foo | |
1187 -// to a pointer to SuperclassOfFoo or casting a pointer to Foo to | |
1188 -// a const pointer to Foo). | |
1189 -// When you use implicit_cast, the compiler checks that the cast is safe. | |
1190 -// Such explicit implicit_casts are necessary in surprisingly many | |
1191 -// situations where C++ demands an exact type match instead of an | |
1192 -// argument type convertable to a target type. | |
1193 -// | |
1194 -// The From type can be inferred, so the preferred syntax for using | |
1195 -// implicit_cast is the same as for static_cast etc.: | |
1196 -// | |
1197 -// implicit_cast<ToType>(expr) | |
1198 -// | |
1199 -// implicit_cast would have been part of the C++ standard library, | |
1200 -// but the proposal was submitted too late. It will probably make | |
1201 -// its way into the language in the future. | |
1202 -template<typename To, typename From> | |
1203 -inline To implicit_cast(From const &f) { | |
1204 - return f; | |
1205 -} | |
1206 - | |
1207 -// The COMPILE_ASSERT macro can be used to verify that a compile time | |
1208 -// expression is true. For example, you could use it to verify the | |
1209 -// size of a static array: | |
1210 -// | |
1211 -// COMPILE_ASSERT(ARRAYSIZE_UNSAFE(content_type_names) == CONTENT_NUM_TYPES, | |
1212 -// content_type_names_incorrect_size); | |
1213 -// | |
1214 -// or to make sure a struct is smaller than a certain size: | |
1215 -// | |
1216 -// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); | |
1217 -// | |
1218 -// The second argument to the macro is the name of the variable. If | |
1219 -// the expression is false, most compilers will issue a warning/error | |
1220 -// containing the name of the variable. | |
1221 - | |
1222 -template <bool> | |
1223 -struct CompileAssert { | |
1224 -}; | |
1225 - | |
1226 -#undef COMPILE_ASSERT | |
1227 -#define COMPILE_ASSERT(expr, msg) \ | |
1228 - typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] | |
1229 - | |
1230 -// Implementation details of COMPILE_ASSERT: | |
1231 -// | |
1232 -// - COMPILE_ASSERT works by defining an array type that has -1 | |
1233 -// elements (and thus is invalid) when the expression is false. | |
1234 -// | |
1235 -// - The simpler definition | |
1236 -// | |
1237 -// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] | |
1238 -// | |
1239 -// does not work, as gcc supports variable-length arrays whose sizes | |
1240 -// are determined at run-time (this is gcc's extension and not part | |
1241 -// of the C++ standard). As a result, gcc fails to reject the | |
1242 -// following code with the simple definition: | |
1243 -// | |
1244 -// int foo; | |
1245 -// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is | |
1246 -// // not a compile-time constant. | |
1247 -// | |
1248 -// - By using the type CompileAssert<(bool(expr))>, we ensures that | |
1249 -// expr is a compile-time constant. (Template arguments must be | |
1250 -// determined at compile-time.) | |
1251 -// | |
1252 -// - The outter parentheses in CompileAssert<(bool(expr))> are necessary | |
1253 -// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written | |
1254 -// | |
1255 -// CompileAssert<bool(expr)> | |
1256 -// | |
1257 -// instead, these compilers will refuse to compile | |
1258 -// | |
1259 -// COMPILE_ASSERT(5 > 0, some_message); | |
1260 -// | |
1261 -// (They seem to think the ">" in "5 > 0" marks the end of the | |
1262 -// template argument list.) | |
1263 -// | |
1264 -// - The array size is (bool(expr) ? 1 : -1), instead of simply | |
1265 -// | |
1266 -// ((expr) ? 1 : -1). | |
1267 -// | |
1268 -// This is to avoid running into a bug in MS VC 7.1, which | |
1269 -// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. | |
1270 - | |
1271 - | |
1272 -// MetatagId refers to metatag-id that we assign to | |
1273 -// each metatag <name, value> pair.. | |
1274 -typedef uint32 MetatagId; | |
1275 - | |
1276 -// Argument type used in interfaces that can optionally take ownership | |
1277 -// of a passed in argument. If TAKE_OWNERSHIP is passed, the called | |
1278 -// object takes ownership of the argument. Otherwise it does not. | |
1279 -enum Ownership { | |
1280 - DO_NOT_TAKE_OWNERSHIP, | |
1281 - TAKE_OWNERSHIP | |
1282 -}; | |
1283 - | |
1284 -// bit_cast<Dest,Source> is a template function that implements the | |
1285 -// equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in | |
1286 -// very low-level functions like the protobuf library and fast math | |
1287 -// support. | |
1288 -// | |
1289 -// float f = 3.14159265358979; | |
1290 -// int i = bit_cast<int32>(f); | |
1291 -// // i = 0x40490fdb | |
1292 -// | |
1293 -// The classical address-casting method is: | |
1294 -// | |
1295 -// // WRONG | |
1296 -// float f = 3.14159265358979; // WRONG | |
1297 -// int i = * reinterpret_cast<int*>(&f); // WRONG | |
1298 -// | |
1299 -// The address-casting method actually produces undefined behavior | |
1300 -// according to ISO C++ specification section 3.10 -15 -. Roughly, this | |
1301 -// section says: if an object in memory has one type, and a program | |
1302 -// accesses it with a different type, then the result is undefined | |
1303 -// behavior for most values of "different type". | |
1304 -// | |
1305 -// This is true for any cast syntax, either *(int*)&f or | |
1306 -// *reinterpret_cast<int*>(&f). And it is particularly true for | |
1307 -// conversions betweeen integral lvalues and floating-point lvalues. | |
1308 -// | |
1309 -// The purpose of 3.10 -15- is to allow optimizing compilers to assume | |
1310 -// that expressions with different types refer to different memory. gcc | |
1311 -// 4.0.1 has an optimizer that takes advantage of this. So a | |
1312 -// non-conforming program quietly produces wildly incorrect output. | |
1313 -// | |
1314 -// The problem is not the use of reinterpret_cast. The problem is type | |
1315 -// punning: holding an object in memory of one type and reading its bits | |
1316 -// back using a different type. | |
1317 -// | |
1318 -// The C++ standard is more subtle and complex than this, but that | |
1319 -// is the basic idea. | |
1320 -// | |
1321 -// Anyways ... | |
1322 -// | |
1323 -// bit_cast<> calls memcpy() which is blessed by the standard, | |
1324 -// especially by the example in section 3.9 . Also, of course, | |
1325 -// bit_cast<> wraps up the nasty logic in one place. | |
1326 -// | |
1327 -// Fortunately memcpy() is very fast. In optimized mode, with a | |
1328 -// constant size, gcc 2.95.3, gcc 4.0.1, and msvc 7.1 produce inline | |
1329 -// code with the minimal amount of data movement. On a 32-bit system, | |
1330 -// memcpy(d,s,4) compiles to one load and one store, and memcpy(d,s,8) | |
1331 -// compiles to two loads and two stores. | |
1332 -// | |
1333 -// I tested this code with gcc 2.95.3, gcc 4.0.1, icc 8.1, and msvc 7.1. | |
1334 -// | |
1335 -// WARNING: if Dest or Source is a non-POD type, the result of the memcpy | |
1336 -// is likely to surprise you. | |
1337 - | |
1338 -template <class Dest, class Source> | |
1339 -inline Dest bit_cast(const Source& source) { | |
1340 - // Compile time assertion: sizeof(Dest) == sizeof(Source) | |
1341 - // A compile error here means your Dest and Source have different sizes. | |
1342 - typedef char VerifySizesAreEqual [sizeof(Dest) == sizeof(Source) ? 1 : -1]; | |
1343 - | |
1344 - Dest dest; | |
1345 - memcpy(&dest, &source, sizeof(dest)); | |
1346 - return dest; | |
1347 -} | |
1348 - | |
1349 -// Used to explicitly mark the return value of a function as unused. If you are | |
1350 -// really sure you don't want to do anything with the return value of a functio
n | |
1351 -// that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: | |
1352 -// | |
1353 -// scoped_ptr<MyType> my_var = ...; | |
1354 -// if (TakeOwnership(my_var.get()) == SUCCESS) | |
1355 -// ignore_result(my_var.release()); | |
1356 -// | |
1357 -template<typename T> | |
1358 -inline void ignore_result(const T& ignored) { | |
1359 -} | |
1360 - | |
1361 -// The following enum should be used only as a constructor argument to indicate | |
1362 -// that the variable has static storage class, and that the constructor should | |
1363 -// do nothing to its state. It indicates to the reader that it is legal to | |
1364 -// declare a static instance of the class, provided the constructor is given | |
1365 -// the base::LINKER_INITIALIZED argument. Normally, it is unsafe to declare a | |
1366 -// static variable that has a constructor or a destructor because invocation | |
1367 -// order is undefined. However, IF the type can be initialized by filling with | |
1368 -// zeroes (which the loader does for static variables), AND the destructor also | |
1369 -// does nothing to the storage, AND there are no virtual methods, then a | |
1370 -// constructor declared as | |
1371 -// explicit MyClass(base::LinkerInitialized x) {} | |
1372 -// and invoked as | |
1373 -// static MyClass my_variable_name(base::LINKER_INITIALIZED); | |
1374 -namespace base { | |
1375 -enum LinkerInitialized { LINKER_INITIALIZED }; | |
1376 -} // base | |
1377 - | |
1378 -#endif // BASE_BASICTYPES_H_ | |
1379 Index: src/base/logging.h | |
1380 =================================================================== | |
1381 --- src/base/logging.h (revision 277) | |
1382 +++ src/base/logging.h (working copy) | |
1383 @@ -1,33 +0,0 @@ | |
1384 -// Copyright (C) 2011 Google Inc. | |
1385 -// | |
1386 -// Licensed under the Apache License, Version 2.0 (the "License"); | |
1387 -// you may not use this file except in compliance with the License. | |
1388 -// You may obtain a copy of the License at | |
1389 -// | |
1390 -// http://www.apache.org/licenses/LICENSE-2.0 | |
1391 -// | |
1392 -// Unless required by applicable law or agreed to in writing, software | |
1393 -// distributed under the License is distributed on an "AS IS" BASIS, | |
1394 -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
1395 -// See the License for the specific language governing permissions and | |
1396 -// limitations under the License. | |
1397 - | |
1398 -// Author: Philippe Liard | |
1399 - | |
1400 -// This file does not come from Chromium. | |
1401 -// It provides a minimalist implementation of common macros. | |
1402 - | |
1403 -#ifndef BASE_LOGGING_H_ | |
1404 -# define BASE_LOGGING_H_ | |
1405 - | |
1406 -# include <cassert> | |
1407 -# include <iostream> | |
1408 - | |
1409 -# define CHECK_EQ(X, Y) assert((X) == (Y)) | |
1410 - | |
1411 -# define DCHECK(X) assert(X) | |
1412 -# define DCHECK_EQ(X, Y) CHECK_EQ((X), (Y)) | |
1413 - | |
1414 -# define NOTREACHED() std::cerr | |
1415 - | |
1416 -#endif | |
OLD | NEW |