lib/standard/string: reverse iterator fix on substring. Fixes #709
authorLucas Bajolet <r4pass@hotmail.com>
Tue, 2 Sep 2014 20:25:07 +0000 (16:25 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Tue, 2 Sep 2014 20:25:07 +0000 (16:25 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/string.nit
tests/sav/test_r_trim.res [new file with mode: 0644]
tests/test_r_trim.nit [new file with mode: 0644]

index b57a3a5..70cf816 100644 (file)
@@ -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 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/tests/test_r_trim.nit b/tests/test_r_trim.nit
new file mode 100644 (file)
index 0000000..4862f9e
--- /dev/null
@@ -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