diff options
author | Josh Haberman <jhaberman@gmail.com> | 2018-09-04 10:58:54 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2018-09-04 10:58:54 -0700 |
commit | d61aede89cf188367766b971f59cf57d7835d8e8 (patch) | |
tree | a19842c62c3c8f51389912ecafdf932d0a572bea /src/google/protobuf/util/internal/utility.h | |
parent | 45d03a977193d1dcce5251e4bffe17bf0ba738ec (diff) | |
download | protobuf-d61aede89cf188367766b971f59cf57d7835d8e8.tar.gz protobuf-d61aede89cf188367766b971f59cf57d7835d8e8.tar.bz2 protobuf-d61aede89cf188367766b971f59cf57d7835d8e8.zip |
Down-integrate from google3.
Diffstat (limited to 'src/google/protobuf/util/internal/utility.h')
-rw-r--r-- | src/google/protobuf/util/internal/utility.h | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/src/google/protobuf/util/internal/utility.h b/src/google/protobuf/util/internal/utility.h index 816987ae..6fe82959 100644 --- a/src/google/protobuf/util/internal/utility.h +++ b/src/google/protobuf/util/internal/utility.h @@ -44,6 +44,8 @@ #include <google/protobuf/stubs/status.h> #include <google/protobuf/stubs/statusor.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { class Method; @@ -68,46 +70,47 @@ static const int64 kTypeUrlSize = 19; // Finds the tech option identified by option_name. Parses the boolean value and // returns it. // When the option with the given name is not found, default_value is returned. -LIBPROTOBUF_EXPORT bool GetBoolOptionOrDefault( +PROTOBUF_EXPORT bool GetBoolOptionOrDefault( const RepeatedPtrField<google::protobuf::Option>& options, - const string& option_name, bool default_value); + const std::string& option_name, bool default_value); // Returns int64 option value. If the option isn't found, returns the // default_value. -LIBPROTOBUF_EXPORT int64 GetInt64OptionOrDefault( +PROTOBUF_EXPORT int64 GetInt64OptionOrDefault( const RepeatedPtrField<google::protobuf::Option>& options, - const string& option_name, int64 default_value); + const std::string& option_name, int64 default_value); // Returns double option value. If the option isn't found, returns the // default_value. -LIBPROTOBUF_EXPORT double GetDoubleOptionOrDefault( +PROTOBUF_EXPORT double GetDoubleOptionOrDefault( const RepeatedPtrField<google::protobuf::Option>& options, - const string& option_name, double default_value); + const std::string& option_name, double default_value); // Returns string option value. If the option isn't found, returns the // default_value. -LIBPROTOBUF_EXPORT string GetStringOptionOrDefault( +PROTOBUF_EXPORT std::string GetStringOptionOrDefault( const RepeatedPtrField<google::protobuf::Option>& options, - const string& option_name, const string& default_value); + const std::string& option_name, const std::string& default_value); // Returns a boolean value contained in Any type. // TODO(skarvaje): Make these utilities dealing with Any types more generic, // add more error checking and move to a more public/sharable location so others // can use. -LIBPROTOBUF_EXPORT bool GetBoolFromAny(const google::protobuf::Any& any); +PROTOBUF_EXPORT bool GetBoolFromAny(const google::protobuf::Any& any); // Returns int64 value contained in Any type. -LIBPROTOBUF_EXPORT int64 GetInt64FromAny(const google::protobuf::Any& any); +PROTOBUF_EXPORT int64 GetInt64FromAny(const google::protobuf::Any& any); // Returns double value contained in Any type. -LIBPROTOBUF_EXPORT double GetDoubleFromAny(const google::protobuf::Any& any); +PROTOBUF_EXPORT double GetDoubleFromAny(const google::protobuf::Any& any); // Returns string value contained in Any type. -LIBPROTOBUF_EXPORT string GetStringFromAny(const google::protobuf::Any& any); +PROTOBUF_EXPORT std::string GetStringFromAny(const google::protobuf::Any& any); // Returns the type string without the url prefix. e.g.: If the passed type is // 'type.googleapis.com/tech.type.Bool', the returned value is 'tech.type.Bool'. -LIBPROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl(StringPiece type_url); +PROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl( + StringPiece type_url); // Returns the simple_type with the base type url (kTypeServiceBaseUrl) // prefixed. @@ -115,13 +118,13 @@ LIBPROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl(StringPiece type_url); // E.g: // GetFullTypeWithUrl("google.protobuf.Timestamp") returns the string // "type.googleapis.com/google.protobuf.Timestamp". -LIBPROTOBUF_EXPORT const string GetFullTypeWithUrl(StringPiece simple_type); +PROTOBUF_EXPORT const std::string GetFullTypeWithUrl(StringPiece simple_type); // Finds and returns option identified by name and option_name within the // provided map. Returns nullptr if none found. const google::protobuf::Option* FindOptionOrNull( const RepeatedPtrField<google::protobuf::Option>& options, - const string& option_name); + const std::string& option_name); // Finds and returns the field identified by field_name in the passed tech Type // object. Returns nullptr if none found. @@ -155,51 +158,51 @@ const google::protobuf::EnumValue* FindEnumValueByNameWithoutUnderscoreOrNull( const google::protobuf::Enum* enum_type, StringPiece enum_name); // Converts input to camel-case and returns it. -LIBPROTOBUF_EXPORT string ToCamelCase(const StringPiece input); +PROTOBUF_EXPORT std::string ToCamelCase(const StringPiece input); // Converts enum name string to camel-case and returns it. -string EnumValueNameToLowerCamelCase(const StringPiece input); +std::string EnumValueNameToLowerCamelCase(const StringPiece input); // Converts input to snake_case and returns it. -LIBPROTOBUF_EXPORT string ToSnakeCase(StringPiece input); +PROTOBUF_EXPORT std::string ToSnakeCase(StringPiece input); // Returns true if type_name represents a well-known type. -LIBPROTOBUF_EXPORT bool IsWellKnownType(const string& type_name); +PROTOBUF_EXPORT bool IsWellKnownType(const std::string& type_name); // Returns true if 'bool_string' represents a valid boolean value. Only "true", // "false", "0" and "1" are allowed. -LIBPROTOBUF_EXPORT bool IsValidBoolString(const string& bool_string); +PROTOBUF_EXPORT bool IsValidBoolString(const std::string& bool_string); // Returns true if "field" is a protobuf map field based on its type. -LIBPROTOBUF_EXPORT bool IsMap(const google::protobuf::Field& field, - const google::protobuf::Type& type); +PROTOBUF_EXPORT bool IsMap(const google::protobuf::Field& field, + const google::protobuf::Type& type); // Returns true if the given type has special MessageSet wire format. bool IsMessageSetWireFormat(const google::protobuf::Type& type); // Infinity/NaN-aware conversion to string. -LIBPROTOBUF_EXPORT string DoubleAsString(double value); -LIBPROTOBUF_EXPORT string FloatAsString(float value); +PROTOBUF_EXPORT std::string DoubleAsString(double value); +PROTOBUF_EXPORT std::string FloatAsString(float value); // Convert from int32, int64, uint32, uint64, double or float to string. template <typename T> -string ValueAsString(T value) { +std::string ValueAsString(T value) { return SimpleItoa(value); } template <> -inline string ValueAsString(float value) { +inline std::string ValueAsString(float value) { return FloatAsString(value); } template <> -inline string ValueAsString(double value) { +inline std::string ValueAsString(double value) { return DoubleAsString(value); } // Converts a string to float. Unlike safe_strtof, conversion will fail if the // value fits into double but not float (e.g., DBL_MAX). -LIBPROTOBUF_EXPORT bool SafeStrToFloat(StringPiece str, float* value); +PROTOBUF_EXPORT bool SafeStrToFloat(StringPiece str, float* value); // Returns whether a StringPiece begins with the provided prefix. bool StringStartsWith(StringPiece text, StringPiece prefix); @@ -211,4 +214,6 @@ bool StringEndsWith(StringPiece text, StringPiece suffix); } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_UTILITY_H__ |