| 159 | } |
| 160 | |
| 161 | string string::substr(fl::size start, fl::size length) const FL_NOEXCEPT { |
| 162 | // Handle `npos` / overflow: when `length == npos` the caller |
| 163 | // means "to end of string", and when `length` is large enough |
| 164 | // that `start + length` would wrap, we clamp to the end before |
| 165 | // the addition can overflow. |
| 166 | fl::size end; |
| 167 | if (length == npos || length > size() - (start < size() ? start : size())) { |
| 168 | end = size(); |
| 169 | } else { |
| 170 | end = start + length; |
| 171 | if (end > size()) end = size(); |
| 172 | } |
| 173 | return substring(start, end); |
| 174 | } |
| 175 | |
| 176 | string string::substr(fl::size start) const FL_NOEXCEPT { |
| 177 | return substring(start, size()); |