[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suggestion: strip indentation for long string constructor
- From: steve donovan <steve.j.donovan@...>
- Date: Sun, 16 Aug 2009 16:59:16 +0200
On Sun, Aug 16, 2009 at 12:33 PM, Stuart P.Bentley<stuart@testtrack4.com> wrote:
> [[
> This string starts with 6 spaces!
> And there's another six after that newline!
> Does that look right to you?]]
But it's not difficult to strip out initial indentation using pure Lua code:
For instance, pl.text.dedent:
--- dedent a multiline string by removing any initial indent.
-- useful when working with [[..]] strings.
-- @param s the string
-- @return a string with initial indent zero.
function dedent (s)
local sl = split(s,'\n')
local i1,i2 = sl[1]:find('^%s*')
sl = sl:mapn('sub',i2+1)
return sl:concat('\n')
end
steve d.