Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: third_party/libphonenumber/cpp/src/normalize_utf8.h

Issue 8736001: Pull the phone library directly. Delete old version. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (C) 2011 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <string>
16
17 #include "utf/unicodetext.h"
18
19 namespace i18n {
20 namespace phonenumbers {
21
22 using std::string;
23
24 struct NormalizeUTF8 {
25 // Put a UTF-8 string in ASCII digits: All decimal digits (Nd) replaced by
26 // their ASCII counterparts; all other characters are copied from input to
27 // output.
28 static string NormalizeDecimalDigits(const string& number) {
29 string normalized;
30 UnicodeText number_as_unicode;
31 number_as_unicode.PointToUTF8(number.data(), number.size());
32 for (UnicodeText::const_iterator it = number_as_unicode.begin();
33 it != number_as_unicode.end();
34 ++it) {
35 int32_t digitValue = u_charDigitValue(*it);
36 if (digitValue == -1) {
37 // Not a decimal digit.
38 char utf8[4];
39 int len = it.get_utf8(utf8);
40 normalized.append(utf8, len);
41 } else {
42 normalized.push_back('0' + digitValue);
43 }
44 }
45 return normalized;
46 }
47 };
48
49 } // namespace phonenumbers
50 } // namespace i18n
OLDNEW
« no previous file with comments | « third_party/libphonenumber/cpp/src/metadata.cc ('k') | third_party/libphonenumber/cpp/src/phonenumber.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698