blueloveTH 2023-12-01 10:42:42 +08:00
parent 74e31b36ed
commit 9e66bab34b
2 changed files with 15 additions and 2 deletions

View File

@ -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);

View File

@ -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){