lib/string: teach clients to use non deprecated services.
authorJean Privat <jean@pryen.org>
Fri, 4 Apr 2014 13:36:30 +0000 (09:36 -0400)
committerJean Privat <jean@pryen.org>
Fri, 4 Apr 2014 18:16:08 +0000 (14:16 -0400)
Mostly, this mean using `chars`.

Signed-off-by: Jean Privat <jean@pryen.org>

18 files changed:
contrib/nitcc/src/nitcc_lexer0.nit
contrib/nitcc/src/nitcc_semantic.nit
contrib/nitcc/src/re2nfa.nit
examples/calculator.nit
lib/json_serialization.nit
lib/mpd.nit
lib/nitcc_runtime.nit
lib/opts.nit
lib/simple_json_reader/simple_json_reader.nit
lib/standard/file.nit
lib/standard/string.nit
src/debugger.nit
src/modelize_class.nit
src/modelize_property.nit
src/nitdoc.nit
src/nitni/nitni_base.nit
src/serialization_phase.nit
tests/base_iterator1.nit

index 6f12765..7fa876f 100644 (file)
@@ -25,14 +25,14 @@ import nitcc_parser
 class Lexer_nitcc
        var text: String
 
-       var iter: Iterator[Char] = "".iterator
+       var iter: Iterator[Char] = "".chars.iterator
        var pos = 0
 
        var tokens = new Array[NToken]
 
        fun lex: Array[NToken]
        do
-               iter = text.iterator
+               iter = text.chars.iterator
                while iter.is_ok do
                        trim
                        if not iter.is_ok then break
index 02aea35..b723c1a 100644 (file)
@@ -454,7 +454,7 @@ redef class Token
                var text = self.text
                if text != null then
                        var nfa = new Automaton.epsilon
-                       for c in text.as(not null) do
+                       for c in text.chars do
                                nfa.concat(new Automaton.atom(c.ascii))
                        end
                        return nfa
index da66d9f..d381fe1 100644 (file)
@@ -38,7 +38,7 @@ redef class Nstr
        do
                var a = new Automaton.epsilon
                var val
-               for c in self.value do
+               for c in self.value.chars do
                        var b = new Automaton.atom(c.ascii)
                        a.concat(b)
                end
@@ -50,7 +50,7 @@ redef class Nch_dec
        redef fun value: String do return text.substring_from(1).to_i.ascii.to_s
        redef fun make_rfa: Automaton
        do
-               var a = new Automaton.atom(self.value.first.ascii)
+               var a = new Automaton.atom(self.value.chars.first.ascii)
                return a
        end
 end
@@ -219,7 +219,7 @@ redef class Nre_class
                        exit(1)
                        abort
                end
-               var a = new Automaton.cla(c1.first.ascii, c2.first.ascii)
+               var a = new Automaton.cla(c1.chars.first.ascii, c2.chars.first.ascii)
                return a
        end
 end
index 35ed125..541f4d2 100644 (file)
@@ -123,7 +123,7 @@ class CalculatorGui
                                var s = context.result.to_precision_native(6)
                                var index : nullable Int = null
                                for i in s.length.times do
-                                   var chiffre = s[i]
+                                   var chiffre = s.chars[i]
                                    if chiffre == '0' and index == null then
                                        index = i
                                    else if chiffre != '0' then
@@ -132,7 +132,7 @@ class CalculatorGui
                                end
                                if index != null then
                                        s = s.substring(0, index)
-                                       if s[s.length-1] == ',' then s = s.substring(0, s.length-1)
+                                       if s.chars[s.length-1] == ',' then s = s.substring(0, s.length-1)
                                end
                                lbl_disp.text = s
                        end
index fd04d62..b361f88 100644 (file)
@@ -154,7 +154,7 @@ class JsonDeserializer
 
                                if val.length != 1 then print "Error: expected a single char when deserializing '{val}'."
                                
-                               return val.first
+                               return val.chars.first
                        end
 
                        print "Malformed Json string: unexpected Json Object kind '{kind}'"
index 9383934..fd8fa5d 100644 (file)
@@ -87,7 +87,7 @@ class MPDConnection
                        var words = l.split_with(" ")
                        if words.length > 1 then
                                var key = words[0].to_lower
