mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-09 21:20:17 +00:00
when a negative start index is passed to str.find, 0 is used instead
This commit is contained in:
parent
4b10090f70
commit
d33f966b05
@ -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;
|
||||
|
||||
@ -242,4 +242,5 @@ except ValueError:
|
||||
|
||||
assert a.find('1') == 0
|
||||
assert a.find('1', 1) == -1
|
||||
assert a.find('1', -1000000) == 0
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user