stdlib/strings: Removed usage of Strings as SequenceRead by using chars.
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 17 Feb 2014 15:39:26 +0000 (10:39 -0500)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 17 Feb 2014 15:39:26 +0000 (10:39 -0500)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

29 files changed:
examples/draw_operation.nit
lib/base64.nit
lib/bcm2835.nit
lib/mnit_linux/sdl.nit
lib/opts.nit
lib/standard/file.nit
lib/standard/stream.nit
lib/standard/string.nit
lib/standard/string_search.nit
src/debugger.nit
src/literal.nit
src/location.nit
src/markdown.nit
src/naive_interpreter.nit
src/network_debugger.nit
src/nitx.nit
src/parser/lexer.nit
src/parser/xss/lexer.xss
src/test_parser.nit
tests/base_string.nit
tests/bench_string_append.nit
tests/example_procedural_string.nit
tests/sav/test_parser_args1.res
tests/sav/test_parser_args2.res
tests/shootout_nsieve.nit
tests/test_string2.nit
tests/test_string_long.nit
tests/test_string_unicode.nit
tests/test_substring.nit

index 8ad92fc..cada831 100644 (file)
@@ -124,7 +124,7 @@ redef class String
                end
 
                var ci = 0
-               for c in self do
+               for c in self.chars do
                        var local_dispc
                        if c.override_dispc then
                                local_dispc = c
@@ -193,10 +193,10 @@ else
        b = gets.to_i
 
        printn "Operator (+, -, *, /, %): "
-       op_char = gets[0]
+       op_char = gets.chars[0]
 
        printn "Char to display: "
-       disp_char = gets[0]
+       disp_char = gets.chars[0]
 
        printn "Size of text: "
        disp_size = gets.to_i
