1 """Starlark helpers for Objective-C protos."""
3 # State constants for objc_proto_camel_case_name.
5 _last_was_lowercase = 1
6 _last_was_uppercase = 2
9 def objc_proto_camel_case_name(name):
10 """A Starlark version of the ObjC generator's CamelCase name transform.
13 src/google/protobuf/compiler/objectivec/names.cc's UnderscoresToCamelCase()
15 NOTE: This code is written to model the C++ in protoc's ObjC generator so it
16 is easier to confirm that the algorithms between the implementations match.
17 The customizations for starlark performance are:
18 - The cascade within the loop is reordered and special cases "_" to
19 optimize for google3 inputs.
20 - The "last was" state is handled via integers instead of three booleans.
22 The `first_capitalized` argument in the C++ code is left off this code and
23 it acts as if the value were `True`.
26 name: The proto file name to convert to camel case. The extension should
30 The converted proto name to camel case.
34 last_was = _last_was_other
35 for c in name.elems():
37 # lowercase letter can follow a lowercase or uppercase letter.
38 if last_was != _last_was_lowercase and last_was != _last_was_uppercase:
39 segments.append(current)
43 last_was = _last_was_lowercase
44 elif c == "_": # more common than rest, special case it.
45 last_was = _last_was_other
47 if last_was != _last_was_number:
48 segments.append(current)
51 last_was = _last_was_number
53 if last_was != _last_was_uppercase:
54 segments.append(current)
58 last_was = _last_was_uppercase
60 last_was = _last_was_other
61 segments.append(current)
64 if x in ("Url", "Http", "Https"):