From 977bd47eabe438ca82e0f5f0c2c73adcaf25d85d Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 2 Sep 2014 16:25:07 -0400 Subject: [PATCH] lib/standard/string: reverse iterator fix on substring. Fixes #709 Signed-off-by: Lucas Bajolet --- lib/standard/string.nit | 4 ++-- tests/sav/test_r_trim.res | 1 + tests/test_r_trim.nit | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/sav/test_r_trim.res create mode 100644 tests/test_r_trim.nit diff --git a/lib/standard/string.nit b/lib/standard/string.nit index b57a3a5..70cf816 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -364,7 +364,7 @@ abstract class Text if iter.item.ascii > 32 then break iter.next end - if iter.index == length then return self.empty + if iter.index < 0 then return self.empty return self.substring(0, iter.index + 1) end @@ -1136,7 +1136,7 @@ private class FlatStringReverseIterator curr_pos = pos + tgt.index_from end - redef fun is_ok do return curr_pos >= 0 + redef fun is_ok do return curr_pos >= target.index_from redef fun item do return target_items[curr_pos] diff --git a/tests/sav/test_r_trim.res b/tests/sav/test_r_trim.res new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/sav/test_r_trim.res @@ -0,0 +1 @@ + diff --git a/tests/test_r_trim.nit b/tests/test_r_trim.nit new file mode 100644 index 0000000..4862f9e --- /dev/null +++ b/tests/test_r_trim.nit @@ -0,0 +1,15 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +print "\t\t\t".substring(1, 2).r_trim -- 1.7.9.5