stdlib/strings: Access iterator through its position constructor.
[nit.git] / lib / standard / string.nit
index f080e2a..524d4d4 100644 (file)
@@ -378,6 +378,10 @@ abstract class StringCharView
 
        redef fun length do return target.length
 
+       redef fun iterator: IndexedIterator[Char] do return self.iterator_from(0)
+
+       fun iterator_from(pos: Int): IndexedIterator[Char] is abstract
+
        redef fun has(c: Char): Bool
        do
                for i in self do
@@ -747,7 +751,7 @@ private class FlatStringCharView
                return target._items[index + target._index_from]
        end
 
-       redef fun iterator: IndexedIterator[Char] do return new FlatStringIterator.with_pos(target, 0)
+       redef fun iterator_from(start) do return new FlatStringIterator.with_pos(target, start)
 
 end
 
@@ -918,7 +922,7 @@ private class FlatBufferCharView
                if target.capacity < s.length then enlarge(s_length + target.length)
        end
 
-       redef fun iterator: IndexedIterator[Char] do return new FlatBufferIterator.with_pos(target, 0)
+       redef fun iterator_from(pos) do return new FlatBufferIterator.with_pos(target, pos)
 
 end
 
@@ -1051,7 +1055,7 @@ redef class Float
        # Pretty print self, print needoed decimals up to a max of 3.
        redef fun to_s do
                var str = to_precision( 3 )
-               if is_inf != 0 then return str
+               if is_inf != 0 or is_nan then return str
                var len = str.length
                for i in [0..len-1] do
                        var j = len-1-i
@@ -1070,6 +1074,8 @@ redef class Float
        # `self` representation with `nb` digits after the '.'.
        fun to_precision(nb: Int): String
        do
+               if is_nan then return "nan"
+
                var isinf = self.is_inf
                if isinf == 1 then
                        return "inf"