Allow <= and >= as overloadable operators and add in a string <= function (though some refactoring to do <, >, and => would be good) and a sorted to vec

This commit is contained in:
Nathan Braswell
2018-12-06 04:39:40 +00:00
parent d2011640f7
commit caafc6f4e4
3 changed files with 41 additions and 1 deletions

View File

@@ -206,6 +206,23 @@ obj str (Object, Serializable, Hashable) {
var str.construct(other) : str
return *this == str
}
fun operator<=(other: ref str): bool {
var l = 0
var r = 0
while (l < length() || r < other.length()) {
if l == length() {
return true
} else if r == other.length() {
return false
} else if (*this)[l] < other[r] {
return true
} else if (*this)[l] > other[r] {
return false
}
l++
r++
}
}
fun operator*(n: int): str {
var to_ret.construct(): str