aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-02 15:10:17 -0700
committerBruce Hill <bruce@bruce-hill.com>2018-11-02 15:10:22 -0700
commitdc41f30c73c9686685e3a4183c1213fb4ba55c90 (patch)
tree279ca7da2de0efe2f363684f3c84a540635f11a8
parent307dea18815ba4a06a3098edb170d7ad90708815 (diff)
Tweak
-rw-r--r--string2.lua3
-rw-r--r--string2.moon1
2 files changed, 4 insertions, 0 deletions
diff --git a/string2.lua b/string2.lua
index cf86026..09cb5ea 100644
--- a/string2.lua
+++ b/string2.lua
@@ -81,6 +81,9 @@ local string2 = {
starts_with = function(self, s)
return sub(self, 1, #s) == s
end,
+ ends_with = function(self, s)
+ return #self >= #s and sub(self, #self - #s, -1) == s
+ end,
lines = function(self)
local _accum_0 = { }
local _len_0 = 1
diff --git a/string2.moon b/string2.moon
index e4ee482..e6db628 100644
--- a/string2.moon
+++ b/string2.moon
@@ -27,6 +27,7 @@ string2 = {
byte: byte, bytes: (i, j)=> {byte(@, i or 1, j or -1)}
split: (sep)=> [chunk for i,chunk in isplit(@, sep)]
starts_with: (s)=> sub(@, 1, #s) == s
+ ends_with: (s)=> #@ >= #s and sub(@, #@-#s, -1) == s
lines: => [line for i,line in isplit(@, '\n')]
line: (line_num)=>
for i, line, start in isplit(@, '\n')