diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2016-03-08 09:29:49 -0500 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2016-03-08 09:29:49 -0500 |
commit | 1bf4b38f29d6cc3f24ad1e0b6c3339420bd719be (patch) | |
tree | 5490ef3898bcef4f43f53a45d255bcd611da341f /src/google | |
parent | 3dd323818911a486bc62d172988aa23f68e64a7c (diff) | |
download | protobuf-1bf4b38f29d6cc3f24ad1e0b6c3339420bd719be.tar.gz protobuf-1bf4b38f29d6cc3f24ad1e0b6c3339420bd719be.tar.bz2 protobuf-1bf4b38f29d6cc3f24ad1e0b6c3339420bd719be.zip |
Fix up handing of fields with leading names that should be all caps.
Add a compile test to confirm things are working as expected.
Diffstat (limited to 'src/google')
-rw-r--r-- | src/google/protobuf/compiler/objectivec/objectivec_helpers.cc | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 24ff2b56..613a511c 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -124,9 +124,14 @@ string UnderscoresToCamelCase(const string& input, bool first_capitalized) { } values.push_back(current); + string result; + bool first_segment_forces_upper = false; for (vector<string>::iterator i = values.begin(); i != values.end(); ++i) { string value = *i; bool all_upper = (kUpperSegments.count(value) > 0); + if (all_upper && (result.length() == 0)) { + first_segment_forces_upper = true; + } for (int j = 0; j < value.length(); j++) { if (j == 0 || all_upper) { value[j] = ascii_toupper(value[j]); @@ -134,13 +139,11 @@ string UnderscoresToCamelCase(const string& input, bool first_capitalized) { // Nothing, already in lower. } } - *i = value; - } - string result; - for (vector<string>::iterator i = values.begin(); i != values.end(); ++i) { - result += *i; + result += value; } - if ((result.length() != 0) && !first_capitalized) { + if ((result.length() != 0) && + !first_capitalized && + !first_segment_forces_upper) { result[0] = ascii_tolower(result[0]); } return result; |