diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2014-11-10 17:34:54 -0800 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2014-11-10 17:34:54 -0800 |
commit | 6ef984af4b0c63c1c33127a12dcfc8e6359f0c9e (patch) | |
tree | d17c61ff9f3ae28224fbddac6d26bfc59e2cf755 /src/google/protobuf/stubs/strutil.h | |
parent | baca1a8a1aa180c42de6278d3b8286c4496c6a10 (diff) | |
download | protobuf-6ef984af4b0c63c1c33127a12dcfc8e6359f0c9e.tar.gz protobuf-6ef984af4b0c63c1c33127a12dcfc8e6359f0c9e.tar.bz2 protobuf-6ef984af4b0c63c1c33127a12dcfc8e6359f0c9e.zip |
Down-integrate from internal code base.
Diffstat (limited to 'src/google/protobuf/stubs/strutil.h')
-rw-r--r-- | src/google/protobuf/stubs/strutil.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index 4178ac9f..f2e1a944 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -57,6 +57,8 @@ namespace protobuf { // strings, so locale should not be taken into account. // ascii_isdigit() // Like above, but only accepts digits. +// ascii_isspace() +// Check if the character is a space character. // ---------------------------------------------------------------------- inline bool ascii_isalnum(char c) { @@ -69,6 +71,10 @@ inline bool ascii_isdigit(char c) { return ('0' <= c && c <= '9'); } +inline bool ascii_isspace(char c) { + return c == ' '; +} + // ---------------------------------------------------------------------- // HasPrefixString() // Check if a string begins with a given prefix. @@ -119,10 +125,15 @@ inline string StripSuffixString(const string& str, const string& suffix) { // in 'remove') with the character 'replacewith'. // Good for keeping html characters or protocol characters (\t) out // of places where they might cause a problem. +// StripWhitespace +// Removes whitespaces from both ends of the given string. // ---------------------------------------------------------------------- LIBPROTOBUF_EXPORT void StripString(string* s, const char* remove, char replacewith); +LIBPROTOBUF_EXPORT void StripWhitespace(string* s); + + // ---------------------------------------------------------------------- // LowerString() // UpperString() @@ -501,6 +512,16 @@ inline string ToString(string a) { // StrCat() // These methods join some strings together. // ---------------------------------------------------------------------- +template <typename T1, typename T2, typename T3, typename T4, typename T5, + typename T6, typename T7> +string StrCat( + const T1& a, const T2& b, const T3& c, const T4& d, const T5& e, + const T6& f, const T7& g) { + return internal::ToString(a) + internal::ToString(b) + + internal::ToString(c) + internal::ToString(d) + internal::ToString(e) + + internal::ToString(f) + internal::ToString(g); +} + template <typename T1, typename T2, typename T3, typename T4, typename T5> string StrCat( const T1& a, const T2& b, const T3& c, const T4& d, const T5& e) { @@ -556,6 +577,17 @@ string Join(const Range& components, // ---------------------------------------------------------------------- LIBPROTOBUF_EXPORT string ToHex(uint64 num); +// ---------------------------------------------------------------------- +// GlobalReplaceSubstring() +// Replaces all instances of a substring in a string. Does nothing +// if 'substring' is empty. Returns the number of replacements. +// +// NOTE: The string pieces must not overlap s. +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT int GlobalReplaceSubstring(const string& substring, + const string& replacement, + string* s); + } // namespace protobuf } // namespace google |