diff options
author | Marc-Antoine Ruel <[email protected]> | 2018-11-08 15:06:53 -0500 |
---|---|---|
committer | Marc-Antoine Ruel <[email protected]> | 2018-11-08 20:48:29 -0500 |
commit | b1cf69a523c81320b36392a16ef9f08ad0e004bc (patch) | |
tree | 6e902afea10bd7c9386055c43eea693b0103a3e9 /src/runtime/string.go | |
parent | 76d04990f4cb484ce46c2a6310f8918da2927383 (diff) | |
download | tinygo-b1cf69a523c81320b36392a16ef9f08ad0e004bc.tar.gz tinygo-b1cf69a523c81320b36392a16ef9f08ad0e004bc.zip |
compiler: implement binop string: <, <=, >, >=
Include unit tests.
Diffstat (limited to 'src/runtime/string.go')
-rw-r--r-- | src/runtime/string.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/runtime/string.go b/src/runtime/string.go index 540c6410f..f3e42df7e 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -32,6 +32,24 @@ func stringEqual(x, y string) bool { return true } +// Return true iff x < y. +//go:nobounds +func stringLess(x, y string) bool { + l := len(x) + if m := len(y); m < l { + l = m + } + for i := 0; i < l; i++ { + if x[i] < y[i] { + return true + } + if x[i] > y[i] { + return false + } + } + return len(x) < len(y) +} + // Add two strings together. func stringConcat(x, y _string) _string { if x.length == 0 { |