diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc index 7a512ffb4293..646f80706c74 100644 --- a/src/google/protobuf/util/field_mask_util.cc +++ b/src/google/protobuf/util/field_mask_util.cc @@ -62,23 +62,23 @@ bool FieldMaskUtil::SnakeCaseToCamelCase(StringPiece input, std::string* output) { output->clear(); bool after_underscore = false; - for (unsigned int i = 0; i < input.size(); ++i) { - if (input[i] >= 'A' && input[i] <= 'Z') { + for (const char& input_char : input) { + if (input_char >= 'A' && input_char <= 'Z') { // The field name must not contain uppercase letters. return false; } if (after_underscore) { - if (input[i] >= 'a' && input[i] <= 'z') { - output->push_back(input[i] + 'A' - 'a'); + if (input_char >= 'a' && input_char <= 'z') { + output->push_back(input_char + 'A' - 'a'); after_underscore = false; } else { // The character after a "_" must be a lowercase letter. return false; } - } else if (input[i] == '_') { + } else if (input_char == '_') { after_underscore = true; } else { - output->push_back(input[i]); + output->push_back(input_char); } } if (after_underscore) { @@ -331,14 +331,13 @@ void FieldMaskTree::AddPath(const std::string& path) { } bool new_branch = false; Node* node = &root_; - for (const std::string& part : parts) { + for (const std::string& node_name : parts) { if (!new_branch && node != &root_ && node->children.empty()) { // Path matches an existing leaf node. This means the path is already // covered by this tree (for example, adding "foo.bar.baz" to a tree // which already contains "foo.bar"). return; } - const std::string& node_name = part; Node*& child = node->children[node_name]; if (child == NULL) { new_branch = true;