aboutsummaryrefslogtreecommitdiff
path: root/libs/regex.neb
diff options
context:
space:
mode:
authormryouse2022-07-15 00:55:27 +0000
committermryouse2022-07-15 00:55:27 +0000
commit91098f7f4e4a57d1163b3d8831d6e00548021b72 (patch)
treea74f28f8b56c62e3c209f4533ebc20907fa86353 /libs/regex.neb
parent55abb4a0ed18b7e1314ca72842caeaae9d21693b (diff)
refactor: use drop-while to short-circuit
Diffstat (limited to 'libs/regex.neb')
-rw-r--r--libs/regex.neb15
1 files changed, 6 insertions, 9 deletions
diff --git a/libs/regex.neb b/libs/regex.neb
index 928f739..8919232 100644
--- a/libs/regex.neb
+++ b/libs/regex.neb
@@ -38,14 +38,11 @@
(func .search (pattern text)
(if (eq? "^" (first-char pattern))
(.match-inner (rest-char pattern) text)
+ ;(.match-inner (concat ".*" pattern) text))) ; this is elegant but requires going through the entire string
(block
- (def progress text)
- (def out (list))
+ (def seed (list))
(for-count (length text)
- (redef out (append out (.match-inner pattern progress)))
- (redef progress (rest-char progress)))
- (or
- (eq? 0 (list-length out))
- (if (eq? 1 (list-length out))
- (first out)
- (apply or out))))))
+ (redef seed (append seed idx)))
+
+ (not (empty? (drop-while seed
+ (not (.match-inner pattern (join (slice (split text) _item_) "")))))))))