From fd9a559475ac6bff7c82594dc313d762ab807592 Mon Sep 17 00:00:00 2001 From: unwox Date: Wed, 16 Oct 2024 22:40:09 +0600 Subject: improve site structure for seo --- lib/string.fnl | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/string.fnl') diff --git a/lib/string.fnl b/lib/string.fnl index 1696a64..6538827 100644 --- a/lib/string.fnl +++ b/lib/string.fnl @@ -12,11 +12,22 @@ (table.insert result (must (luna.utf8.sub str i 1)))) result) -(fn split [str] - (accumulate [res [] v _ (str:gmatch "%S+")] +(fn split [str delimiter] + (if (empty? str) + [] (do - (table.insert res v) - res))) + (local result {}) + (local len (# str)) + (var cursor 1) + (var (start end) (str:find delimiter)) + (while start + (when (< cursor start) + (table.insert result (str:sub cursor (- start 1)))) + (set cursor (+ end 1)) + (set (start end) (str:find delimiter cursor))) + (when (<= cursor len) + (table.insert result (str:sub cursor len))) + result))) (fn ends-with [str end] (= (string.sub str (- (# end))) end)) -- cgit v1.2.3