File tree 2 files changed +5
-5
lines changed 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -98,18 +98,17 @@ std::string llvm::convertToSnakeFromCamelCase(StringRef input) {
98
98
99
99
std::string snakeCase;
100
100
snakeCase.reserve (input.size ());
101
- auto check = [&input](size_t j, std::function <bool (int )> check ) {
102
- return j < input.size () ? check (input[j]) : false ;
101
+ auto check = [&input](size_t j, function_ref <bool (int )> predicate ) {
102
+ return j < input.size () && predicate (input[j]);
103
103
};
104
104
for (size_t i = 0 ; i < input.size (); ++i) {
105
- snakeCase.push_back (input[i]);
105
+ snakeCase.push_back (tolower (input[i]));
106
+ // Handles "runs" of capitals, such as in OPName -> op_name.
106
107
if (check (i, isupper) && check (i + 1 , isupper) && check (i + 2 , islower))
107
108
snakeCase.push_back (' _' );
108
109
if ((check (i, islower) || check (i, isdigit)) && check (i + 1 , isupper))
109
110
snakeCase.push_back (' _' );
110
111
}
111
- std::transform (snakeCase.begin (), snakeCase.end (), snakeCase.begin (),
112
- [](unsigned char c) { return std::tolower (c); });
113
112
return snakeCase;
114
113
}
115
114
Original file line number Diff line number Diff line change @@ -186,6 +186,7 @@ TEST(StringExtrasTest, ConvertToSnakeFromCamelCase) {
186
186
testConvertToSnakeCase (" opName" , " op_name" );
187
187
testConvertToSnakeCase (" OPName" , " op_name" );
188
188
testConvertToSnakeCase (" Intel_OCL_BI" , " intel_ocl_bi" );
189
+ testConvertToSnakeCase (" I32Attr" , " i32_attr" );
189
190
testConvertToSnakeCase (" opNAME" , " op_name" );
190
191
testConvertToSnakeCase (" opNAMe" , " op_na_me" );
191
192
testConvertToSnakeCase (" opnameE" , " opname_e" );
You can’t perform that action at this time.
0 commit comments