-                               var first_space = l.index_of(' ')
+                               var first_space = l.chars.index_of(' ')
                                var rest = l.substring_from(first_space+1)
                                if  key == "volume:" then
                                        volume = rest.to_i
@@ -158,7 +158,7 @@ class MPDConnection
                        var words = l.split_with(" ")
                        if words.length > 1 then
                                var key = words[0].to_lower
-                               var first_space = l.index_of(' ')
+                               var first_space = l.chars.index_of(' ')
                                var rest = l.substring_from(first_space+1)
                                if key == "album:" then
                                        album = rest
index 1342c59..5f05815 100644 (file)
@@ -191,7 +191,7 @@ abstract class Lexer
                                c = '\0'
                                next = null
                        else
-                               c = text[pos]
+                               c = text.chars[pos]
                                next = state.trans(c)
                        end
                        if next == null then
@@ -467,7 +467,7 @@ end
 class NLexerError
        super NError
 
-       redef fun unexpected do return "character '{text.first}'"
+       redef fun unexpected do return "character '{text.chars.first}'"
 end
 
 # A parser error linked to a unexpected token
index 14e28fa..0ef02ad 100644 (file)
@@ -270,7 +270,7 @@ class OptionContext
                                parseargs = false
                        else
                                # We're looking for packed short options
-                               if str.last_index_of('-') == 0 and str.length > 2 then
+                               if str.chars.last_index_of('-') == 0 and str.length > 2 then
                                        var next_called = false
                                        for i in [1..str.length] do
                                                var short_opt = "-" + str.chars[i].to_s
index 3fd3d22..e9f8426 100644 (file)
@@ -27,7 +27,7 @@ redef class Nvalue_number
        redef fun to_nit_object
        do
                var text = n_number.text
-               if text.has('.') or text.has('e') or text.has('E') then return text.to_f
+               if text.chars.has('.') or text.chars.has('e') or text.chars.has('E') then return text.to_f
                return text.to_i
        end
 end
index b851876..f2653d1 100644 (file)
@@ -277,7 +277,7 @@ redef class String
                var l = length - 1 # Index of the last char
                while l > 0 and self.chars[l] == '/' do l -= 1 # remove all trailing `/`
                if l == 0 then return "/"
-               var pos = last_index_of_from('/', l)
+               var pos = chars.last_index_of_from('/', l)
                var n = self
                if pos >= 0 then
                        n = substring(pos+1, l-pos)
@@ -299,7 +299,7 @@ redef class String
        do
                var l = length - 1 # Index of the last char
                while l > 0 and self.chars[l] == '/' do l -= 1 # remove all trailing `/`
-               var pos = last_index_of_from('/', l)
+               var pos = chars.last_index_of_from('/', l)
                if pos > 0 then
                        return substring(0, pos)
                else if pos == 0 then
@@ -419,7 +419,7 @@ redef class String
        #     assert ".file".file_extension         == null
        fun file_extension: nullable String
        do
-               var last_slash = last_index_of('.')
+               var last_slash = chars.last_index_of('.')
                if last_slash > 0 then
                        return substring( last_slash+1, length )
                else
index 3e3dd65..8e26e2d 100644 (file)
@@ -208,7 +208,7 @@ abstract class Text
        fun has_substring(str: String, pos: Int): Bool
        do
                var myiter = self.chars.iterator_from(pos)
-               var itsiter = str.iterator
+               var itsiter = str.chars.iterator
                while myiter.is_ok and itsiter.is_ok do
                        if myiter.item != itsiter.item then return false
                        myiter.next
@@ -425,7 +425,7 @@ abstract class Text
        fun escape_more_to_c(chars: String): String
        do
                var b = new FlatBuffer
-               for c in escape_to_c do
+               for c in escape_to_c.chars do
                        if chars.chars.has(c) then
                                b.add('\\')
                        end
@@ -445,12 +445,12 @@ abstract class Text
        #     assert s.length        ==  2
        #     var u = s.unescape_nit
        #     assert u.length        ==  1
-       #     assert u[0].ascii      ==  10 # (the ASCII value of the "new line" character)
+       #     assert u.chars[0].ascii      ==  10 # (the ASCII value of the "new line" character)
        fun unescape_nit: String
        do
                var res = new FlatBuffer.with_capacity(self.length)
                var was_slash = false
