diff options
author | Bo Yang <teboring@google.com> | 2016-09-19 13:45:07 -0700 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2016-10-10 11:23:36 -0700 |
commit | cc8ca5b6a5478b40546d4206392eb1471454460d (patch) | |
tree | c0b45abfa16d7d373a6ea8f7fe50f1de00ab938e /src/google/protobuf/util/internal/utility.cc | |
parent | 337a028bb65ccca4dda768695950b5aba53ae2c9 (diff) | |
download | protobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.tar.gz protobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.tar.bz2 protobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.zip |
Integrate internal changes
Diffstat (limited to 'src/google/protobuf/util/internal/utility.cc')
-rw-r--r-- | src/google/protobuf/util/internal/utility.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc index 5f613e77..9aab3481 100644 --- a/src/google/protobuf/util/internal/utility.cc +++ b/src/google/protobuf/util/internal/utility.cc @@ -41,6 +41,8 @@ #include <google/protobuf/stubs/map_util.h> #include <google/protobuf/stubs/mathlimits.h> +#include <algorithm> + namespace google { namespace protobuf { namespace util { @@ -178,6 +180,19 @@ const google::protobuf::Field* FindJsonFieldInTypeOrNull( return NULL; } +const google::protobuf::Field* FindFieldInTypeByNumberOrNull( + const google::protobuf::Type* type, int32 number) { + if (type != NULL) { + for (int i = 0; i < type->fields_size(); ++i) { + const google::protobuf::Field& field = type->fields(i); + if (field.number() == number) { + return &field; + } + } + } + return NULL; +} + const google::protobuf::EnumValue* FindEnumValueByNameOrNull( const google::protobuf::Enum* enum_type, StringPiece enum_name) { if (enum_type != NULL) { @@ -204,6 +219,32 @@ const google::protobuf::EnumValue* FindEnumValueByNumberOrNull( return NULL; } +const google::protobuf::EnumValue* FindEnumValueByNameWithoutUnderscoreOrNull( + const google::protobuf::Enum* enum_type, StringPiece enum_name) { + if (enum_type != NULL) { + for (int i = 0; i < enum_type->enumvalue_size(); ++i) { + const google::protobuf::EnumValue& enum_value = enum_type->enumvalue(i); + string enum_name_without_underscore = enum_value.name(); + + // Remove underscore from the name. + enum_name_without_underscore.erase( + std::remove(enum_name_without_underscore.begin(), + enum_name_without_underscore.end(), '_'), + enum_name_without_underscore.end()); + // Make the name uppercase. + for (string::iterator it = enum_name_without_underscore.begin(); + it != enum_name_without_underscore.end(); ++it) { + *it = ascii_toupper(*it); + } + + if (enum_name_without_underscore == enum_name) { + return &enum_value; + } + } + } + return NULL; +} + string ToCamelCase(const StringPiece input) { bool capitalize_next = false; bool was_cap = true; |