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
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
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
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
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
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
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
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)
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
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
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
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)
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
if eof then return
else
var c = x.ascii
- s.push(c)
+ s.chars.push(c)
if c == '\n' then return
end
end
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
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
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
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
# 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
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
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
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
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
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
# 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
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
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
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
# 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
# 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
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
redef fun to_s
do
var s = new Buffer.with_capacity(1)
- s[0] = self
+ s.chars[0] = self
return s.to_s
end
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
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
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
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
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
fun html_escape: String
do
var ret = self
- if ret.has('&') then ret = ret.replace('&', "&")
- if ret.has('<') then ret = ret.replace('<', "<")
- if ret.has('>') then ret = ret.replace('>', ">")
- if ret.has('"') then ret = ret.replace('"', """)
+ if ret.chars.has('&') then ret = ret.replace('&', "&")
+ if ret.chars.has('<') then ret = ret.replace('<', "<")
+ if ret.chars.has('>') then ret = ret.replace('>', ">")
+ if ret.chars.has('"') then ret = ret.replace('"', """)
return ret
end
end
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)
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
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)
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
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
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
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
v.toolcontext.error(self.hot_location, "Invalid character literal {txt}")
return
end
- self.value = txt[1]
+ self.value = txt.chars[1]
end
end
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
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)
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 ' '
# 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
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)
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
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
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
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
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
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
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
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
redef class String
redef fun output
do
- for c in self do c.output
+ for c in self.chars do c.output
end
end
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
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
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
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
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'
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
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)
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
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
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"}")