-               for c in self do
+               for c in chars do
                        if not was_slash then
                                if c == '\\' then
                                        was_slash = true
index a73bab5..08befc6 100644 (file)
@@ -639,7 +639,7 @@ class Debugger
        # Processes an array print command
        fun process_array_command(parts_of_command: Array[String])
        do
-               var index_of_first_brace = parts_of_command[1].index_of('[')
+               var index_of_first_brace = parts_of_command[1].chars.index_of('[')
                var variable_name = get_real_variable_name(parts_of_command[1].substring(0,index_of_first_brace))
                var braces = parts_of_command[1].substring_from(index_of_first_brace)
 
@@ -1095,8 +1095,8 @@ class Debugger
        # Returns an array containing all the indexes demanded
        fun process_index(index_string: String): nullable Array[Int]
        do
-               var from_end_index = index_string.index_of('.')
-               var to_start_index = index_string.last_index_of('.')
+               var from_end_index = index_string.chars.index_of('.')
+               var to_start_index = index_string.chars.last_index_of('.')
 
                if from_end_index != -1 and to_start_index != -1 then
                        var index_from_string = index_string.substring(0,from_end_index)
index 34b5c28..2d1dc58 100644 (file)
@@ -120,7 +120,7 @@ redef class ModelBuilder
                                        error(nfd, "Error: A formal parameter type `{ptname}' already exists")
                                        return
                                end
-                               for c in ptname do if c >= 'a' and c<= 'z' then
+                               for c in ptname.chars do if c >= 'a' and c<= 'z' then
                                        warning(nfd, "Warning: lowercase in the formal parameter type {ptname}")
                                        break
                                end
index 9667d77..9425fcf 100644 (file)
@@ -934,7 +934,7 @@ redef class ATypePropdef
                if mprop == null then
                        var mvisibility = new_property_visibility(modelbuilder, nclassdef, self.n_visibility)
                        mprop = new MVirtualTypeProp(mclassdef, name, mvisibility)
-                       for c in name do if c >= 'a' and c<= 'z' then
+                       for c in name.chars do if c >= 'a' and c<= 'z' then
                                modelbuilder.warning(n_id, "Warning: lowercase in the virtual type {name}")
                                break
                        end
index 4715068..abcc91f 100644 (file)
@@ -1785,7 +1785,7 @@ redef class ADoc
                for t in n_comment do
                        var text = t.text
                        text = text.substring_from(1)
-                       if text.first == ' ' then text = text.substring_from(1)
+                       if text.chars.first == ' ' then text = text.substring_from(1)
                        res.append(text.html_escape)
                end
                var str = res.to_s
index 69f64f3..896b579 100644 (file)
@@ -45,7 +45,7 @@ redef class MMethod
                if nit_name == ">>" then return "_right"
                if nit_name == "<=>" then return "_starship"
 
-               if nit_name.last == '=' then return "{nit_name.substring(0, nit_name.length-1)}__assign"
+               if nit_name.chars.last == '=' then return "{nit_name.substring(0, nit_name.length-1)}__assign"
                return nit_name
        end
 end
index 73ce377..f565f56 100644 (file)
@@ -135,7 +135,7 @@ private class SerializationPhase
 
                for nclassdef in nclassdefs do
                        var name = nclassdef.n_id.text
-                       if not name.has('[') then # FIXME this is a temporary hack
+                       if not name.chars.has('[') then # FIXME this is a temporary hack
                                code.add "              if name == \"{name}\" then return new {name}.from_deserializer(self)"
                        end
                end
index ceec37d..aa06403 100644 (file)
@@ -31,8 +31,8 @@ for v in col do print v
 
 # ok
 var map = new MapIterable
-map.map["Riri"] = "Riri".to_a
-map.map["Fifi"] = "Fifi".to_a
-map.map["Loulou"] = "Loulou".to_a
+map.map["Riri"] = "Riri".chars.to_a
+map.map["Fifi"] = "Fifi".chars.to_a
+map.map["Loulou"] = "Loulou".chars.to_a
 for k, v in map do print "{k}: {v.join(",")}"