mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Use Rust Filename comparisons for C++ Filename operators
To prevent inconsistencies between implementations. This means allocating new boxed Filenames for each comparison, but an extra string copy is avoided by making the C++ operators friends of the C++ class (which is ABI-safe).
This commit is contained in:
@@ -35,7 +35,8 @@ Filename::Filename(std::string_view filename) : filename_(filename) {}
|
||||
Filename::operator std::string() const { return filename_; }
|
||||
|
||||
bool operator==(const Filename& lhs, const Filename& rhs) {
|
||||
return loot::rust::compare_filenames(std::string(lhs), std::string(rhs)) == 0;
|
||||
return loot::rust::new_filename(lhs.filename_)
|
||||
->eq(*loot::rust::new_filename(rhs.filename_));
|
||||
}
|
||||
|
||||
bool operator!=(const Filename& lhs, const Filename& rhs) {
|
||||
@@ -43,7 +44,8 @@ bool operator!=(const Filename& lhs, const Filename& rhs) {
|
||||
}
|
||||
|
||||
bool operator<(const Filename& lhs, const Filename& rhs) {
|
||||
return loot::rust::compare_filenames(std::string(lhs), std::string(rhs)) < 0;
|
||||
return loot::rust::new_filename(lhs.filename_)
|
||||
->lt(*loot::rust::new_filename(rhs.filename_));
|
||||
}
|
||||
|
||||
bool operator>(const Filename& lhs, const Filename& rhs) { return rhs < lhs; }
|
||||
|
||||
Reference in New Issue
Block a user