File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,12 @@ uniquify = function(list)
167167 end )()
168168end
169169trim = 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
171176end
172177trim_all = function (tbl )
173178 for k , v in pairs (tbl ) do
Original file line number Diff line number Diff 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
107113trim_all = ( tbl) ->
108114 for k, v in pairs tbl
Original file line number Diff line number Diff line change @@ -249,6 +249,11 @@ tests = {
249249 " blah blah"
250250 }
251251
252+ {
253+ -> util. trim " hello#{" " \r ep 20000}world "
254+ " hello#{" " \r ep 20000}world"
255+ }
256+
252257 {
253258 -> util. trim_filter {
254259 " " , " thing " ,
You can’t perform that action at this time.
0 commit comments