lib/core: Fix substring in `ASCIIFlatString`
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 16 May 2016 19:59:03 +0000 (15:59 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 16 May 2016 19:59:03 +0000 (15:59 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/core/text/flat.nit

index b7e8e61..2fa0bcb 100644 (file)
@@ -666,15 +666,15 @@ private class ASCIIFlatString
        end
 
        redef fun substring(from, count) do
+               var ln = _length
+               if count <= 0 then return ""
+               if (count + from) > ln then count = ln - from
                if count <= 0 then return ""
-
                if from < 0 then
                        count += from
-                       if count < 0 then return ""
+                       if count <= 0 then return ""
                        from = 0
                end
-               var ln = _length
-               if (count + from) > ln then count = ln - from
                return new ASCIIFlatString.full_data(_items, count, from + _first_byte, count)
        end