aboutsummaryrefslogtreecommitdiff
path: root/files.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-22 14:56:12 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-22 14:56:39 -0700
commit0fe94570b5c33e01472f61fcd564809f93e1b08a (patch)
treea9260bc99bdc8acdc3d3ee3a01753c870ebbe9d2 /files.moon
parentdfd39f0b14794b360fd6c961c65ab45d229e00b1 (diff)
Better handling of invalid line numbers (returning nil instead of random
garbage).
Diffstat (limited to 'files.moon')
-rw-r--r--files.moon6
1 files changed, 5 insertions, 1 deletions
diff --git a/files.moon b/files.moon
index 7f23490..bdf95e3 100644
--- a/files.moon
+++ b/files.moon
@@ -143,7 +143,11 @@ Files.get_line_number = (str, pos)->
Files.get_line = (str, line_no)->
line_starts = Files.get_line_starts(str)
- return str\sub(line_starts[line_no] or 1, (line_starts[line_no+1] or 1) - 2)
+ start = line_starts[line_no]
+ return unless start
+ stop = line_starts[line_no+1]
+ return unless stop
+ return str\sub(start, stop - 2)
get_lines = re.compile([[
lines <- {| line (%nl line)* |}