@@ -1109,17 +1109,21 @@ String String::_camelcase_to_underscore() const {
1109
1109
String new_string;
1110
1110
int start_index = 0 ;
1111
1111
1112
- for (int i = 1 ; i < size (); i++) {
1113
- bool is_prev_upper = is_unicode_upper_case (cstr[i - 1 ]);
1114
- bool is_prev_lower = is_unicode_lower_case (cstr[i - 1 ]);
1115
- bool is_prev_digit = is_digit (cstr[i - 1 ]);
1112
+ if (length () == 0 ) {
1113
+ return *this ;
1114
+ }
1116
1115
1117
- bool is_curr_upper = is_unicode_upper_case (cstr[i]);
1118
- bool is_curr_lower = is_unicode_lower_case (cstr[i]);
1119
- bool is_curr_digit = is_digit (cstr[i]);
1116
+ bool is_prev_upper = is_unicode_upper_case (cstr[0 ]);
1117
+ bool is_prev_lower = is_unicode_lower_case (cstr[0 ]);
1118
+ bool is_prev_digit = is_digit (cstr[0 ]);
1119
+
1120
+ for (int i = 1 ; i < length (); i++) {
1121
+ const bool is_curr_upper = is_unicode_upper_case (cstr[i]);
1122
+ const bool is_curr_lower = is_unicode_lower_case (cstr[i]);
1123
+ const bool is_curr_digit = is_digit (cstr[i]);
1120
1124
1121
1125
bool is_next_lower = false ;
1122
- if (i + 1 < size ()) {
1126
+ if (i + 1 < length ()) {
1123
1127
is_next_lower = is_unicode_lower_case (cstr[i + 1 ]);
1124
1128
}
1125
1129
@@ -1132,6 +1136,10 @@ String String::_camelcase_to_underscore() const {
1132
1136
new_string += substr (start_index, i - start_index) + " _" ;
1133
1137
start_index = i;
1134
1138
}
1139
+
1140
+ is_prev_upper = is_curr_upper;
1141
+ is_prev_lower = is_curr_lower;
1142
+ is_prev_digit = is_curr_digit;
1135
1143
}
1136
1144
1137
1145
new_string += substr (start_index, size () - start_index);
0 commit comments