diff options
Diffstat (limited to 'src/google/protobuf/stubs/strutil.h')
-rw-r--r-- | src/google/protobuf/stubs/strutil.h | 123 |
1 files changed, 10 insertions, 113 deletions
diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index 4178ac9..777694b 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ +// http://code.google.com/p/protobuf/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -126,7 +126,6 @@ LIBPROTOBUF_EXPORT void StripString(string* s, const char* remove, // ---------------------------------------------------------------------- // LowerString() // UpperString() -// ToUpper() // Convert the characters in "s" to lowercase or uppercase. ASCII-only: // these functions intentionally ignore locale because they are applied to // identifiers used in the Protocol Buffer language, not to natural-language @@ -149,12 +148,6 @@ inline void UpperString(string * s) { } } -inline string ToUpper(const string& s) { - string out = s; - UpperString(&out); - return out; -} - // ---------------------------------------------------------------------- // StringReplace() // Give me a string and two patterns "old" and "new", and I replace @@ -175,33 +168,6 @@ LIBPROTOBUF_EXPORT string StringReplace(const string& s, const string& oldsub, LIBPROTOBUF_EXPORT void SplitStringUsing(const string& full, const char* delim, vector<string>* res); -// Split a string using one or more byte delimiters, presented -// as a nul-terminated c string. Append the components to 'result'. -// If there are consecutive delimiters, this function will return -// corresponding empty strings. If you want to drop the empty -// strings, try SplitStringUsing(). -// -// If "full" is the empty string, yields an empty string as the only value. -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT void SplitStringAllowEmpty(const string& full, - const char* delim, - vector<string>* result); - -// ---------------------------------------------------------------------- -// Split() -// Split a string using a character delimiter. -// ---------------------------------------------------------------------- -inline vector<string> Split( - const string& full, const char* delim, bool skip_empty = true) { - vector<string> result; - if (skip_empty) { - SplitStringUsing(full, delim, &result); - } else { - SplitStringAllowEmpty(full, delim, &result); - } - return result; -} - // ---------------------------------------------------------------------- // JoinStrings() // These methods concatenate a vector of strings into a C++ string, using @@ -241,7 +207,9 @@ inline string JoinStrings(const vector<string>& components, // hex digits, upper or lower case) to specify a Unicode code // point. The dest array will contain the UTF8-encoded version of // that code-point (e.g., if source contains \u2019, then dest will -// contain the three bytes 0xE2, 0x80, and 0x99). +// contain the three bytes 0xE2, 0x80, and 0x99). For the inverse +// transformation, use UniLib::UTF8EscapeString +// (util/utf8/unilib.h), not CEscapeString. // // Errors: In the first form of the call, errors are reported with // LOG(ERROR). The same is true for the second form of the call if @@ -349,15 +317,6 @@ inline uint64 strtou64(const char *nptr, char **endptr, int base) { } // ---------------------------------------------------------------------- -// safe_strto32() -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT bool safe_int(string text, int32* value_p); - -inline bool safe_strto32(string text, int32* value) { - return safe_int(text, value); -} - -// ---------------------------------------------------------------------- // FastIntToBuffer() // FastHexToBuffer() // FastHex64ToBuffer() @@ -485,78 +444,16 @@ static const int kDoubleToBufferSize = 32; static const int kFloatToBufferSize = 24; // ---------------------------------------------------------------------- -// ToString() are internal help methods used in StrCat() and Join() +// NoLocaleStrtod() +// Exactly like strtod(), except it always behaves as if in the "C" +// locale (i.e. decimal points must be '.'s). // ---------------------------------------------------------------------- -namespace internal { -inline string ToString(int i) { - return SimpleItoa(i); -} -inline string ToString(string a) { - return a; -} -} // namespace internal - -// ---------------------------------------------------------------------- -// StrCat() -// These methods join some strings together. -// ---------------------------------------------------------------------- -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) { - return internal::ToString(a) + internal::ToString(b) + - internal::ToString(c) + internal::ToString(d) + internal::ToString(e); -} - -template <typename T1, typename T2, typename T3, typename T4> -string StrCat( - const T1& a, const T2& b, const T3& c, const T4& d) { - return internal::ToString(a) + internal::ToString(b) + - internal::ToString(c) + internal::ToString(d); -} - -template <typename T1, typename T2, typename T3> -string StrCat(const T1& a, const T2& b, const T3& c) { - return internal::ToString(a) + internal::ToString(b) + - internal::ToString(c); -} - -template <typename T1, typename T2> -string StrCat(const T1& a, const T2& b) { - return internal::ToString(a) + internal::ToString(b); -} - -// ---------------------------------------------------------------------- -// Join() -// These methods concatenate a range of components into a C++ string, using -// the C-string "delim" as a separator between components. -// ---------------------------------------------------------------------- -template <typename Iterator> -void Join(Iterator start, Iterator end, - const char* delim, string* result) { - for (Iterator it = start; it != end; ++it) { - if (it != start) { - result->append(delim); - } - result->append(internal::ToString(*it)); - } -} - -template <typename Range> -string Join(const Range& components, - const char* delim) { - string result; - Join(components.begin(), components.end(), delim, &result); - return result; -} - -// ---------------------------------------------------------------------- -// ToHex() -// Return a lower-case hex string representation of the given integer. -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT string ToHex(uint64 num); +LIBPROTOBUF_EXPORT double NoLocaleStrtod(const char* text, char** endptr); } // namespace protobuf } // namespace google #endif // GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ + + |