Skip to content

Commit dadb0d1

Browse files
committed
Merge branch 'dev' of github.com:rules-proto-grpc/rules_proto_grpc into dev
2 parents ad48699 + b4bc48d commit dadb0d1

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

internal/common.bzl

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def pascal_objc(s):
5959
"""
6060
Convert pascal_case -> PascalCase
6161
62-
Objective C uses pascal case, but there are e exceptions that it uppercases
63-
the entire segment: url, http, and https.
62+
Objective C uses pascal case, but there are exceptions that it uppercases.
63+
For example, it will uppercase the words "url", "http", and "https".
6464
6565
https://github.com/protocolbuffers/protobuf/blob/54176b26a9be6c9903b375596b778f51f5947921/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc#L91
6666
@@ -78,14 +78,50 @@ def pascal_objc(s):
7878
s = s.replace("-", "_")
7979

8080
segments = []
81-
for segment in s.split("_"):
81+
current = ""
82+
last_char_was_number = False
83+
last_char_was_lower = False
84+
last_char_was_upper = False
85+
for char in s.elems():
86+
if char.isdigit():
87+
if last_char_was_number:
88+
segments.append(current)
89+
current = ""
90+
current += char
91+
last_char_was_number = True
92+
last_char_was_lower = False
93+
last_char_was_upper = False
94+
elif char.islower():
95+
if not last_char_was_lower and not last_char_was_upper:
96+
segments.append(current)
97+
current = ""
98+
current += char
99+
last_char_was_number = False
100+
last_char_was_lower = True
101+
last_char_was_upper = False
102+
elif char.isupper():
103+
if not last_char_was_upper:
104+
segments.append(current)
105+
current = ""
106+
current += char.lower()
107+
last_char_was_number = False
108+
last_char_was_lower = False
109+
last_char_was_upper = True
110+
else:
111+
last_char_was_number = False
112+
last_char_was_lower = False
113+
last_char_was_upper = False
114+
segments.append(current)
115+
116+
new_segments = []
117+
for segment in segments:
82118
repl = _objc_upper_segments.get(segment)
83119
if repl:
84120
segment = repl
85121
else:
86122
segment = capitalize(segment)
87-
segments.append(segment)
88-
return "".join(segments)
123+
new_segments.append(segment)
124+
return "".join(new_segments)
89125

90126
def pascal_case(s):
91127
"""

0 commit comments

Comments
 (0)