builtin: remove former string operator methods (#10184)

pull/10186/head^2
Enzo 2021-05-24 13:05:29 +02:00 committed by GitHub
parent db848ed314
commit ce7f78522d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 42 deletions

View File

@ -495,9 +495,8 @@ pub fn (s string) u64() u64 {
return strconv.common_parse_uint(s, 0, 64, false, false) return strconv.common_parse_uint(s, 0, 64, false, false)
} }
// eq implements the `s == a` (equal) operator.
[direct_array_access] [direct_array_access]
fn (s string) eq(a string) bool { fn (s string) == (a string) bool {
if s.str == 0 { if s.str == 0 {
// should never happen // should never happen
panic('string.eq(): nil string') panic('string.eq(): nil string')
@ -516,17 +515,7 @@ fn (s string) eq(a string) bool {
} }
} }
fn (s string) == (a string) bool { fn (s string) < (a string) bool {
return s.eq(a)
}
// ne implements the `s != a` (not equal) operator.
fn (s string) ne(a string) bool {
return !s.eq(a)
}
// lt implements the `s < a` (less than) operator.
fn (s string) lt(a string) bool {
for i in 0 .. s.len { for i in 0 .. s.len {
if i >= a.len || s[i] > a[i] { if i >= a.len || s[i] > a[i] {
return false return false
@ -540,27 +529,7 @@ fn (s string) lt(a string) bool {
return false return false
} }
fn (s string) < (a string) bool { fn (s string) + (a string) string {
return s.lt(a)
}
// le implements the `s <= a` (less than or equal to) operator.
fn (s string) le(a string) bool {
return s.lt(a) || s.eq(a)
}
// gt implements the `s > a` (greater than) operator.
fn (s string) gt(a string) bool {
return !s.le(a)
}
// ge implements the `s >= a` (greater than or equal to) operator.
fn (s string) ge(a string) bool {
return !s.lt(a)
}
// add concatenates string with the string given in `s`.
fn (s string) add(a string) string {
new_len := a.len + s.len new_len := a.len + s.len
mut res := string{ mut res := string{
str: unsafe { malloc(new_len + 1) } str: unsafe { malloc(new_len + 1) }
@ -582,10 +551,6 @@ fn (s string) add(a string) string {
return res return res
} }
fn (s string) + (a string) string {
return s.add(a)
}
// split splits the string to an array by `delim`. // split splits the string to an array by `delim`.
// Example: assert 'A B C'.split(' ') == ['A','B','C'] // Example: assert 'A B C'.split(' ') == ['A','B','C']
// If `delim` is empty the string is split by it's characters. // If `delim` is empty the string is split by it's characters.
@ -1229,10 +1194,10 @@ pub fn (s string) trim_suffix(str string) string {
// compare_strings returns `-1` if `a < b`, `1` if `a > b` else `0`. // compare_strings returns `-1` if `a < b`, `1` if `a > b` else `0`.
pub fn compare_strings(a &string, b &string) int { pub fn compare_strings(a &string, b &string) int {
if a.lt(b) { if a < b {
return -1 return -1
} }
if a.gt(b) { if a > b {
return 1 return 1
} }
return 0 return 0
@ -1240,10 +1205,10 @@ pub fn compare_strings(a &string, b &string) int {
// compare_strings_reverse returns `1` if `a < b`, `-1` if `a > b` else `0`. // compare_strings_reverse returns `1` if `a < b`, `-1` if `a > b` else `0`.
fn compare_strings_reverse(a &string, b &string) int { fn compare_strings_reverse(a &string, b &string) int {
if a.lt(b) { if a < b {
return 1 return 1
} }
if a.gt(b) { if a > b {
return -1 return -1
} }
return 0 return 0