summaryrefslogtreecommitdiff
path: root/lib/std/strfind.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-03-24 23:45:06 -0700
committerOri Bernstein <ori@eigenstate.org>2018-03-24 23:45:06 -0700
commit8da5ac5ac4258588634453d55cec95f29a02647b (patch)
tree75fd88bc74686846d10ac7681198231fb181e835 /lib/std/strfind.myr
parent56c70bd6049b8eb88c7b7ab3636d6c1761fa0008 (diff)
downloadmc-8da5ac5ac4258588634453d55cec95f29a02647b.tar.gz
Clean up and remove edge cases in strfind.
Diffstat (limited to 'lib/std/strfind.myr')
-rw-r--r--lib/std/strfind.myr26
1 files changed, 9 insertions, 17 deletions
diff --git a/lib/std/strfind.myr b/lib/std/strfind.myr
index a874ea4..f446f69 100644
--- a/lib/std/strfind.myr
+++ b/lib/std/strfind.myr
@@ -8,22 +8,16 @@ pkg std =
;;
const strfind = {haystack, needle
- -> strfindin(haystack, needle, 0, haystack.len)
+ -> strfindin(haystack, needle, 0, haystack.len, 1)
}
const strrfind = {haystack, needle
- -> strfindin(haystack, needle, haystack.len - 1, -1)
+ -> strfindin(haystack, needle, haystack.len - 1, -1, -1)
}
-const strfindin = {haystack, needle, start, end
- var inc : size
-
- inc = 1
- if start > end
- inc = -1
- ;;
- if needle.len == 0
- -> `None
+const strfindin = {haystack, needle, start, end, inc
+ if haystack.len == 0 && needle.len == 0
+ -> `std.Some 0
;;
for var i = start; i != end; i += inc
/*
@@ -33,14 +27,12 @@ const strfindin = {haystack, needle, start, end
if i + needle.len > haystack.len
continue
;;
- if haystack[i] == needle[0]
- for var j = 0; j < needle.len; j++
- if haystack[i + j] != needle[j]
- goto nextiter
- ;;
+ for var j = 0; j < needle.len; j++
+ if haystack[i + j] != needle[j]
+ goto nextiter
;;
- -> `Some i
;;
+ -> `Some i
:nextiter
;;
-> `None