X Tutup
Skip to content

Commit 4a58f5c

Browse files
committed
1 parent 642041f commit 4a58f5c

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lapis/util.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ uniquify = function(list)
167167
end)()
168168
end
169169
trim = function(str)
170-
return tostring(str):match("^%s*(.-)%s*$")
170+
str = tostring(str)
171+
if #str > 200 then
172+
return str:gsub("^%s+", ""):reverse():gsub("^%s+", ""):reverse()
173+
else
174+
return str:match("^%s*(.-)%s*$")
175+
end
171176
end
172177
trim_all = function(tbl)
173178
for k, v in pairs(tbl) do

lapis/util.moon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ uniquify = (list) ->
102102
seen[item] = true
103103
item
104104

105-
trim = (str) -> tostring(str)\match "^%s*(.-)%s*$"
105+
trim = (str) ->
106+
str = tostring str
107+
108+
if #str > 200
109+
str\gsub("^%s+", "")\reverse()\gsub("^%s+", "")\reverse()
110+
else
111+
str\match "^%s*(.-)%s*$"
106112

107113
trim_all = (tbl) ->
108114
for k,v in pairs tbl

spec/util_spec.moon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ tests = {
249249
"blah blah"
250250
}
251251

252+
{
253+
-> util.trim " hello#{" "\rep 20000}world "
254+
"hello#{" "\rep 20000}world"
255+
}
256+
252257
{
253258
-> util.trim_filter {
254259
" ", " thing ",

0 commit comments

Comments
 (0)
X Tutup