when a negative start index is passed to str.find, 0 is used instead

This commit is contained in:
albertexye 2024-04-01 14:36:18 -04:00
parent 4b10090f70
commit d33f966b05
2 changed files with 2 additions and 1 deletions

View File

@ -266,7 +266,7 @@ int utf8len(unsigned char c, bool suppress){
}
int Str::index(const Str& sub, int start) const {
if (start < 0 || start >= this->u8_length()) return -1;
if (start < 0) start = 0;
auto p = std::search(data + start, data + size, sub.data, sub.data + sub.size);
if(p == data + size) return -1;
return p - data;

View File

@ -242,4 +242,5 @@ except ValueError:
assert a.find('1') == 0
assert a.find('1', 1) == -1
assert a.find('1', -1000000) == 0