mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fix string comparison functions
This commit is contained in:
committed by
Alex Medvednikov
parent
57466f7960
commit
00594462c4
@@ -169,37 +169,35 @@ fn (s string) ne(a string) bool {
|
||||
return !s.eq(a)
|
||||
}
|
||||
|
||||
// s >= a
|
||||
fn (s string) ge(a string) bool {
|
||||
mut j := 0
|
||||
// s < a
|
||||
fn (s string) lt(a string) bool {
|
||||
for i := 0; i < s.len; i++ {
|
||||
if i >= a.len {
|
||||
return true
|
||||
}
|
||||
if int(s[i]) < int(a[j]) {
|
||||
if i >= a.len || s[i] > a[i] {
|
||||
return false
|
||||
}
|
||||
else if int(s[i]) > int(a[j]) {
|
||||
else if s[i] < a[i] {
|
||||
return true
|
||||
}
|
||||
j++
|
||||
}
|
||||
return true
|
||||
if s.len < a.len {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// s <= a
|
||||
fn (s string) le(a string) bool {
|
||||
return !s.ge(a) || s == a
|
||||
}
|
||||
|
||||
// s < a
|
||||
fn (s string) lt(a string) bool {
|
||||
return s.le(a) && s != a
|
||||
return s.lt(a) || s.eq(a)
|
||||
}
|
||||
|
||||
// s > a
|
||||
fn (s string) gt(a string) bool {
|
||||
return s.ge(a) && s != a
|
||||
return !s.le(a)
|
||||
}
|
||||
|
||||
// s >= a
|
||||
fn (s string) ge(a string) bool {
|
||||
return !s.lt(a)
|
||||
}
|
||||
|
||||
// TODO `fn (s string) + (a string)` ? To be consistent with operator overloading syntax.
|
||||
|
||||
Reference in New Issue
Block a user