mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
some fix
This commit is contained in:
parent
874d3a0b88
commit
1c9bd1836c
@ -56,8 +56,8 @@ int pkpy_Str__unicode_index_to_byte(const pkpy_Str* self, int i);
|
|||||||
int pkpy_Str__byte_index_to_unicode(const pkpy_Str* self, int n);
|
int pkpy_Str__byte_index_to_unicode(const pkpy_Str* self, int n);
|
||||||
int pkpy_Str__index(const pkpy_Str* self, const pkpy_Str* sub, int start);
|
int pkpy_Str__index(const pkpy_Str* self, const pkpy_Str* sub, int start);
|
||||||
int pkpy_Str__count(const pkpy_Str* self, const pkpy_Str* sub);
|
int pkpy_Str__count(const pkpy_Str* self, const pkpy_Str* sub);
|
||||||
c11_array/* T=c11_string */ pkpy_Str__split(const pkpy_Str* self, char sep);
|
c11_vector/* T=c11_string */ pkpy_Str__split(const pkpy_Str* self, char sep);
|
||||||
c11_array/* T=c11_string */ pkpy_Str__split2(const pkpy_Str* self, const pkpy_Str* sep);
|
c11_vector/* T=c11_string */ pkpy_Str__split2(const pkpy_Str* self, const pkpy_Str* sep);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -192,24 +192,24 @@ struct Str: pkpy_Str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vector<std::string_view> split(const Str& sep) const{
|
vector<std::string_view> split(const Str& sep) const{
|
||||||
c11_array/* T=c11_string */ res = pkpy_Str__split2(this, &sep);
|
c11_vector/* T=c11_string */ res = pkpy_Str__split2(this, &sep);
|
||||||
vector<std::string_view> retval(res.count);
|
vector<std::string_view> retval(res.count);
|
||||||
for(int i = 0; i < res.count; i++){
|
for(int i = 0; i < res.count; i++){
|
||||||
c11_string tmp = c11__getitem(c11_string, &res, i);
|
c11_string tmp = c11__getitem(c11_string, &res, i);
|
||||||
retval[i] = std::string_view(tmp.data, tmp.size);
|
retval[i] = std::string_view(tmp.data, tmp.size);
|
||||||
}
|
}
|
||||||
c11_array__dtor(&res);
|
c11_vector__dtor(&res);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<std::string_view> split(char sep) const{
|
vector<std::string_view> split(char sep) const{
|
||||||
c11_array/* T=c11_string */ res = pkpy_Str__split(this, sep);
|
c11_vector/* T=c11_string */ res = pkpy_Str__split(this, sep);
|
||||||
vector<std::string_view> retval(res.count);
|
vector<std::string_view> retval(res.count);
|
||||||
for(int i = 0; i < res.count; i++){
|
for(int i = 0; i < res.count; i++){
|
||||||
c11_string tmp = c11__getitem(c11_string, &res, i);
|
c11_string tmp = c11__getitem(c11_string, &res, i);
|
||||||
retval[i] = std::string_view(tmp.data, tmp.size);
|
retval[i] = std::string_view(tmp.data, tmp.size);
|
||||||
}
|
}
|
||||||
c11_array__dtor(&res);
|
c11_vector__dtor(&res);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ void c11_vector__dtor(c11_vector* self);
|
|||||||
c11_vector c11_vector__copy(const c11_vector* self);
|
c11_vector c11_vector__copy(const c11_vector* self);
|
||||||
void* c11_vector__at(c11_vector* self, int index);
|
void* c11_vector__at(c11_vector* self, int index);
|
||||||
void c11_vector__reserve(c11_vector* self, int capacity);
|
void c11_vector__reserve(c11_vector* self, int capacity);
|
||||||
c11_array c11_vector__as_array(c11_vector* self);
|
|
||||||
|
|
||||||
#define c11__getitem(T, self, index) ((T*)(self)->data)[index]
|
#define c11__getitem(T, self, index) ((T*)(self)->data)[index]
|
||||||
#define c11__setitem(T, self, index, value) ((T*)(self)->data)[index] = value;
|
#define c11__setitem(T, self, index, value) ((T*)(self)->data)[index] = value;
|
||||||
|
@ -351,7 +351,7 @@ int pkpy_Str__count(const pkpy_Str *self, const pkpy_Str *sub){
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
c11_array/* T=c11_string */ pkpy_Str__split(const pkpy_Str *self, char sep){
|
c11_vector/* T=c11_string */ pkpy_Str__split(const pkpy_Str *self, char sep){
|
||||||
c11_vector retval;
|
c11_vector retval;
|
||||||
c11_vector__ctor(&retval, sizeof(c11_string));
|
c11_vector__ctor(&retval, sizeof(c11_string));
|
||||||
const char* data = pkpy_Str__data(self);
|
const char* data = pkpy_Str__data(self);
|
||||||
@ -370,10 +370,10 @@ c11_array/* T=c11_string */ pkpy_Str__split(const pkpy_Str *self, char sep){
|
|||||||
c11_string tmp = {data + i, self->size - i};
|
c11_string tmp = {data + i, self->size - i};
|
||||||
c11_vector__push(c11_string, &retval, tmp);
|
c11_vector__push(c11_string, &retval, tmp);
|
||||||
}
|
}
|
||||||
return c11_vector__as_array(&retval);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
c11_array/* T=c11_string */ pkpy_Str__split2(const pkpy_Str *self, const pkpy_Str *sep){
|
c11_vector/* T=c11_string */ pkpy_Str__split2(const pkpy_Str *self, const pkpy_Str *sep){
|
||||||
c11_vector retval;
|
c11_vector retval;
|
||||||
c11_vector__ctor(&retval, sizeof(c11_string));
|
c11_vector__ctor(&retval, sizeof(c11_string));
|
||||||
int start = 0;
|
int start = 0;
|
||||||
@ -387,5 +387,5 @@ c11_array/* T=c11_string */ pkpy_Str__split2(const pkpy_Str *self, const pkpy_St
|
|||||||
}
|
}
|
||||||
c11_string tmp = {data + start, self->size - start};
|
c11_string tmp = {data + start, self->size - start};
|
||||||
if(tmp.size != 0) c11_vector__push(c11_string, &retval, tmp);
|
if(tmp.size != 0) c11_vector__push(c11_string, &retval, tmp);
|
||||||
return c11_vector__as_array(&retval);
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,3 @@ void c11_vector__reserve(c11_vector* self, int capacity){
|
|||||||
self->data = realloc(self->data, self->elem_size * self->capacity);
|
self->data = realloc(self->data, self->elem_size * self->capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
c11_array c11_vector__as_array(c11_vector* self){
|
|
||||||
c11_array retval = {
|
|
||||||
.data = self->data,
|
|
||||||
.count = self->count,
|
|
||||||
.elem_size = self->elem_size,
|
|
||||||
};
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user