Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,14 @@ func splitWordBoundaries(s string) []byte {
}
if i+2 < len(s) {
if e := s[i+2]; isASCIIUpper(c) && isASCIIUpper(d) && isASCIILower(e) {
out = append(out, c, ' ', d, e)
i += 3
// The lowercase letter only marks where the acronym ends: it
// opens the next word, so leave it for the following iteration.
// Consuming it here skips the boundary check on the pair it
// forms with the byte after it, which kept "Pv6" glued together
// in "IPv6Address" while "Int8Value" split the same
// letter/digit boundary.
out = append(out, c, ' ', d)
i += 2
continue
}
}
Expand Down
15 changes: 15 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,18 @@ func TestAllCase(t *testing.T) {
KebabCase: "first-last",
SnakeCase: "first_last",
}},
{in: "IPv6Address", want: output{
PascalCase: "IPv6Address",
CamelCase: "iPv6Address",
KebabCase: "i-pv-6-address",
SnakeCase: "i_pv_6_address",
}},
{in: "HTMLv5Doc", want: output{
PascalCase: "HtmLv5Doc",
CamelCase: "htmLv5Doc",
KebabCase: "htm-lv-5-doc",
SnakeCase: "htm_lv_5_doc",
}},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -522,6 +534,9 @@ func TestWords(t *testing.T) {
{"UPPERCASE", []string{"UPPERCASE"}},
{"HTTPCode", []string{"HTTP", "Code"}},
{"Int8Value", []string{"Int", "8", "Value"}},
{"IPv6Address", []string{"I", "Pv", "6", "Address"}},
{"ABc1", []string{"A", "Bc", "1"}},
{"ABCdEf", []string{"AB", "Cd", "Ef"}},
}
for _, tc := range testCases {
tc := tc
Expand Down