minor string_eq fix

This commit is contained in:
able 2024-01-23 04:32:00 -06:00
parent b025e301bb
commit 4b2691fa57
2 changed files with 18 additions and 5 deletions

2
TODO
View file

@ -1,4 +1,4 @@
- [ ] Fix string_eq - [x] Fix string_eq
- [ ] Move function signatures to the *.h file - [ ] Move function signatures to the *.h file
- [ ] Sorting stuff - [ ] Sorting stuff
- [x] Random Libraries - [x] Random Libraries

View file

@ -19,12 +19,25 @@ String from_c_str(char* ptr) {
}; };
} }
// String equality tests for length/contents
// If the contents and length are the same then it is true else its false
bool string_eq(String lhs, String rhs) { bool string_eq(String lhs, String rhs) {
bool same_contents = false;
bool same_ptr = false;
bool same_len = false;
if (lhs.ptr == rhs.ptr) { if (lhs.ptr == rhs.ptr) {
same_ptr = true;
}
if (lhs.len == rhs.len) { if (lhs.len == rhs.len) {
same_len = true;
}
if (same_len && same_ptr){
return true; return true;
} } else {
// TODO: still check the contents instead of just unconditionally falsing
return false; return false;
} }
return false;
} }