index 861cb9a..9c57166 100644 (file)
@@ -28,7 +28,7 @@ redef class String
        do
                var inv_base64_chars = new HashMap[Char,Int]
                for k in [0..base64_chars.length[ do
-                       inv_base64_chars[ base64_chars[k] ] = k
+                       inv_base64_chars[ base64_chars.chars[k] ] = k
                end
                return inv_base64_chars
        end
@@ -52,23 +52,23 @@ redef class String
                for s in [0..steps[ do
                        var e = 0
                        for ss in [0..3[ do
-                               e += self[s*3+ss].ascii.lshift((2-ss)*8)
+                               e += self.chars[s*3+ss].ascii.lshift((2-ss)*8)
                        end
                        for ss in [0..4[ do
-                               result[s*4+3-ss] = base64_chars[ e.rshift(ss*6).bin_and( mask_6bit ) ]
+                               result[s*4+3-ss] = base64_chars.chars[ e.rshift(ss*6).bin_and( mask_6bit ) ]
                        end
                end
 
                if chars_in_last_step == 1 then
-                       var e = self[length-1].ascii.lshift(16)
+                       var e = self.chars[length-1].ascii.lshift(16)
                        for ss in [0..2[ do
-                               result[steps*4+1-ss] = base64_chars[ e.rshift((ss+2)*6).bin_and( mask_6bit ) ]
+                               result[steps*4+1-ss] = base64_chars.chars[ e.rshift((ss+2)*6).bin_and( mask_6bit ) ]
                        end
                else if chars_in_last_step == 2 then
-                       var e = self[length-2].ascii.lshift(16) +
-                               self[length-1].ascii.lshift(8)
+                       var e = self.chars[length-2].ascii.lshift(16) +
+                               self.chars[length-1].ascii.lshift(8)
                        for ss in [0..3[ do
-                               result[steps*4+2-ss] = base64_chars[ e.rshift((ss+1)*6).bin_and( mask_6bit ) ]
+                               result[steps*4+2-ss] = base64_chars.chars[ e.rshift((ss+1)*6).bin_and( mask_6bit ) ]
                        end
                end
 
@@ -104,7 +104,7 @@ redef class String
                for s in [0..steps[ do
                        var e = 0
                        for ss in [0..4[ do
-                               e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6)
+                               e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6)
                        end
 
                        for ss in [0..3[ do
@@ -116,7 +116,7 @@ redef class String
                if padding_count == 1 then
                        var e = 0
                        for ss in [0..3[ do
-                               e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6)
+                               e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6)
                        end
 
                        for ss in [0..2[ do
@@ -125,7 +125,7 @@ redef class String
                else if padding_count == 2 then
                        var e = 0
                        for ss in [0..2[ do
-                               e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6)
+                               e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6)
                        end
 
                        result[s*3] = e.rshift(2*8).bin_and( mask_8bit ).ascii
index 3557073..aac7352 100644 (file)
@@ -440,7 +440,7 @@ class HD44780
                clear
                return_home
                var count = 0
-               for c in v do
+               for c in v.chars do
                        if c == '\n' then
                                # FIXME, this should work
                                #write(true, "C0".to_hex)
index 55d4d07..f9497e4 100644 (file)
@@ -330,7 +330,7 @@ class SDLKeyEvent
 
        redef fun to_c: nullable Char
        do
-               if key_name.length == 1 then return key_name.first
+               if key_name.length == 1 then return key_name.chars.first
                return null
        end
 
index 1ac2326..ec3c006 100644 (file)
@@ -138,7 +138,7 @@ abstract class OptionParameter
        redef fun read_param(it)
        do
                super
-               if it.is_ok and it.item.first != '-' then
+               if it.is_ok and it.item.chars.first != '-' then
                        value = convert(it.item)
                        it.next
                else
@@ -273,7 +273,7 @@ class OptionContext
                                if str.last_index_of('-') == 0 and str.length > 2 then
                                        var next_called = false
                                        for i in [1..str.length] do
-                                               var short_opt = "-" + str[i].to_s
+                                               var short_opt = "-" + str.chars[i].to_s
                                                if _optmap.has_key(short_opt) then
                                                        var option = _optmap[short_opt]
                                                        if option isa OptionParameter then
index 239f785..978a489 100644 (file)
@@ -240,7 +240,7 @@ redef class String
        fun dirname: String
        do
                var l = _length - 1 # Index of the last char
-               if l > 0 and self[l] == '/' then l -= 1 # remove trailing `/`
+               if l > 0 and self.chars[l] == '/' then l -= 1 # remove trailing `/`
                var pos = last_index_of_from('/', l)
                if pos > 0 then
                        return substring(0, pos)
@@ -309,7 +309,7 @@ redef class String
        do
                if path.is_empty then return self
                if self.is_empty then return path
-               if path[0] == '/' then return path
+               if path.chars[0] == '/' then return path
                return "{self}/{path}"
        end
 
index c63e38a..eae8ef7 100644 (file)
@@ -70,7 +70,7 @@ interface IStream
                                if eof then return
                        else
                                var c = x.ascii
-                               s.push(c)
+                               s.chars.push(c)
                                if c == '\n' then return
                        end
                end
@@ -103,7 +103,7 @@ abstract class BufferedIStream
                if _buffer_pos >= _buffer.length then
                        return -1
                end
-               var c = _buffer[_buffer_pos]
+               var c = _buffer.chars[_buffer_pos]
                _buffer_pos += 1
                return c.ascii
        end
@@ -121,7 +121,7 @@ abstract class BufferedIStream
                                k = _buffer.length
                        end
                        while j < k and i > 0 do
-                               s.add(_buffer[j])
+                               s.add(_buffer.chars[j])
                                j +=  1
                                i -= 1
                        end
@@ -137,7 +137,7 @@ abstract class BufferedIStream
                        var j = _buffer_pos
                        var k = _buffer.length
                        while j < k do
-                               s.add(_buffer[j])
+                               s.add(_buffer.chars[j])
                                j += 1
                        end
                        _buffer_pos = j
@@ -151,7 +151,7 @@ abstract class BufferedIStream
                loop
                        # First phase: look for a '\n'
                        var i = _buffer_pos
-                       while i < _buffer.length and _buffer[i] != '\n' do i += 1
+                       while i < _buffer.length and _buffer.chars[i] != '\n' do i += 1
 
                        # if there is something to append
                        if i > _buffer_pos then
@@ -161,7 +161,7 @@ abstract class BufferedIStream
                                # Copy from the buffer to the string
                                var j = _buffer_pos
                                while j < i do
-                                       s.add(_buffer[j])
+                                       s.add(_buffer.chars[j])
                                        j += 1
                                end
                        end
index 810a9fd..42451d4 100644 (file)
@@ -56,7 +56,7 @@ abstract class AbstractString
                if from < count then
                        var r = new Buffer.with_capacity(count - from)
                        while from < count do
-                               r.push(_items[from])
+                               r.chars.push(_items[from])
                                from += 1
                        end
                        return r.to_s
@@ -144,7 +144,7 @@ abstract class AbstractString
                var i = 0
                var neg = false
 
-               for c in self
+               for c in self.chars
                do
                        var v = c.to_i
                        if v > base then
@@ -175,7 +175,7 @@ abstract class AbstractString
        fun is_numeric: Bool
        do
                var has_point_or_comma = false
-               for i in self
+               for i in self.chars
                do
                        if not i.is_numeric
                        then
@@ -196,7 +196,7 @@ abstract class AbstractString
        fun to_upper: String
        do
                var s = new Buffer.with_capacity(length)
-               for i in self do s.add(i.to_upper)
+               for i in self.chars do s.add(i.to_upper)
                return s.to_s
        end
 
@@ -206,7 +206,7 @@ abstract class AbstractString
        fun to_lower : String
        do
                var s = new Buffer.with_capacity(length)
-               for i in self do s.add(i.to_lower)
+               for i in self.chars do s.add(i.to_lower)
                return s.to_s
        end
 
@@ -217,18 +217,18 @@ abstract class AbstractString
        #     assert "\na\nb\tc\t".trim          == "a\nb\tc"
        fun trim: String
        do
-               if self._length == 0 then return self.to_s
+               if self.length == 0 then return self.to_s
                # find position of the first non white space char (ascii < 32) from the start of the string
                var start_pos = 0
-               while self[start_pos].ascii <= 32 do
+               while self.chars[start_pos].ascii <= 32 do
                        start_pos += 1
-                       if start_pos == _length then return ""
+                       if start_pos == length then return ""
                end
                # find position of the first non white space char from the end of the string
                var end_pos = length - 1
-               while self[end_pos].ascii <= 32 do
+               while self.chars[end_pos].ascii <= 32 do
                        end_pos -= 1
-                       if end_pos == start_pos then return self[start_pos].to_s
+                       if end_pos == start_pos then return self.chars[start_pos].to_s
                end
                return self.substring(start_pos, end_pos - start_pos + 1)
        end
@@ -247,7 +247,7 @@ abstract class AbstractString
        do
                var res = new Buffer
                var underscore = false
-               for c in self do
+               for c in self.chars do
                        if (c >= 'a' and c <= 'z') or (c >='A' and c <= 'Z') then
                                res.add(c)
                                underscore = false
@@ -280,7 +280,7 @@ abstract class AbstractString
        fun escape_to_c: String
        do
                var b = new Buffer
-               for c in self do
+               for c in self.chars do
                        if c == '\n' then
                                b.append("\\n")
                        else if c == '\0' then
@@ -819,8 +819,8 @@ class Buffer
                var l1 = length
                var l2 = s.length
                while i < l1 and i < l2 do
-                       var c1 = self[i].ascii
-                       var c2 = s[i].ascii
+                       var c1 = self.chars[i].ascii
+                       var c2 = s.chars[i].ascii
                        if c1 < c2 then
                                return true
                        else if c2 < c1 then
@@ -1010,9 +1010,9 @@ redef class Int
                # Sign
                if self < 0 then
                        n = - self
-                       s[0] = '-'
+                       s.chars[0] = '-'
                else if self == 0 then
-                       s[0] = '0'
+                       s.chars[0] = '0'
                        return
                else
                        n = self
@@ -1020,7 +1020,7 @@ redef class Int
                # Fill digits
                var pos = digit_count(base) - 1
                while pos >= 0 and n > 0 do 
-                       s[pos] = (n % base).to_c
+                       s.chars[pos] = (n % base).to_c
                        n = n / base # /
                        pos -= 1
                end
@@ -1058,7 +1058,7 @@ redef class Float
                var len = str.length
                for i in [0..len-1] do
                        var j = len-1-i
-                       var c = str[j]
+                       var c = str.chars[j]
                        if c == '0' then
                                continue
                        else if c == '.' then
@@ -1111,7 +1111,7 @@ redef class Char
        redef fun to_s
        do
                var s = new Buffer.with_capacity(1)
-               s[0] = self
+               s.chars[0] = self
                return s.to_s
        end
 
index 46bda9b..22d0bc9 100644 (file)
@@ -76,12 +76,12 @@ class BM_Pattern
                var j = from
                while j < n - m + 1 do
                        var i = m - 1 # Cursor in the pattern
-                       while i >= 0 and _motif[i] == s[i + j] do i -= 1
+                       while i >= 0 and _motif.chars[i] == s.chars[i + j] do i -= 1
                        if i < 0 then
                                return j
                        else
                                var gs = _gs[i] # Good shift
-                               var bc = bc(s[i+j]) - m + 1 + i # Bad char
+                               var bc = bc(s.chars[i+j]) - m + 1 + i # Bad char
                                # Both are true, do move to the best
                                if gs > bc then
                                        j += gs
@@ -142,7 +142,7 @@ class BM_Pattern
                var m = _length
                var i = 0
                while i < m - 1 do
-                       _bc_table[x[i]] = m - i - 1
+                       _bc_table[x.chars[i]] = m - i - 1
                        i += 1
                end
        end
@@ -162,7 +162,7 @@ class BM_Pattern
                        else
                                if i < g then g = i
                                f = i
-                               while g >= 0 and x[g] == x[g + m - 1 - f] do g -= 1
+                               while g >= 0 and x.chars[g] == x.chars[g + m - 1 - f] do g -= 1
                                suff[i] = f - g
                        end
                        i -= 1
@@ -239,7 +239,7 @@ redef class Char
        do
                var stop = s.length
                while from < stop do
-                       if s[from] == self then return from
+                       if s.chars[from] == self then return from
                        from += 1
                end
                return -1
@@ -265,7 +265,7 @@ redef class String
                var stop = s.length - length + 1
                while from < stop do
                        var i = length - 1
-                       while i >= 0 and self[i] == s[i + from] do i -= 1
+                       while i >= 0 and self.chars[i] == s.chars[i + from] do i -= 1
                        # Test if we found
                        if i < 0 then return from
                        # Not found so try next one
@@ -330,10 +330,10 @@ redef class String
        fun html_escape: String
        do
                var ret = self
-               if ret.has('&') then ret = ret.replace('&', "&amp;")
-               if ret.has('<') then ret = ret.replace('<', "&lt;")
-               if ret.has('>') then ret = ret.replace('>', "&gt;")
-               if ret.has('"') then ret = ret.replace('"', "&quot;")
+               if ret.chars.has('&') then ret = ret.replace('&', "&amp;")
+               if ret.chars.has('<') then ret = ret.replace('<', "&lt;")
+               if ret.chars.has('>') then ret = ret.replace('>', "&gt;")
+               if ret.chars.has('"') then ret = ret.replace('"', "&quot;")
                return ret
        end
 end
index be9c26b..12d8b37 100644 (file)
@@ -596,7 +596,7 @@ class Debugger
                        print "\nEnd of current instruction \n"
                else if parts_of_command[1] == "stack" then
                        print self.stack_trace
-               else if parts_of_command[1].has('[') and parts_of_command[1].has(']') then
+               else if parts_of_command[1].chars.has('[') and parts_of_command[1].chars.has(']') then
                        process_array_command(parts_of_command)
                else
                        var instance = seek_variable(get_real_variable_name(parts_of_command[1]), frame)
@@ -832,7 +832,7 @@ class Debugger
                var trigger_string_escape = false
                var trigger_concat_in_string = false
 
-               for i in instruction do
+               for i in instruction.chars do
                        if trigger_char_escape then
                                if i == '\'' then trigger_char_escape = false
                        else if trigger_string_escape then
@@ -844,7 +844,7 @@ class Debugger
                                if i.is_alphanumeric or i == '_' then
                                        instruction_buffer.add(i)
                                else if i == '.' then
-                                       if instruction_buffer.is_numeric or (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then
+                                       if instruction_buffer.is_numeric or (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then
                                                instruction_buffer.clear
                                        else
                                                result_array.push(instruction_buffer.to_s)
@@ -858,13 +858,13 @@ class Debugger
                                        trigger_concat_in_string = false
                                        trigger_string_escape = true
                                else
-                                       if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
+                                       if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
                                        instruction_buffer.clear
                                end
                        end
                end
 
-               if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
+               if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
 
                return result_array
        end
@@ -876,7 +876,7 @@ class Debugger
                var buf = new Buffer
                var trigger_copy = false
 
-               for i in function do
+               for i in function.chars do
                        if i == ')' then break
                        if trigger_copy then buf.add(i)
                        if i == '(' then trigger_copy = true
@@ -1166,7 +1166,7 @@ class Debugger
 
                var last_was_opening_bracket = false
 
-               for i in braces do
+               for i in braces.chars do
                        if i == '[' then
                                if last_was_opening_bracket then
                                        return null
@@ -1344,7 +1344,7 @@ class Debugger
        fun get_char(value: String): nullable Instance
        do
                if value.length >= 1 then
-                       return char_instance(value[0])
+                       return char_instance(value.chars[0])
                else
                        return null
                end
index 668f72a..9daefcb 100644 (file)
@@ -90,7 +90,7 @@ redef class ACharExpr
                        v.toolcontext.error(self.hot_location, "Invalid character literal {txt}")
                        return
                end
-               self.value = txt[1]
+               self.value = txt.chars[1]
        end
 end
 
@@ -101,7 +101,7 @@ redef class AStringFormExpr
        do
                var txt = self.n_string.text
                var skip = 1
-               if txt[0] == txt[1] and txt.length >= 6 then skip = 3
+               if txt.chars[0] == txt.chars[1] and txt.length >= 6 then skip = 3
                self.value = txt.substring(skip, txt.length-(2*skip)).unescape_nit
        end
 end
index b3e8458..753acea 100644 (file)
@@ -174,7 +174,7 @@ class Location
                var line_start = l.file.line_starts[i-1]
                var line_end = line_start
                var string = l.file.string
-               while line_end+1 < string.length and string[line_end+1] != '\n' and string[line_end+1] != '\r' do
+               while line_end+1 < string.length and string.chars[line_end+1] != '\n' and string.chars[line_end+1] != '\r' do
                        line_end += 1
                end
                var lstart = string.substring(line_start, l.column_start - 1)
@@ -195,7 +195,7 @@ class Location
                end
                var indent = new Buffer
                for j in [line_start..line_start+l.column_start-1[ do
-                       if string[j] == '\t' then
+                       if string.chars[j] == '\t' then
                                indent.add '\t'
                        else
                                indent.add ' '
index 2d2b6e4..d4b7a81 100644 (file)
@@ -51,7 +51,7 @@ private class Doc2Mdwn
                        # Count the number of spaces
                        lastindent = indent
                        indent = 0
-                       while text.length > indent and text[indent] == ' ' do indent += 1
+                       while text.length > indent and text.chars[indent] == ' ' do indent += 1
 
                        # Is codeblock? Then just collect them
                        if indent > 4 then
index ef2a5f3..26149a4 100644 (file)
@@ -751,13 +751,13 @@ redef class AInternMethPropdef
                                if arg1 >= recvval.length or arg1 < 0 then
                                        debug("Illegal access on {recvval} for element {arg1}/{recvval.length}")
                                end
-                               return v.char_instance(recvval[arg1])
+                               return v.char_instance(recvval.chars[arg1])
                        else if pname == "[]=" then
                                var arg1 = args[1].to_i
                                if arg1 >= recvval.length or arg1 < 0 then
                                        debug("Illegal access on {recvval} for element {arg1}/{recvval.length}")
                                end
-                               recvval[arg1] = args[2].val.as(Char)
+                               recvval.chars[arg1] = args[2].val.as(Char)
                                return null
                        else if pname == "copy_to" then
                                # sig= copy_to(dest: NativeString, length: Int, from: Int, to: Int)
index fc6dc36..cac7dd5 100755 (executable)
@@ -167,7 +167,7 @@ redef class Stdin
        do
                var loc_buf = new Buffer
                if connection.ready_to_read(0) then buf.append(connection.read)
-               for i in [buf_pos .. buf.length-1] do loc_buf.add(buf[i])
+               for i in [buf_pos .. buf.length-1] do loc_buf.add(buf.chars[i])
                buf.clear
                buf_pos = 0
                return loc_buf.to_s
@@ -185,7 +185,7 @@ redef class Stdin
                        buf.append(connection.read)
                end
                buf_pos += 1
-               return buf[buf_pos-1].ascii
+               return buf.chars[buf_pos-1].ascii
        end
 
        # Reads a line on the network if available
@@ -204,8 +204,8 @@ redef class Stdin
                                buf.append(connection.read)
                        end
                        buf_pos += 1
-                       if buf[buf_pos-1] == '\n' then break
-                       line_buf.add(buf[buf_pos-1])
+                       if buf.chars[buf_pos-1] == '\n' then break
+                       line_buf.add(buf.chars[buf_pos-1])
                end
                return line_buf.to_s
        end
index 84c0815..c073793 100644 (file)
@@ -159,7 +159,7 @@ class NitIndex
                else
                        var category = parts[0]
                        var keyword = parts[1]
-                       if keyword.first == ' ' then keyword = keyword.substring_from(1)
+                       if keyword.chars.first == ' ' then keyword = keyword.substring_from(1)
                        return new IndexQueryPair(str, keyword, category)
                end
        end
@@ -863,7 +863,7 @@ redef class String
        private fun escape: String
        do
                var b = new Buffer
-               for c in self do
+               for c in self.chars do
                        if c == '\n' then
                                b.append("\\n")
                        else if c == '\0' then
index 5e230dc..614a11e 100644 (file)
@@ -1297,7 +1297,7 @@ class Lexer
                        if sp >= string_len then
                                dfa_state = -1
                        else
-                               var c = string[sp].ascii
+                               var c = string.chars[sp].ascii
                                sp += 1
 
                                var cr = _cr
index 6a4d1d0..7784714 100644 (file)
@@ -107,7 +107,7 @@ $ end foreach
                        if sp >= string_len then
                                dfa_state = -1
                        else
-                               var c = string[sp].ascii
+                               var c = string.chars[sp].ascii
                                sp += 1
 
                                var cr = _cr
index 91851ba..674753c 100644 (file)
@@ -45,7 +45,7 @@ var only_lexer = false
 var need_help = false
 var no_file = false
 
-while not args.is_empty and args.first.first == '-' do
+while not args.is_empty and args.first.chars.first == '-' do
        if args.first == "-n" then
                no_print = true
        else if args.first == "-l" then
index 4ff4c8e..8251428 100644 (file)
@@ -17,7 +17,7 @@ import string
 redef class String
        redef fun output
        do
-               for c in self do c.output
+               for c in self.chars do c.output
        end
 end
 
index 9f5944f..6a2d643 100644 (file)
@@ -48,7 +48,7 @@ print(i)
 
 i = 0
 for k in [0..s.length[ do
-       var c = s[k]
+       var c = s.chars[k]
        if c >= 'a' and c <= 'z' then
                i = i + 1
        end
index 069ed21..a78d01f 100644 (file)
@@ -20,8 +20,8 @@ fun first_word(s: String): String
 do
        var result = new Buffer
        var i = 0
-       while i < s.length and s[i] != ' ' do
-               result.add(s[i])
+       while i < s.length and s.chars[i] != ' ' do
+               result.add(s.chars[i])
                i = i + 1
        end
        return result.to_s
index ea32fbf..f2d3216 100644 (file)
@@ -196,7 +196,7 @@ Start ../src/test_parser.nit:17,1--110,1
               TKwfalse "false" ../src/test_parser.nit:46,15--19
           AWhileExpr ../src/test_parser.nit:48,1--64,3
             TKwwhile "while" ../src/test_parser.nit:48,1--5
-            AAndExpr ../src/test_parser.nit:48,7--51
+            AAndExpr ../src/test_parser.nit:48,7--57
               ANotExpr ../src/test_parser.nit:48,7--23
                 TKwnot "not" ../src/test_parser.nit:48,7--9
                 ACallExpr ../src/test_parser.nit:48,11--23
@@ -206,20 +206,23 @@ Start ../src/test_parser.nit:17,1--110,1
                     AListExprs ../src/test_parser.nit:48,14
                   TId "is_empty" ../src/test_parser.nit:48,16--23
                   AListExprs ../src/test_parser.nit:48,23
-              AEqExpr ../src/test_parser.nit:48,29--51
-                ACallExpr ../src/test_parser.nit:48,29--44
-                  ACallExpr ../src/test_parser.nit:48,29--38
-                    ACallExpr ../src/test_parser.nit:48,29--32
-                      AImplicitSelfExpr ../src/test_parser.nit:48,29
-                      TId "args" ../src/test_parser.nit:48,29--32
-                      AListExprs ../src/test_parser.nit:48,32
-                    TId "first" ../src/test_parser.nit:48,34--38
-                    AListExprs ../src/test_parser.nit:48,38
-                  TId "first" ../src/test_parser.nit:48,40--44
-                  AListExprs ../src/test_parser.nit:48,44
-                ACharExpr ../src/test_parser.nit:48,49--51
-                  TChar "\'-\'" ../src/test_parser.nit:48,49--51
-            TKwdo "do" ../src/test_parser.nit:48,53--54
+              AEqExpr ../src/test_parser.nit:48,29--57
+                ACallExpr ../src/test_parser.nit:48,29--50
+                  ACallExpr ../src/test_parser.nit:48,29--44
+                    ACallExpr ../src/test_parser.nit:48,29--38
+                      ACallExpr ../src/test_parser.nit:48,29--32
+                        AImplicitSelfExpr ../src/test_parser.nit:48,29
+                        TId "args" ../src/test_parser.nit:48,29--32
+                        AListExprs ../src/test_parser.nit:48,32
+                      TId "first" ../src/test_parser.nit:48,34--38
+                      AListExprs ../src/test_parser.nit:48,38
+                    TId "chars" ../src/test_parser.nit:48,40--44
+                    AListExprs ../src/test_parser.nit:48,44
+                  TId "first" ../src/test_parser.nit:48,46--50
+                  AListExprs ../src/test_parser.nit:48,50
+                ACharExpr ../src/test_parser.nit:48,55--57
+                  TChar "\'-\'" ../src/test_parser.nit:48,55--57
+            TKwdo "do" ../src/test_parser.nit:48,59--60
             ABlockExpr ../src/test_parser.nit:49,2--64,3
               AIfExpr ../src/test_parser.nit:49,2--62,4
                 TKwif "if" ../src/test_parser.nit:49,2--3
index af40e9f..f647540 100644 (file)
@@ -212,11 +212,13 @@ Read token at ../src/test_parser.nit:48,29--32 text='args'
 Read token at ../src/test_parser.nit:48,33 text='.'
 Read token at ../src/test_parser.nit:48,34--38 text='first'
 Read token at ../src/test_parser.nit:48,39 text='.'
-Read token at ../src/test_parser.nit:48,40--44 text='first'
-Read token at ../src/test_parser.nit:48,46--47 text='=='
-Read token at ../src/test_parser.nit:48,49--51 text=''-''
-Read token at ../src/test_parser.nit:48,53--54 text='do'
-Read token at ../src/test_parser.nit:48,55--49,0 text='
+Read token at ../src/test_parser.nit:48,40--44 text='chars'
+Read token at ../src/test_parser.nit:48,45 text='.'
+Read token at ../src/test_parser.nit:48,46--50 text='first'
+Read token at ../src/test_parser.nit:48,52--53 text='=='
+Read token at ../src/test_parser.nit:48,55--57 text=''-''
+Read token at ../src/test_parser.nit:48,59--60 text='do'
+Read token at ../src/test_parser.nit:48,61--49,0 text='
 '
 Read token at ../src/test_parser.nit:49,2--3 text='if'
 Read token at ../src/test_parser.nit:49,5--8 text='args'
index b84da54..b0ecf41 100644 (file)
@@ -19,13 +19,13 @@ do
        var count = 0
        var array = new Buffer.with_capacity(n)
        for i in [0..n[ do
-               array[i] = 'o'
+               array.chars[i] = 'o'
        end
        for i in [2..n[ do
-               if array[i] == 'o' then
+               if array.chars[i] == 'o' then
                        var j = i * 2
                        while j < n do
-                               array[j] = 'x'
+                               array.chars[j] = 'x'
                                j = j + i
                        end
                        count = count + 1
index 1401821..82e2527 100644 (file)
@@ -15,9 +15,9 @@
 fun test(s: String)
 do
        print s.length
-       print s.first
-       print s.last
-       print s[2]
+       print s.chars.first
+       print s.chars.last
+       print s.chars[2]
        print s.substring(1, 2)
        print s.substring(-1, 2)
        print s.substring(1, 0)
index 94324a3..1b59ba8 100644 (file)
@@ -23,8 +23,8 @@ var i = 0
 while i < 5000 do
     var j = 0
     while j < s.length do
-        r.add(s[j])
-        r2.add(s[j])
+        r.add(s.chars[j])
+        r2.add(s.chars[j])
         j = j + 1
     end
     i = i + 1
index 9a576c7..9dee4a7 100644 (file)
@@ -17,5 +17,5 @@
 var a = "éè"
 print(a.length)
 for i in [0..a.length[ do
-       print("{i} is {a[i]} ({a[i].ascii})")
+       print("{i} is {a.chars[i]} ({a.chars[i].ascii})")
 end
index 28eb4f3..c2393aa 100644 (file)
@@ -34,10 +34,10 @@ print("has_suffix: {s.has_suffix(p)}")
 
 var test = "test"
 
-print("test[0] == 't' => {test[0] == 't'}")
-print("test[1] == 'e' => {test[1] == 'e'}")
-print("test[2] == 's' => {test[2] == 's'}")
-print("test[3] == 't' => {test[3] == 't'}")
+print("test[0] == 't' => {test.chars[0] == 't'}")
+print("test[1] == 'e' => {test.chars[1] == 'e'}")
+print("test[2] == 's' => {test.chars[2] == 's'}")
+print("test[3] == 't' => {test.chars[3] == 't'}")
 
 print("test.substring(0,1) == \"t\" => {test.substring(0,1) == "t"}")
 print("test.substring(0,2) == \"te\" => {test.substring(0,2) == "te"}")