1

Text stripping

This commit is contained in:
Alex Yatskov 2024-05-02 18:10:16 -07:00
parent ca45fc2fdb
commit 75cc3a3cb5

View File

@ -255,7 +255,7 @@ function Param:slice(start, stop)
local text = ''
local cursors = {}
for i = start,stop do
for i = start, stop do
text = text .. self.text:sub(i, i)
table.insert(cursors, self.cursors[i])
end
@ -275,6 +275,22 @@ function Param:strip()
self:slice(1, #self.text - #self.text:match('%s*$'))
self:slice(1 + #self.text:match('^%s*'), #self.text)
local text = ''
local cursors = {}
for i = 1, #self.text do
local char = self.text:sub(i, i)
local cursor = self.cursors[i]
if cursor:is_literal() or not char:match('%s') or not text:match('%s$') then
text = text .. char
table.insert(cursors, cursor)
end
end
self.text = text
self.cursors = cursors
return #self.text > 0
end