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

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

Issue 6803005: Autofill phone number enhancements and integration of Phone Number Util Library: part 1 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months 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
Property Changes:
Added: svn:eol-style
+ LF
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 // Author: Philippe Liard
16
17 #ifndef I18N_PHONENUMBERS_STRINGUTIL_H_
18 #define I18N_PHONENUMBERS_STRINGUTIL_H_
19
20 #include <cstddef>
21 #include <string>
22
23 #include "base/basictypes.h"
24
25 namespace i18n {
26 namespace phonenumbers {
27
28 using std::string;
29
30 // Supports string("hello") + 10.
31 string operator+(const string& s, int n);
32
33 // Converts integer to string.
34 string SimpleItoa(uint64 n);
35 string SimpleItoa(int n);
36
37 // Replaces any occurrence of the character 'remove' (or the characters
38 // in 'remove') with the character 'replacewith'.
39 void StripString(string* s, const char* remove, char replacewith);
40
41 // Returns true if 'in' starts with 'prefix' and writes 'in' minus 'prefix' into
42 // 'out'.
43 bool TryStripPrefixString(const string& in, const string& prefix, string* out);
44
45 // Returns true if 's' ends with 'suffix'.
46 bool HasSuffixString(const string& s, const string& suffix);
47
48 // Converts string to int32.
49 void safe_strto32(const string& s, int32 *n);
50
51 // Converts string to uint64.
52 void safe_strtou64(const string& s, uint64 *n);
53
54 // Remove all occurrences of a given set of characters from a string.
55 void strrmm(string* s, const string& chars);
56
57 // Holds a reference to a std::string or C string. It can also be constructed
58 // from an integer which is converted to a string.
59 class StringHolder {
60 public:
61 // Don't make the constructors explicit to make the StrCat usage convenient.
62 StringHolder(const string& s);
63 StringHolder(const char* s);
64 StringHolder(uint64 n);
65 ~StringHolder();
66
67 const string* GetString() const {
68 return string_;
69 }
70
71 const char* GetCString() const {
72 return cstring_;
73 }
74
75 size_t Length() const {
76 return len_;
77 }
78
79 private:
80 const string converted_string_; // Stores the string converted from integer.
81 const string* const string_;
82 const char* const cstring_;
83 const size_t len_;
84 };
85
86 string& operator+=(string& lhs, const StringHolder& rhs);
87
88 // Efficient string concatenation.
89
90 string StrCat(const StringHolder& s1, const StringHolder& s2);
91
92 string StrCat(const StringHolder& s1, const StringHolder& s2,
93 const StringHolder& s3);
94
95 string StrCat(const StringHolder& s1, const StringHolder& s2,
96 const StringHolder& s3, const StringHolder& s4);
97
98 string StrCat(const StringHolder& s1, const StringHolder& s2,
99 const StringHolder& s3, const StringHolder& s4,
100 const StringHolder& s5);
101
102 string StrCat(const StringHolder& s1, const StringHolder& s2,
103 const StringHolder& s3, const StringHolder& s4,
104 const StringHolder& s5, const StringHolder& s6);
105
106 string StrCat(const StringHolder& s1, const StringHolder& s2,
107 const StringHolder& s3, const StringHolder& s4,
108 const StringHolder& s5, const StringHolder& s6,
109 const StringHolder& s7);
110
111 string StrCat(const StringHolder& s1, const StringHolder& s2,
112 const StringHolder& s3, const StringHolder& s4,
113 const StringHolder& s5, const StringHolder& s6,
114 const StringHolder& s7, const StringHolder& s8,
115 const StringHolder& s9, const StringHolder& s10,
116 const StringHolder& s11);
117
118 void StrAppend(string* dest, const StringHolder& s1);
119
120 void StrAppend(string* dest, const StringHolder& s1, const StringHolder& s2);
121
122 } // namespace phonenumbers
123 } // namespace i18n
124
125 #endif // I18N_PHONENUMBERS_STRINGUTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698