| 1133 | } |
| 1134 | |
| 1135 | void FindShortestSeparator(const StringPiece& start, |
| 1136 | const StringPiece& limit, |
| 1137 | string* separator) { |
| 1138 | // Find length of common prefix |
| 1139 | size_t min_length = min(start.size(), limit.size()); |
| 1140 | size_t diff_index = 0; |
| 1141 | while ((diff_index < min_length) && |
| 1142 | (start[diff_index] == limit[diff_index])) { |
| 1143 | diff_index++; |
| 1144 | } |
| 1145 | |
| 1146 | if (diff_index >= min_length) { |
| 1147 | // Handle the case where either string is a prefix of the other |
| 1148 | // string, or both strings are identical. |
| 1149 | start.CopyToString(separator); |
| 1150 | return; |
| 1151 | } |
| 1152 | |
| 1153 | if (diff_index+1 == start.size()) { |
| 1154 | // If the first difference is in the last character, do not bother |
| 1155 | // incrementing that character since the separator will be no |
| 1156 | // shorter than "start". |
| 1157 | start.CopyToString(separator); |
| 1158 | return; |
| 1159 | } |
| 1160 | |
| 1161 | if (start[diff_index] == 0xff) { |
| 1162 | // Avoid overflow when incrementing start[diff_index] |
| 1163 | start.CopyToString(separator); |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | separator->assign(start.data(), diff_index); |
| 1168 | separator->push_back(start[diff_index] + 1); |
| 1169 | if (*separator >= limit) { |
| 1170 | // Never pick a separator that causes confusion with "limit" |
| 1171 | start.CopyToString(separator); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | int SafeSnprintf(char *str, size_t size, const char *format, ...) { |
| 1176 | va_list printargs; |
nothing calls this directly
no test coverage detected