summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-10-16 22:40:09 +0600
committerunwox <me@unwox.com>2024-10-16 22:43:17 +0600
commitfd9a559475ac6bff7c82594dc313d762ab807592 (patch)
tree5ae19da434713cb31fe9747a2f713eb3506936f9 /lib
parentc760c798a56fb80c891f26ca932e7d182da67069 (diff)
improve site structure for seo
Diffstat (limited to 'lib')
-rw-r--r--lib/string.fnl19
1 files changed, 15 insertions, 4 deletions
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))