Mercurial > repos > tabletprog
changeset 306:8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 27 Jul 2014 13:01:08 -0700 |
parents | 14b4e540af28 |
children | 056b8ad76559 |
files | modules/string.tp |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/modules/string.tp Sat Jul 26 15:02:01 2014 -0700 +++ b/modules/string.tp Sun Jul 27 13:01:08 2014 -0700 @@ -211,6 +211,12 @@ start <- bytes } clampedLen <- tocopy num + if: clampedLen < 0 { + clampedLen <- bytes - clampedLen + if: clampedLen < 0 { + clampedLen <- 0 + } + } if: start + clampedLen > bytes { clampedLen <- bytes - start } @@ -293,16 +299,16 @@ } do: { start <- start + 1 } - end <- l + end <- l - 1 while: { - if: end > 0 { - b <- byte: end - 1 + if: end > start { + b <- byte: end b = space || b = tab || b = nl || b = cr } } do: { end <- end - 1 } - from: start withLength: (end - start) + from: start withLength: (end + 1 - start) } startsWith? <- :prefix {