end
# Inserts a String `str` at position `pos`
- fun insert_at(str: String, pos: Int): RopeString
+ redef fun insert_at(str, pos)
do
if str.length == 0 then return self
if self.length == 0 then return new RopeString.from(str)
end
# Adds `s` at the beginning of self
- fun prepend(s: String): String do return insert_at(s, 0)
+ redef fun prepend(s) do return insert_at(s, 0)
# Adds `s` at the end of self
- fun append(s: String): String
+ redef fun append(s)
do
if self.is_empty then return s
return new RopeString.from_root(append_to_path(root,s))
end
end
+redef class FlatString
+
+ redef fun append(s) do return (new RopeString.from(self)) + s
+
+ redef fun prepend(s) do return (new RopeString.from(self)).prepend(s)
+
+ redef fun insert_at(s, pos)
+ do
+ if pos == 0 then return prepend(s)
+ if pos == length then return append(s)
+
+ var l = substring(0,pos)
+ var r = substring_from(pos)
+ var ret: String = new RopeString.from(l)
+ ret += s
+ return ret + r
+ end
+
+end
+
private class RopeStringChars
super SequenceRead[Char]
redef type SELFTYPE: String
redef fun to_s do return self
+
+ fun append(s: String): SELFTYPE is abstract
+
+ fun prepend(s: String): SELFTYPE is abstract
+
+ fun insert_at(s: String, pos: Int): SELFTYPE is abstract
end
private class FlatSubstringsIter
--- /dev/null
+quick brown fox over the lazy dog
+The quick brown fox over the lazy dog
+quick brown fox jumps over the lazy dog
+quick brown fox over the lazy dog.
+The quick brown fox jumps over the lazy dog.
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var st = "quick brown fox over the lazy dog"
+
+print st
+
+var pr = st.prepend("The ")
+
+print pr
+
+pr = st.insert_at(" jumps", 15)
+
+print pr
+
+pr = st.append(".")
+
+print pr
+
+print st.insert_at(" jumps", 15). prepend("The ").append(".")