Reputation: 105
I have a message:
message Image {
string link_40dp = 1;
}
After the compilation, in Java, the field name is link40Dp
(the first letter after a number is capitalized). But, I am expecting, that the field name would be link40dp
(d
in lower case).
Is it expected behavior or bug? Are there other corner-cases like this?
I am using Protobuf Gradle Plugin v0.8.5
and Protoc v3.6.1
to generate messages in Java.
Upvotes: 3
Views: 2756
Reputation: 105
I went through sources and found that it is the expected behavior.
See the code of the capitalization. All the capitalization rules can be found in the code snippet.
Upvotes: 1
Reputation: 109567
The field name was converted from snake case (with underscores) to camel case (with syllable capitals).
Hence for link_40dp
camel case would deliver "link" + capitalize("40dp")
.
Where capitalize(string) would turn the first letter into a capital.
The Apache commons library would capitalize "40dp" as "40dp" (no change) I think, but evidently here a "smarter" capitalize skips the digits.
This at least signals that the original string contained an underscore: link_40dp
, link4_0dp
or link40_dp
.
So it is an expected behavior, though rather unexpected.
Upvotes: 3