mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
This commit is contained in:
parent
74e31b36ed
commit
9e66bab34b
@ -26,6 +26,7 @@ struct Str{
|
||||
Str(std::nullptr_t) { FATAL_ERROR(); }
|
||||
Str(const char* s);
|
||||
Str(const char* s, int len);
|
||||
Str(std::pair<char *, int>);
|
||||
Str(const Str& other);
|
||||
Str(Str&& other);
|
||||
|
||||
|
16
src/str.cpp
16
src/str.cpp
@ -42,6 +42,19 @@ int utf8len(unsigned char c, bool suppress){
|
||||
|
||||
#undef STR_INIT
|
||||
|
||||
Str::Str(std::pair<char *, int> detached) {
|
||||
this->size = detached.second;
|
||||
this->data = detached.first;
|
||||
this->is_ascii = true;
|
||||
// check is_ascii
|
||||
for(int i=0; i<size; i++){
|
||||
if(!isascii(data[i])){
|
||||
is_ascii = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Str::Str(const Str& other): size(other.size), is_ascii(other.is_ascii) {
|
||||
_alloc();
|
||||
memcpy(data, other.data, size);
|
||||
@ -423,8 +436,7 @@ int utf8len(unsigned char c, bool suppress){
|
||||
|
||||
Str SStream::str(){
|
||||
// after this call, the buffer is no longer valid
|
||||
auto detached = buffer.detach();
|
||||
return Str(detached.first, detached.second);
|
||||
return Str(buffer.detach());
|
||||
}
|
||||
|
||||
SStream& SStream::operator<<(const Str& s){
|
||||
|
Loading…
x
Reference in New Issue
Block a user