Skip to content

Commit

Permalink
Better doc, maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
NiLuJe committed Sep 30, 2020
1 parent 1da5270 commit 764e26f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions frontend/util.lua
Expand Up @@ -24,17 +24,17 @@ function util.stripPunctuation(text)
return text:gsub("\226[\128-\131][\128-\191]", ''):gsub("^%p+", ''):gsub("%p+$", '')
end

---- Various whitespace trimming helpers, from http://lua-users.org/wiki/CommonFunctions
-- Various whitespace trimming helpers, from http://lua-users.org/wiki/CommonFunctions & http://lua-users.org/wiki/StringTrim
---- Remove leading whitespace from string.
---- @string s the string to be trimmed
---- @treturn string trimmed text
-- remove leading whitespace from string.
-- http://en.wikipedia.org/wiki/Trim_(programming)
function util.ltrim(s)
return (s:gsub("^%s*", ""))
end

-- remove trailing whitespace from string.
-- http://en.wikipedia.org/wiki/Trim_(programming)
---- Remove trailing whitespace from string.
---- @string s the string to be trimmed
---- @treturn string trimmed text
function util.rtrim(s)
local n = #s
while n > 0 and s:find("^%s", n) do
Expand All @@ -43,7 +43,9 @@ function util.rtrim(s)
return s:sub(1, n)
end

-- c.f., http://lua-users.org/wiki/StringTrim
---- Remove leading & trailing whitespace from string.
---- @string s the string to be trimmed
---- @treturn string trimmed text
function util.trim(s)
local from = s:match"^%s*()"
return from > #s and "" or s:match(".*%S", from)
Expand Down

1 comment on commit 764e26f

@Frenzie
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good, hard to say without running ldoc to be sure though ;)

Please sign in to comment.