This commit is contained in:
blueloveTH 2023-07-26 01:15:15 +08:00
parent ab35605ae7
commit a0bc51ab94

View File

@ -64,12 +64,11 @@ int utf8len(unsigned char c, bool suppress){
} }
std::ostream& operator<<(std::ostream& os, const Str& str){ std::ostream& operator<<(std::ostream& os, const Str& str){
os.write(str.data, str.size); return os << str.sv();
return os;
} }
bool operator<(const std::string_view other, const Str& str){ bool operator<(const std::string_view other, const Str& str){
return str > other; return other < str.sv();
} }
void Str::_alloc(){ void Str::_alloc(){
@ -130,33 +129,23 @@ int utf8len(unsigned char c, bool suppress){
} }
bool Str::operator<(const Str& other) const { bool Str::operator<(const Str& other) const {
int ret = strncmp(data, other.data, std::min(size, other.size)); return this->sv() < other.sv();
if(ret != 0) return ret < 0;
return size < other.size;
} }
bool Str::operator<(const std::string_view other) const { bool Str::operator<(const std::string_view other) const {
int ret = strncmp(data, other.data(), std::min(size, (int)other.size())); return this->sv() < other;
if(ret != 0) return ret < 0;
return size < (int)other.size();
} }
bool Str::operator>(const Str& other) const { bool Str::operator>(const Str& other) const {
int ret = strncmp(data, other.data, std::min(size, other.size)); return this->sv() > other.sv();
if(ret != 0) return ret > 0;
return size > other.size;
} }
bool Str::operator<=(const Str& other) const { bool Str::operator<=(const Str& other) const {
int ret = strncmp(data, other.data, std::min(size, other.size)); return this->sv() <= other.sv();
if(ret != 0) return ret < 0;
return size <= other.size;
} }
bool Str::operator>=(const Str& other) const { bool Str::operator>=(const Str& other) const {
int ret = strncmp(data, other.data, std::min(size, other.size)); return this->sv() >= other.sv();
if(ret != 0) return ret > 0;
return size >= other.size;
} }
Str::~Str(){ Str::~Str(){