From 46ab7c1e6b788edb91b907d1568d324fa2da1397 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 14 Oct 2014 12:46:06 -0400 Subject: [PATCH] lib: Updated lib for compliance with the new ropes Signed-off-by: Lucas Bajolet --- lib/ropes_debug.nit | 71 +++++++++----------------- lib/string_experimentations/utf8_noindex.nit | 8 +-- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/lib/ropes_debug.nit b/lib/ropes_debug.nit index a122a02..da40da1 100644 --- a/lib/ropes_debug.nit +++ b/lib/ropes_debug.nit @@ -14,74 +14,53 @@ # Exposes methods for debugging ropes when needed. module ropes_debug -intrude import ::standard::ropes -import ::standard +import standard +intrude import standard::ropes -redef class Rope +redef class Text # Writes self as a dot file on the hard drive - fun to_dot(filepath: String): String is abstract -end + private fun internal_to_dot: String is abstract -redef class RopeNode - # Generates a dot string - fun to_dot(s: String): String is abstract + fun to_dot: String do + return "digraph g \{\n" + internal_to_dot + "\}\n" + end end -redef class Leaf - redef fun to_dot(s): String +redef class Concat + redef fun internal_to_dot: String do - s += "n{object_id} [label = \"{str}\" shape = rect];\n" - s += "n{str.object_id} -> n{object_id} [label = \"contains\"];\n" - s = str.to_dot(s) + var s = "n{object_id} [label = {length}];\n" + s += "n{object_id} -> n{left.object_id} [label = \"left\"];\n" + s += left.internal_to_dot + s += "n{object_id} -> n{right.object_id} [label = \"right\"];\n" + s += right.internal_to_dot return s end end -redef class Concat - redef fun to_dot(s): String +redef class RopeBuffer + redef fun internal_to_dot: String do - s += "n{object_id} [label = {length}];\n" - if left != null then - s += "n{object_id} -> n{left.object_id} [label = \"left\"];\n" - s = left.to_dot(s) - end - if right != null then - s += "n{object_id} -> n{right.object_id} [label = \"right\"];\n" - s = right.to_dot(s) - end + var s = "n{object_id} [label = {length}];\n" + s += "n{object_id} -> n{str.object_id} [label = \"str\"];\n" + s += str.internal_to_dot + s += "n{object_id} -> n{ns.object_id} [label = \"ns\"];\n" + s += "n{ns.object_id}[label = \"NativeString\", content=\"{ns.to_s_with_length(rpos)}\"];\n" return s end end -redef class FlatText - fun to_dot(s: String): String is abstract -end - redef class FlatString - redef fun to_dot(s: String): String + redef fun internal_to_dot: String do - return s + "n{object_id} [label=\"FlatString\\nindex_from = {index_from}\\nindex_to = {index_to}\\nNativeString = {items.to_s_with_length(items.cstring_length)}\"];\n" + return "n{object_id} [label=\"FlatString\\nindex_from = {index_from}\\nindex_to = {index_to}\\nNativeString = {items.to_s_with_length(items.cstring_length)}\"];\n" end end redef class FlatBuffer - redef fun to_dot(s: String): String + redef fun internal_to_dot: String do - return s + "n{object_id} [label=\"FlatBuffer\\length = {length}\\ncapacity = {capacity}\\nitems = {items.to_s_with_length(items.cstring_length)}\"];\n" + return "n{object_id} [label=\"FlatBuffer\\length = {length}\\ncapacity = {capacity}\\nitems = {items.to_s_with_length(items.cstring_length)}\"];\n" end end -redef class RopeString - redef fun to_dot(filepath: String) - do - var of = new OFStream.open(filepath) - var ret: String = new RopeString.from("digraph g \{\n") - ret = root.to_dot(ret).as(RopeString) - ret += "\}\n" - ret.write_to(of) - of.close - return ret - end -end - - diff --git a/lib/string_experimentations/utf8_noindex.nit b/lib/string_experimentations/utf8_noindex.nit index 16c2502..c473a3c 100644 --- a/lib/string_experimentations/utf8_noindex.nit +++ b/lib/string_experimentations/utf8_noindex.nit @@ -448,8 +448,8 @@ redef class FlatString items.copy_to(new_str, bytelen, index_from, 0) o.items.copy_to(new_str, o.bytelen, o.index_from, bytelen) return new FlatString.full(new_str, 0, new_bytelen - 1, new_bytelen, newlen) - else if o isa RopeString then - return new RopeString.from(self) + o + else if o isa Concat then + return new Concat(self, o) else # If it goes to this point, that means another String implementation was concerned, therefore you need to support the + operation for this variant abort @@ -519,7 +519,7 @@ redef class FlatBuffer redef var bytelen: Int redef init from(s) do - if s isa RopeString then + if s isa Concat then with_capacity(50) for i in s.substrings do self.append(i) end @@ -618,7 +618,7 @@ redef class FlatBuffer end redef fun append(s) do - if s isa RopeString then + if s isa Concat then for i in s.substrings do append i end var i = s.as(FlatString) -- 1.7.9.5