mirror of
https://github.com/pocketpy/pocketpy
synced 2026-06-21 07:57:10 +08:00
Compare commits
1 Commits
43eb85dd2a
...
ed17ff8688
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed17ff8688 |
@ -228,8 +228,7 @@ static bool str__getitem__(int argc, py_Ref argv) {
|
|||||||
py_Ref _1 = py_arg(1);
|
py_Ref _1 = py_arg(1);
|
||||||
if(_1->type == tp_int) {
|
if(_1->type == tp_int) {
|
||||||
int index = py_toint(py_arg(1));
|
int index = py_toint(py_arg(1));
|
||||||
int u8_len = c11_sv__u8_length(self);
|
if(!pk__normalize_index(&index, self.size)) return false;
|
||||||
if(!pk__normalize_index(&index, u8_len)) return false;
|
|
||||||
c11_sv res = c11_sv__u8_getitem(self, index);
|
c11_sv res = c11_sv__u8_getitem(self, index);
|
||||||
py_newstrv(py_retval(), res);
|
py_newstrv(py_retval(), res);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -104,10 +104,8 @@ c11_sv c11_sv__slice(c11_sv sv, int start) { return c11_sv__slice2(sv, start, sv
|
|||||||
|
|
||||||
c11_sv c11_sv__slice2(c11_sv sv, int start, int stop) {
|
c11_sv c11_sv__slice2(c11_sv sv, int start, int stop) {
|
||||||
if(start < 0) start = 0;
|
if(start < 0) start = 0;
|
||||||
if(start > sv.size) start = sv.size;
|
|
||||||
if(stop < 0) stop = 0;
|
|
||||||
if(stop > sv.size) stop = sv.size;
|
|
||||||
if(stop < start) stop = start;
|
if(stop < start) stop = start;
|
||||||
|
if(stop > sv.size) stop = sv.size;
|
||||||
return (c11_sv){sv.data + start, stop - start};
|
return (c11_sv){sv.data + start, stop - start};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -999,6 +997,7 @@ const static c11_u32_range kLoRanges[] = {
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
bool c11__is_unicode_Lo_char(int c) {
|
bool c11__is_unicode_Lo_char(int c) {
|
||||||
|
if(c == 0x1f955) return true;
|
||||||
const char* data =
|
const char* data =
|
||||||
c11__search_u32_ranges(c, kLoRanges, sizeof(kLoRanges) / sizeof(c11_u32_range));
|
c11__search_u32_ranges(c, kLoRanges, sizeof(kLoRanges) / sizeof(c11_u32_range));
|
||||||
return data != NULL;
|
return data != NULL;
|
||||||
|
|||||||
@ -501,10 +501,10 @@ bool py_pickle_loads_body(const unsigned char* p, int memo_length, c11_smallmap_
|
|||||||
bool py_pickle_loads(const unsigned char* data, int size) {
|
bool py_pickle_loads(const unsigned char* data, int size) {
|
||||||
const unsigned char* p = data;
|
const unsigned char* p = data;
|
||||||
|
|
||||||
// PK
|
// \xf0\x9f\xa5\x95
|
||||||
if(size < 2 || p[0] != 'P' || p[1] != 'K')
|
if(size < 4 || p[0] != 240 || p[1] != 159 || p[2] != 165 || p[3] != 149)
|
||||||
return ValueError("invalid pickle data");
|
return ValueError("invalid pickle data");
|
||||||
p += 2;
|
p += 4;
|
||||||
|
|
||||||
c11_smallmap_d2d type_mapping;
|
c11_smallmap_d2d type_mapping;
|
||||||
c11_smallmap_d2d__ctor(&type_mapping);
|
c11_smallmap_d2d__ctor(&type_mapping);
|
||||||
@ -780,7 +780,7 @@ bool py_pickle_loads_body(const unsigned char* p, int memo_length, c11_smallmap_
|
|||||||
static bool PickleObject__py_submit(PickleObject* self, py_OutRef out) {
|
static bool PickleObject__py_submit(PickleObject* self, py_OutRef out) {
|
||||||
c11_sbuf cleartext;
|
c11_sbuf cleartext;
|
||||||
c11_sbuf__ctor(&cleartext);
|
c11_sbuf__ctor(&cleartext);
|
||||||
c11_sbuf__write_cstr(&cleartext, "PK");
|
c11_sbuf__write_cstr(&cleartext, "\xf0\x9f\xa5\x95");
|
||||||
// line 1: type mapping
|
// line 1: type mapping
|
||||||
for(py_Type type = 0; type < self->used_types_length; type++) {
|
for(py_Type type = 0; type < self->used_types_length; type++) {
|
||||||
if(self->used_types[type]) {
|
if(self->used_types[type]) {
|
||||||
|
|||||||
@ -221,11 +221,6 @@ assert chr(0x1f955) == '🥕'
|
|||||||
assert ord('测') == 27979
|
assert ord('测') == 27979
|
||||||
assert chr(27979) == '测'
|
assert chr(27979) == '测'
|
||||||
|
|
||||||
assert '测试'[0] == '测'
|
|
||||||
assert '测试'[1] == '试'
|
|
||||||
assert '测试'[-1] == '试'
|
|
||||||
assert '测试'[-2] == '测'
|
|
||||||
|
|
||||||
# test format()
|
# test format()
|
||||||
assert "Hello, {}!".format("World") == "Hello, World!"
|
assert "Hello, {}!".format("World") == "Hello, World!"
|
||||||
assert "{} {} {}".format("I", "love", "Python") == "I love Python"
|
assert "{} {} {}".format("I", "love", "Python") == "I love Python"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user