summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/std/strfind.myr26
-rw-r--r--mbld/test.myr8
-rw-r--r--test/data/strfind-expected2
3 files changed, 12 insertions, 24 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
diff --git a/mbld/test.myr b/mbld/test.myr
index cc9a304..bf666fd 100644
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -124,11 +124,7 @@ const runtest = {b, n, targs, isbench, failed
const matchtest = {name, pat
match std.strfind(pat, ":")
- | `std.Some i: pat = pat[:i]
- | `std.None: /* ok */
- ;;
- match std.strfind(name, pat)
- | `std.Some _: -> true
- | `std.None: -> false
+ | `std.Some i: -> std.strhas(name, pat[:i])
+ | `std.None: -> std.strhas(name, pat)
;;
}
diff --git a/test/data/strfind-expected b/test/data/strfind-expected
index 04e7a1c..4e6ab82 100644
--- a/test/data/strfind-expected
+++ b/test/data/strfind-expected
@@ -1,4 +1,4 @@
-No match
+Found 0
No match
No match
Found 0