mirror of
https://github.com/pocketpy/pocketpy
synced 2026-03-21 20:50:16 +00:00
fix #468
This commit is contained in:
parent
1d33267092
commit
35917fc5f4
@ -477,12 +477,14 @@ static bool str_rjust(int argc, py_Ref argv) { return str__widthjust_impl(false,
|
||||
|
||||
static bool str_find(int argc, py_Ref argv) {
|
||||
if(argc > 3) return TypeError("find() takes at most 3 arguments");
|
||||
c11_string* self = pk_tostr(&argv[0]);
|
||||
int start = 0;
|
||||
if(argc == 3) {
|
||||
PY_CHECK_ARG_TYPE(2, tp_int);
|
||||
start = py_toint(py_arg(2));
|
||||
if(start < 0) start += c11_sv__u8_length(c11_string__sv(self));
|
||||
if(start < 0) start = 0;
|
||||
}
|
||||
c11_string* self = pk_tostr(&argv[0]);
|
||||
PY_CHECK_ARG_TYPE(1, tp_str);
|
||||
c11_string* sub = pk_tostr(&argv[1]);
|
||||
int res = c11_sv__index2(c11_string__sv(self), c11_string__sv(sub), start);
|
||||
|
||||
@ -317,6 +317,8 @@ static bool list_index(int argc, py_Ref argv) {
|
||||
if(argc == 3) {
|
||||
PY_CHECK_ARG_TYPE(2, tp_int);
|
||||
start = py_toint(py_arg(2));
|
||||
if(start < 0) start += py_list_len(py_arg(0));
|
||||
if(start < 0) start = 0;
|
||||
}
|
||||
for(int i = start; i < py_list_len(py_arg(0)); i++) {
|
||||
int res = py_equal(py_list_getitem(py_arg(0), i), py_arg(1));
|
||||
|
||||
@ -169,6 +169,7 @@ assert a.index('23') == 1
|
||||
|
||||
assert a.index('2', 1) == 1
|
||||
assert a.index('1', 0) == 0
|
||||
assert a.index('2', -2) == 1
|
||||
|
||||
assert a.find('1') == 0
|
||||
assert a.find('1', 1) == -1
|
||||
|
||||
@ -75,6 +75,7 @@ assert a.index(3) == 2
|
||||
|
||||
assert a.index(2, 1) == 1
|
||||
assert a.index(1, 0) == 0
|
||||
assert a.index(2, -2) == 1
|
||||
|
||||
a, b = [1, 2]
|
||||
assert a == 1 and b == 2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user