Skip to content

stringx indent and dedent functions add an extra "\n" at the end of the string #446

Open
@Aire-One

Description

Hello,

The indent and dedent functions both add a final "\n" sequence at the end of the string.

Code reference of the indent function:

Penlight/lua/pl/stringx.lua

Lines 500 to 514 in b101290

--- indent a multiline string.
-- @tparam string s the (multiline) string
-- @tparam integer n the size of the indent
-- @tparam[opt=' '] string ch the character to use when indenting
-- @return indented string
function stringx.indent (s,n,ch)
assert_arg(1,s,'string')
assert_arg(2,n,'number')
local lines = usplit(s ,'\n')
local prefix = string.rep(ch or ' ',n)
for i, line in ipairs(lines) do
lines[i] = prefix..line
end
return concat(lines,'\n')..'\n'
end

I think this extra "\n" sequence shouldn't be here. It's not part of the functions documentations and is (at least in my use case) unwanted.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions