From 8f7c9586e4d255914e208e1271e7f5617d4b938a Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 28 Feb 2014 15:16:33 -0500 Subject: [PATCH] stdlib/strings: Moved Substring to Buffer since it was in no way similar to the String implementation. Signed-off-by: Lucas Bajolet --- lib/standard/string.nit | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/standard/string.nit b/lib/standard/string.nit index f33bc0b..4b6602a 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -48,23 +48,7 @@ abstract class AbstractString # A `from` index < 0 will be replaced by 0. # Unless a `count` value is > 0 at the same time. # In this case, `from += count` and `count -= from`. - fun substring(from: Int, count: Int): String - do - assert count >= 0 - count += from - if from < 0 then from = 0 - if count > length then count = length - if from < count then - var r = new Buffer.with_capacity(count - from) - while from < count do - r.chars.push(_items[from]) - from += 1 - end - return r.to_s - else - return "" - end - end + fun substring(from: Int, count: Int): String is abstract # Create a substring from `self` beginning at the `from` position # @@ -942,6 +926,25 @@ class Buffer end readable private var _capacity: Int + + redef fun substring(from, count) + do + assert count >= 0 + count += from + if from < 0 then from = 0 + if count > length then count = length + if from < count then + var r = new Buffer.with_capacity(count - from) + while from < count do + r.chars.push(_items[from]) + from += 1 + end + return r.to_s + else + return "" + end + end + end private class FlatBufferReverseIterator -- 1.7.9.5