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

Unified Diff: third_party/protobuf/src/google/protobuf/util/internal/utility.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/util/internal/utility.cc
diff --git a/third_party/protobuf/src/google/protobuf/util/internal/utility.cc b/third_party/protobuf/src/google/protobuf/util/internal/utility.cc
index ee7a51fc41b6db81b4ee9b58cfaa11d7a023791e..05759e85ab62abb0d60ae2de4d3455282b3c171f 100644
--- a/third_party/protobuf/src/google/protobuf/util/internal/utility.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/utility.cc
@@ -30,6 +30,8 @@
#include <google/protobuf/util/internal/utility.h>
+#include <algorithm>
+
#include <google/protobuf/stubs/callback.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
@@ -52,7 +54,7 @@ const StringPiece SkipWhiteSpace(StringPiece str) {
for (i = 0; i < str.size() && isspace(str[i]); ++i) {
}
GOOGLE_DCHECK(i == str.size() || !isspace(str[i]));
- return StringPiece(str, i);
+ return str.substr(i);
}
} // namespace
@@ -128,8 +130,12 @@ string GetStringFromAny(const google::protobuf::Any& any) {
}
const StringPiece GetTypeWithoutUrl(StringPiece type_url) {
- size_t idx = type_url.rfind('/');
- return type_url.substr(idx + 1);
+ if (type_url.size() > kTypeUrlSize && type_url[kTypeUrlSize] == '/') {
+ return type_url.substr(kTypeUrlSize + 1);
+ } else {
+ size_t idx = type_url.rfind('/');
+ return type_url.substr(idx + 1);
+ }
}
const string GetFullTypeWithUrl(StringPiece simple_type) {
@@ -174,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) {
@@ -200,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;
@@ -279,7 +324,7 @@ string ToSnakeCase(StringPiece input) {
return result;
}
-set<string>* well_known_types_ = NULL;
+std::set<string>* well_known_types_ = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(well_known_types_init_);
const char* well_known_types_name_array_[] = {
"google.protobuf.Timestamp", "google.protobuf.Duration",
@@ -292,7 +337,7 @@ const char* well_known_types_name_array_[] = {
void DeleteWellKnownTypes() { delete well_known_types_; }
void InitWellKnownTypes() {
- well_known_types_ = new set<string>;
+ well_known_types_ = new std::set<string>;
for (int i = 0; i < GOOGLE_ARRAYSIZE(well_known_types_name_array_); ++i) {
well_known_types_->insert(well_known_types_name_array_[i]);
}
@@ -311,15 +356,23 @@ bool IsValidBoolString(const string& bool_string) {
bool IsMap(const google::protobuf::Field& field,
const google::protobuf::Type& type) {
- return (field.cardinality() ==
- google::protobuf::Field_Cardinality_CARDINALITY_REPEATED &&
- GetBoolOptionOrDefault(type.options(),
- "google.protobuf.MessageOptions.map_entry", false));
+ return (
+ field.cardinality() ==
+ google::protobuf::Field_Cardinality_CARDINALITY_REPEATED &&
+ (GetBoolOptionOrDefault(
+ type.options(), "google.protobuf.MessageOptions.map_entry", false) ||
+ GetBoolOptionOrDefault(type.options(), "proto2.MessageOptions.map_entry",
+ false)));
}
bool IsMessageSetWireFormat(const google::protobuf::Type& type) {
- return GetBoolOptionOrDefault(
- type.options(), "google.protobuf.MessageOptions.message_set_wire_format", false);
+ return (
+ GetBoolOptionOrDefault(
+ type.options(),
+ "google.protobuf.MessageOptions.message_set_wire_format", false) ||
+ GetBoolOptionOrDefault(type.options(),
+ "proto2.MessageOptions.message_set_wire_format",
+ false));
}
string DoubleAsString(double value) {
@@ -359,3 +412,4 @@ bool SafeStrToFloat(StringPiece str, float* value) {
} // namespace util
} // namespace protobuf
} // namespace google
+

Powered by Google App Engine
This is Rietveld 408576698