Skip to content

Commit

Permalink
builtin: cleanup compare_strings functions (#21255)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Apr 11, 2024
1 parent fa321ed commit 27cd1b1
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions vlib/builtin/string.v
Original file line number Diff line number Diff line change
Expand Up @@ -1785,24 +1785,20 @@ pub fn (s string) trim_string_right(str string) string {

// compare_strings returns `-1` if `a < b`, `1` if `a > b` else `0`.
pub fn compare_strings(a &string, b &string) int {
if a < b {
return -1
}
if a > b {
return 1
return match true {
a < b { -1 }
a > b { 1 }
else { 0 }
}
return 0
}

// compare_strings_by_len returns `-1` if `a.len < b.len`, `1` if `a.len > b.len` else `0`.
fn compare_strings_by_len(a &string, b &string) int {
if a.len < b.len {
return -1
}
if a.len > b.len {
return 1
return match true {
a.len < b.len { -1 }
a.len > b.len { 1 }
else { 0 }
}
return 0
}

// compare_lower_strings returns the same as compare_strings but converts `a` and `b` to lower case before comparing.
Expand Down

0 comments on commit 27cd1b1

Please sign in to comment.