mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
ab35605ae7
commit
a0bc51ab94
25
src/str.cpp
25
src/str.cpp
@ -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(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user