summaryrefslogtreecommitdiff
path: root/lib/string.fnl
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-10-15 14:48:16 +0600
committerunwox <me@unwox.com>2024-10-15 14:49:36 +0600
commit1204496efa2fcd495bd74ba8ca249b7f082f3ba5 (patch)
tree57f908c7bae9ff1194ccb68328ec59ef5be00872 /lib/string.fnl
parent1520d83acccdcad2d7f87aec073b48d5f4995bf6 (diff)
WIP try to fix spelling mistakes in search querie
currently works very slowly and uses a lot of CPU
Diffstat (limited to 'lib/string.fnl')
-rw-r--r--lib/string.fnl29
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/string.fnl b/lib/string.fnl
index 9ac6edd..ca29da0 100644
--- a/lib/string.fnl
+++ b/lib/string.fnl
@@ -1,12 +1,25 @@
-(fn split [string]
- (accumulate [res [] v _
- (string:gmatch "%S+")]
+(local {: must} (require :lib.utils))
+
+(fn empty? [str]
+ (or (= str nil) (= (# str) 0)))
+
+(fn letters [str]
+ (assert
+ (= "string" (type str))
+ (string.format "letters(): str must be string, %s given" (type str)))
+ (var result [])
+ (for [i 1 (must (luna.utf.len str))]
+ (table.insert result (must (luna.utf.sub str i 1))))
+ result)
+
+(fn split [str]
+ (accumulate [res [] v _ (str:gmatch "%S+")]
(do
(table.insert res v)
res)))
-(fn ends-with [string end]
- (= (string.sub string (- (# end))) end))
+(fn ends-with [str end]
+ (= (string.sub str (- (# end))) end))
(fn trim [str]
(str:match "^%s*(.-)%s*$"))
@@ -14,9 +27,9 @@
(fn truncate [str len ellipsis]
(if (and (= (type str) "string")
(< 0 (# str)))
- (if (< (# str) len)
+ (if (< (must (luna.utf.len str)) len)
str
- (.. (trim (luna.utf.sub str 1 len)) (or ellipsis "...")))
+ (.. (trim (must (luna.utf.sub str 1 len))) (or ellipsis "...")))
""))
-{: split : ends-with : trim : truncate}
+{: letters : empty? : split : ends-with : trim : truncate}