mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
add PK_SLICE_LOOP
This commit is contained in:
parent
3534492bb6
commit
38dceac61b
@ -234,4 +234,6 @@ inline const char* kPlatformStrings[] = {
|
||||
"unknown" // 6
|
||||
};
|
||||
|
||||
#define PK_SLICE_LOOP(i, start, stop, step) for(int i=start; step>0?i<stop:i>stop; i+=step)
|
||||
|
||||
} // namespace pkpy
|
||||
|
@ -20,7 +20,7 @@ PyObject* PyArrayGetItem(VM* vm, PyObject* _0, PyObject* _1){
|
||||
int start, stop, step;
|
||||
vm->parse_int_slice(s, self.size(), start, stop, step);
|
||||
List new_list;
|
||||
for(int i=start; step>0?i<stop:i>stop; i+=step) new_list.push_back(self[i]);
|
||||
PK_SLICE_LOOP(i, start, stop, step) new_list.push_back(self[i]);
|
||||
return VAR(T(std::move(new_list)));
|
||||
}
|
||||
vm->TypeError("indices must be integers or slices");
|
||||
|
@ -334,9 +334,9 @@ int utf8len(unsigned char c, bool suppress){
|
||||
Str Str::u8_slice(int start, int stop, int step) const{
|
||||
SStream ss;
|
||||
if(is_ascii){
|
||||
for(int i=start; step>0?i<stop:i>stop; i+=step) ss << data[i];
|
||||
PK_SLICE_LOOP(i, start, stop, step) ss << data[i];
|
||||
}else{
|
||||
for(int i=start; step>0?i<stop:i>stop; i+=step) ss << u8_getitem(i);
|
||||
PK_SLICE_LOOP(i, start, stop, step) ss << u8_getitem(i);
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user