fun clanit(i: Int): String
do
- var s = new Buffer
+ var s = new FlatBuffer
s.append("{classes.first}[" * i)
s.append("Root")
s.append("]" * i)
fun clajava(i: Int): String
do
- var s = new Buffer
+ var s = new FlatBuffer
s.append("{classes.first}<" * i)
s.append("Root")
s.append(">" * i)
fun clacpp(i: Int): String
do
- var s = new Buffer
+ var s = new FlatBuffer
s.append("{classes.first}<" * i)
s.append("Root")
s.append("*>" * i)
fun clae(i: Int): String
do
- var s = new Buffer
+ var s = new FlatBuffer
s.append("{classes.first}[" * i)
s.append("ROOT")
s.append("]" * i)
# A pretty print for this help
fun pretty(off: Int): String
do
- var text = new Buffer.from(" ")
+ var text = new FlatBuffer.from(" ")
text.append(_names.join(", "))
text.append(" ")
var rest = off - text.length
# Internal code to handle execution
protected init execute(command: String, arguments: nullable Array[String], pipeflags: Int)
do
- var args = new Buffer
+ var args = new FlatBuffer
var l = 1 # Number of elements in args
args.append(command)
if arguments != null then
fun mkdir
do
var dirs = self.split_with("/")
- var path = new Buffer
+ var path = new FlatBuffer
if dirs.is_empty then return
if dirs[0].is_empty then
# it was a starting /
# Read at most i bytes
fun read(i: Int): String
do
- var s = new Buffer.with_capacity(i)
+ var s = new FlatBuffer.with_capacity(i)
while i > 0 and not eof do
var c = read_char
if c >= 0 then
fun read_line: String
do
assert not eof
- var s = new Buffer
+ var s = new FlatBuffer
append_line_to(s)
return s.to_s
end
# Read all the stream until the eof.
fun read_all: String
do
- var s = new Buffer
+ var s = new FlatBuffer
while not eof do
var c = read_char
if c >= 0 then s.add(c.ascii)
redef fun read(i)
do
- var s = new Buffer.with_capacity(i)
+ var s = new FlatBuffer.with_capacity(i)
var j = _buffer_pos
var k = _buffer.length
while i > 0 do
redef fun read_all
do
- var s = new Buffer
+ var s = new FlatBuffer
while not eof do
var j = _buffer_pos
var k = _buffer.length
redef fun eof do return _buffer_pos >= _buffer.length and end_reached
# The buffer
- var _buffer: nullable Buffer = null
+ var _buffer: nullable FlatBuffer = null
# The current position in the buffer
var _buffer_pos: Int = 0
# Allocate a `_buffer` for a given `capacity`.
protected fun prepare_buffer(capacity: Int)
do
- _buffer = new Buffer.with_capacity(capacity)
+ _buffer = new FlatBuffer.with_capacity(capacity)
_buffer_pos = 0 # need to read
end
end
# assert "Hello World!".to_upper == "HELLO WORLD!"
fun to_upper: String
do
- var s = new Buffer.with_capacity(length)
+ var s = new FlatBuffer.with_capacity(length)
for i in self.chars do s.add(i.to_upper)
return s.to_s
end
# assert "Hello World!".to_lower == "hello world!"
fun to_lower : String
do
- var s = new Buffer.with_capacity(length)
+ var s = new FlatBuffer.with_capacity(length)
for i in self.chars do s.add(i.to_lower)
return s.to_s
end
# Mangle a string to be a unique string only made of alphanumeric characters
fun to_cmangle: String
do
- var res = new Buffer
+ var res = new FlatBuffer
var underscore = false
for c in self.chars do
if (c >= 'a' and c <= 'z') or (c >='A' and c <= 'Z') then
# assert "\n\"'\\".escape_to_c == "\\n\\\"\\'\\\\"
fun escape_to_c: String
do
- var b = new Buffer
+ var b = new FlatBuffer
for c in self.chars do
if c == '\n' then
b.append("\\n")
# assert "ab|\{\}".escape_more_to_c("|\{\}") == "ab\\|\\\{\\\}"
fun escape_more_to_c(chars: String): String
do
- var b = new Buffer
+ var b = new FlatBuffer
for c in escape_to_c do
if chars.chars.has(c) then
b.add('\\')
# assert u[0].ascii == 10 # (the ASCII value of the "new line" character)
fun unescape_nit: String
do
- var res = new Buffer.with_capacity(self.length)
+ var res = new FlatBuffer.with_capacity(self.length)
var was_slash = false
for c in self do
if not was_slash then
end
+abstract class Buffer
+ super Text
+
+ # Modifies the char contained at pos `index`
+ #
+ # DEPRECATED : Use self.chars.[]= instead
+ fun []=(index: Int, item: Char) is abstract
+
+ # Adds a char `c` at the end of self
+ #
+ # DEPRECATED : Use self.chars.add instead
+ fun add(c: Char) is abstract
+
+ # Clears the buffer
+ fun clear is abstract
+
+ # Enlarges the subsequent array containing the chars of self
+ fun enlarge(cap: Int) is abstract
+
+ # Adds the content of string `s` at the end of self
+ fun append(s: String) is abstract
+
+ redef fun chars: BufferCharView is abstract
+end
+
# Mutable strings of characters.
-class Buffer
+class FlatBuffer
super AbstractString
super Comparable
super StringCapable
+ super Buffer
redef type OTHER: String
- redef var chars: BufferCharView = new FlatBufferCharView(self)
+ redef var chars: FlatBufferCharView = new FlatBufferCharView(self)
var capacity: Int
- # Modifies the char contained at pos `index`
- #
- # DEPRECATED : Use self.chars.[]= instead
- fun []=(index: Int, item: Char)
+ redef fun []=(index, item)
do
if index == length then
add(item)
items[index] = item
end
- # Adds a char `c` at the end of self
- #
- # DEPRECATED : Use self.chars.add instead
- fun add(c: Char)
+ redef fun add(c)
do
if capacity <= length then enlarge(length + 5)
items[length] = c
length += 1
end
- # Clears the buffer
- fun clear do length = 0
+ redef fun clear do length = 0
- # Enlarges the subsequent array containing the chars of self
- fun enlarge(cap: Int)
+ redef fun enlarge(cap)
do
var c = capacity
if cap <= c then return
length = 0
end
- # Adds the content of string `s` at the end of self
- fun append(s: String)
+ redef fun append(s)
do
var sl = s.length
if capacity < length + sl then enlarge(length + sl)
redef fun ==(o)
do
- if not o isa Buffer then return false
+ if not o isa FlatBuffer then return false
var l = length
if o.length != l then return false
var i = 0
if from < 0 then from = 0
if count > length then count = length
if from < count then
- var r = new Buffer.with_capacity(count - from)
+ var r = new FlatBuffer.with_capacity(count - from)
while from < count do
r.chars.push(items[from])
from += 1
private class FlatBufferReverseIterator
super IndexedIterator[Char]
- var target: Buffer
+ var target: FlatBuffer
var target_items: NativeString
var curr_pos: Int
- init with_pos(tgt: Buffer, pos: Int)
+ init with_pos(tgt: FlatBuffer, pos: Int)
do
target = tgt
target_items = tgt.items
super BufferCharView
super StringCapable
- redef type SELFTYPE: Buffer
+ redef type SELFTYPE: FlatBuffer
redef fun [](index) do return target.items[index]
private class FlatBufferIterator
super IndexedIterator[Char]
- var target: Buffer
+ var target: FlatBuffer
var target_items: NativeString
var curr_pos: Int
- init with_pos(tgt: Buffer, pos: Int)
+ init with_pos(tgt: FlatBuffer, pos: Int)
do
target = tgt
target_items = tgt.items
fun to_base(base: Int, signed: Bool): String
do
var l = digit_count(base)
- var s = new Buffer.from(" " * l)
+ var s = new FlatBuffer.from(" " * l)
fill_buffer(s, base, signed)
return s.to_s
end
# assert 'x'.to_s == "x"
redef fun to_s
do
- var s = new Buffer.with_capacity(1)
+ var s = new FlatBuffer.with_capacity(1)
s.chars[0] = self
return s.to_s
end
# Concatenate elements.
redef fun to_s
do
- var s = new Buffer
+ var s = new FlatBuffer
for e in self do if e != null then s.append(e.to_s)
return s.to_s
end
do
if is_empty then return ""
- var s = new Buffer # Result
+ var s = new FlatBuffer # Result
# Concat first item
var i = iterator
# Fast implementation
redef fun to_s
do
- var s = new Buffer
+ var s = new FlatBuffer
var i = 0
var l = length
while i < l do
do
if is_empty then return ""
- var s = new Buffer # Result
+ var s = new FlatBuffer # Result
# Concat first item
var i = iterator
fun read_command: String
do
- var buff = new Buffer
+ var buff = new FlatBuffer
while debugger_connection.ready_to_read(40) do buff.append(debugger_connection.read)
return buff.to_s
end
else if command == "nit" then
printn "$~> "
command = gets
- var nit_buf = new Buffer
+ var nit_buf = new FlatBuffer
while not command == ":q" do
nit_buf.append(command)
nit_buf.append("\n")
fun get_identifiers_in_current_instruction(instruction: AbstractString): Array[String]
do
var result_array = new Array[String]
- var instruction_buffer = new Buffer
+ var instruction_buffer = new FlatBuffer
var trigger_char_escape = false
var trigger_string_escape = false
#
fun get_function_arguments(function: AbstractString): String
do
- var buf = new Buffer
+ var buf = new FlatBuffer
var trigger_copy = false
for i in function.chars do
fun get_real_variable_name(name: String): String
do
var explode_string = name.split_with(".")
- var final_string = new Buffer
+ var final_string = new FlatBuffer
for i in explode_string do
var alias_resolved = get_variable_name_by_alias(i)
if alias_resolved != null then
# Returns an array containing their content
fun remove_braces(braces: String): nullable Array[String]
do
- var buffer = new Buffer
+ var buffer = new FlatBuffer
var result_array = new Array[String]
var frame = new Frame(v, mmethoddef, recv, arguments)
v.frame = frame
- var sig = new Buffer
- var comment = new Buffer
+ var sig = new FlatBuffer
+ var comment = new FlatBuffer
var ret = mmethoddef.msignature.return_mtype
if ret != null then
ret = v.resolve_for(ret, selfvar)
lmid = ""
lend = ""
end
- var indent = new Buffer
+ var indent = new FlatBuffer
for j in [line_start..line_start+l.column_start-1[ do
if string.chars[j] == '\t' then
indent.add '\t'
# Create a dot file representing the class hierarchy of a model.
fun generate_class_hierarchy(toolcontext: ToolContext, mmodule: MModule)
do
- var buf = new Buffer
+ var buf = new FlatBuffer
buf.append("digraph \{\n")
buf.append("node [shape=box];\n")
buf.append("rankdir=BT;\n")
# For a simple user of the model, the classdef hierarchy is not really usefull, it is more an internal thing.
fun generate_classdef_hierarchy(toolcontext: ToolContext, model: Model)
do
- var buf = new Buffer
+ var buf = new FlatBuffer
buf.append("digraph \{\n")
buf.append("node [shape=box];\n")
buf.append("rankdir=BT;\n")
# The generated file contains the description of each entity of the model
fun generate_model_hyperdoc(toolcontext: ToolContext, model: Model)
do
- var buf = new Buffer
+ var buf = new FlatBuffer
buf.append("<html>\n<body>\n")
buf.append("<h1>Model</h1>\n")
redef fun to_s
do
- var b = new Buffer
+ var b = new FlatBuffer
if not mparameters.is_empty then
b.append("(")
for i in [0..mparameters.length[ do
# Return a new native string initialized with `txt`
fun native_string_instance(txt: String): Instance
do
- var val = new Buffer.from(txt)
+ var val = new FlatBuffer.from(txt)
val.add('\0')
var ic = self.mainmodule.get_primitive_class("NativeString")
return new PrimitiveInstance[Buffer](ic.mclass_type, val)
# Return a stack stace. One line per function
fun stack_trace: String
do
- var b = new Buffer
+ var b = new FlatBuffer
b.append(",---- Stack trace -- - - -\n")
for f in frames do
b.append("| {f.mpropdef} ({f.current_node.location})\n")
return null
else if pname == "copy_to" then
# sig= copy_to(dest: NativeString, length: Int, from: Int, to: Int)
- var destval = args[1].val.as(Buffer)
+ var destval = args[1].val.as(FlatBuffer)
var lenval = args[2].to_i
var fromval = args[3].to_i
var toval = args[4].to_i
if toval + lenval >= destval.length then
debug("Illegal access on {destval} for element {toval}+{lenval}/{destval.length}")
end
- recvval.copy(fromval, lenval, destval, toval)
+ recvval.as(FlatBuffer).copy(fromval, lenval, destval, toval)
return null
else if pname == "atoi" then
return v.int_instance(recvval.to_i)
else if pname == "io_read" then
var str = recvval.as(IStream).read(args[2].to_i)
var a1 = args[1].val.as(Buffer)
- new Buffer.from(str).copy(0, str.length, a1, 0)
+ new FlatBuffer.from(str).copy(0, str.length, a1.as(FlatBuffer), 0)
return v.int_instance(str.length)
else if pname == "io_close" then
recvval.as(IOS).close
var connection: nullable Socket = null
# Used to store data that has been read from the connection
- var buf: Buffer = new Buffer
+ var buf: Buffer = new FlatBuffer
var buf_pos: Int = 0
# Checks if data is available for reading
# Blocking if the buffer is empty
redef fun read_all
do
- var loc_buf = new Buffer
+ var loc_buf = new FlatBuffer
if connection.ready_to_read(0) then buf.append(connection.read)
for i in [buf_pos .. buf.length-1] do loc_buf.add(buf.chars[i])
buf.clear
# If the buffer is empty, the read_line call is blocking
redef fun read_line
do
- var line_buf = new Buffer
+ var line_buf = new FlatBuffer
if connection.ready_to_read(0) then buf.append(connection.read)
var has_found_eol: Bool = false
loop
end
end
# build graph
- var op = new Buffer
+ var op = new FlatBuffer
op.append("digraph dep \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
for mmodule in poset do
op.append("\"{mmodule.name}\"[URL=\"{mmodule.url}\"];\n")
end
end
# build graph
- var op = new Buffer
+ var op = new FlatBuffer
var name = "dep_{mmodule.name}"
op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
for mmodule in poset do
end
cla.add_all(pe.greaters)
- var op = new Buffer
+ var op = new FlatBuffer
var name = "dep_{mclass.name}"
op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
for c in cla do
# module_owner_name.html
private fun url: String do
if url_cache == null then
- var res = new Buffer
+ var res = new FlatBuffer
res.append("module_")
var mowner = public_owner
if mowner != null then
# MOD_owner_name
private fun anchor: String do
if anchor_cache == null then
- var res = new Buffer
+ var res = new FlatBuffer
res.append("MOD_")
var mowner = public_owner
if mowner != null then
# <a href="url" title="short_comment">html_name</a>
private fun html_link(page: NitdocPage) do
if html_link_cache == null then
- var res = new Buffer
+ var res = new FlatBuffer
if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
res.append("<a href='{url}' title='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{html_name}</a>")
else
# <a href="url" title="short_comment">html_name(signature)</a>
private fun html_link(page: NitdocPage) do
if html_link_cache == null then
- var res = new Buffer
+ var res = new FlatBuffer
res.append("<a href='{url}'")
if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
# <a href="url" title="short_comment">html_name</a>
private fun html_short_link(page: NitdocPage) do
if html_short_link_cache == null then
- var res = new Buffer
+ var res = new FlatBuffer
res.append("<a href='{url}'")
if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
# <a href="url" title="short_comment">html_name</a>
private fun html_link_anchor(page: NitdocPage) do
if html_link_anchor_cache == null then
- var res = new Buffer
+ var res = new FlatBuffer
res.append("<a href='#{anchor}'")
if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
# <a href="url" title="short_comment">html_name</a>
private fun html_link(page: NitdocPage) do
if html_link_cache == null then
- var res = new Buffer
+ var res = new FlatBuffer
if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
res.append("<a href=\"{url}\" title=\"{nprop.short_comment}\">{mproperty.html_name}</a>")
end
private fun untyped_signature(page: NitdocPage): String do
- var res = new Buffer
+ var res = new FlatBuffer
if not mparameters.is_empty then
res.append("(")
for i in [0..mparameters.length[ do
end
private fun full_comment: String do
- var res = new Buffer
+ var res = new FlatBuffer
for t in n_comment do
var text = t.text
text = text.substring_from(1)
end
private class Pager
- var content = new Buffer
+ var content = new FlatBuffer
var indent = 0
fun add(text: String) do
add_indent
# return the generic signature of the class
# [E, F]
private fun signature: String do
- var res = new Buffer
+ var res = new FlatBuffer
if arity > 0 then
res.append("[")
for i in [0..intro.parameter_names.length[ do
# class name is displayed with colors depending on visibility
# abstract interface Foo[E]
private fun prototype: String do
- var res = new Buffer
+ var res = new FlatBuffer
res.append("{kind} ")
if visibility.to_s == "public" then res.append("{name}{signature}".bold.green)
if visibility.to_s == "private" then res.append("{name}{signature}".bold.red)
end
fun to_console: String do
- var res = new Buffer
+ var res = new FlatBuffer
if not is_intro then res.append("redef ")
res.append(mclass.prototype)
return res.to_s
redef class MMethodDef
redef fun to_console do
- var res = new Buffer
+ var res = new FlatBuffer
if not is_intro then res.append("redef ")
if not mproperty.is_init then res.append("fun ")
res.append(mproperty.to_console.bold)
redef class MVirtualTypeDef
redef fun to_console do
- var res = new Buffer
+ var res = new FlatBuffer
res.append("type ")
res.append(mproperty.to_console.bold)
res.append(": {bound.to_console}")
redef class MAttributeDef
redef fun to_console do
- var res = new Buffer
+ var res = new FlatBuffer
res.append("var ")
res.append(mproperty.to_console.bold)
res.append(": {static_mtype.to_console}")
redef class MSignature
redef fun to_console do
- var res = new Buffer
+ var res = new FlatBuffer
if not mparameters.is_empty then
res.append("(")
for i in [0..mparameters.length[ do
redef class MParameter
fun to_console: String do
- var res = new Buffer
+ var res = new FlatBuffer
res.append("{name}: {mtype.to_console}")
if is_vararg then res.append("...")
return res.to_s
redef class MGenericType
redef fun to_console do
- var res = new Buffer
+ var res = new FlatBuffer
res.append("{mclass.name}[")
for i in [0..arguments.length[ do
res.append(arguments[i].to_console)
private fun escape: String
do
- var b = new Buffer
+ var b = new FlatBuffer
for c in self.chars do
if c == '\n' then
b.append("\\n")
res = self.new_var(ret)
end
- var s = new Buffer
- var ss = new Buffer
+ var s = new FlatBuffer
+ var ss = new FlatBuffer
var recv = arguments.first
s.append("val*")
var msignature = mmethoddef.msignature.resolve_for(mmethoddef.mclassdef.bound_mtype, mmethoddef.mclassdef.bound_mtype, mmethoddef.mclassdef.mmodule, true)
- var sig = new Buffer
- var comment = new Buffer
+ var sig = new FlatBuffer
+ var comment = new FlatBuffer
var ret = msignature.return_mtype
if ret != null then
sig.append("{ret.ctype} ")
var frame = new Frame(v, mmethoddef, recv, arguments)
v.frame = frame
- var sig = new Buffer
- var comment = new Buffer
+ var sig = new FlatBuffer
+ var comment = new FlatBuffer
# Because the function is virtual, the signature must match the one of the original class
var intromclassdef = self.mmethoddef.mproperty.intro.mclassdef
var s = "*"
var i = 0
while i < n do
- var s2 = new Buffer.from("Je dis «")
+ var s2 = new FlatBuffer.from("Je dis «")
s2.append(s)
s2.append("» et redis «")
s2.append(s)
do
# Les variables sont déclarées par "var", leur portée va de leur
# déclaration jusqu'au "end" correspondant
- var s = new Buffer # Là où on calcule le résultat
+ var s = new FlatBuffer # Là où on calcule le résultat
# Les chaînes littérales sont déclarées avec des guillemets
s.append("*** Entrepôt ") # On initialise "s"
# puis on concatène des chaînes à "s"
# Si une expression est passée comme valeur initiale d'une
# variable, le type statique de la variable est implicitement
# celui de l'expression.
- var s = new Buffer
+ var s = new FlatBuffer
s.append("* Rayon : ")
# Ici, le type statique de s est implicitement String
redef fun to_s: String
do
- var s = new Buffer
+ var s = new FlatBuffer
s.append(to_s_head)
# Les boucles en NIT sont des structures puissantes, toutefois
# la manipulation des itérateurs peut être facilité par la
fun first_word(s: String): String
do
- var result = new Buffer
+ var result = new FlatBuffer
var i = 0
while i < s.length and s.chars[i] != ' ' do
result.add(s.chars[i])
# Second way: Build a string and display it.
# Pro: Eiffel way (rigourous).
# Con: Eiffel way (heavy).
-var s = new Buffer.from("The value of a is: ")
+var s = new FlatBuffer.from("The value of a is: ")
s.append(a.to_s)
s.append(".\n")
printn(s)
fun nsieve(n: Int): Int
do
var count = 0
- var array = new Buffer.with_capacity(n)
+ var array = new FlatBuffer.with_capacity(n)
for i in [0..n[ do
array.chars[i] = 'o'
end
var subtrim = trimtest.substring(2,15)
-var buffertrimtest = new Buffer.from(trimtest)
+var buffertrimtest = new FlatBuffer.from(trimtest)
print "resulttrim = {buffertrimtest.trim}"
var emptytrim = " \t "
-var bufferemptytest = new Buffer.from(emptytrim)
+var bufferemptytest = new FlatBuffer.from(emptytrim)
print "emptytrim = {emptytrim.trim}"
var onelettertrim = " \n d \n\t "
-var oneletterbuftest = new Buffer.from(onelettertrim)
+var oneletterbuftest = new FlatBuffer.from(onelettertrim)
print "onelettertrim = {onelettertrim.trim}"
var twolettertrim = " \n hg \n\t "
-var twoletterbuftest = new Buffer.from(twolettertrim)
+var twoletterbuftest = new FlatBuffer.from(twolettertrim)
print "twolettertrim = {twolettertrim.trim}"
var firstlettertrim = "d "
-var firstlettertrimbuf = new Buffer.from(firstlettertrim)
+var firstlettertrimbuf = new FlatBuffer.from(firstlettertrim)
print "firstlettertrimtest = {firstlettertrim.trim}"
var lastlettertrim = " d"
-var lastlettertrimbuf = new Buffer.from(lastlettertrim)
+var lastlettertrimbuf = new FlatBuffer.from(lastlettertrim)
print "lastlettertrimtest = {lastlettertrim.trim}"
#False
print "21,52,210.52".is_numeric
-var buf = new Buffer
+var buf = new FlatBuffer
buf.append("45.3")
var s = "Bonjour !\n"
-var r = new Buffer.with_capacity(50)
-var r2 = new Buffer
+var r = new FlatBuffer.with_capacity(50)
+var r2 = new FlatBuffer
var i = 0
while i < 5000 do