</section>
<section>
-<heading>Adding to SuperStrings</heading>
+<heading>Adding and removing Strings</heading>
+
+<para>
+Just like <code>std::vector</code> objects, Strings can be inserted into and erased from
+a SuperString with the <code>insert(int position, const &String)</code> and
+<code>erase(int position)</code> methods.
+</para>
<para>
SuperString objects can be added together, i.e. concatenated, with the <strong>+</strong>
z = x + y; // z = [ "abc", "def" ]
y += z; // y = [ "def", "abc", "def" ]
</example>
+<para>
+the + operater can add strings and superstrings to append or prepend the one to the other. the result us always a superstring.
+</para>
</section>
<para>
split on a regex ? how to split on an empty string ?
-the + operater can add strings and superstrings to append or prepend the one to the other. the result us always a superstring.
add characters and strings ? -> TODO
return _ss.at(i);
}
+ // Inserting and erasing Strings
+
+ void insert(int position, const String &s)
+ {
+ _ss.insert(_ss.begin() + position, s);
+ }
+
+ void erase(int position)
+ {
+ _ss.erase(_ss.begin() + position);
+ }
+
// Adding Strings and SuperStrings
friend SuperString operator+(const SuperString&, const String&);
print_ss(ss9);
std::cout << "\n";
+ // insert method
+
+ SuperString ss10(2);
+ String s10("123");
+
+ ss10[0] = "abc";
+ ss10[1] = "def";
+ print_ss(ss10);
+ std::cout << " --> After inserting " << s10 << ": ";
+ ss10.insert(1, s10);
+ print_ss(ss10);
+ std::cout << "\n";
+
+ assert(~ss10 == 3);
+ assert(ss10[1] == "123");
+ assert(ss10[2] == "def");
+
+ // erase method
+
+ SuperString ss11(3);
+ ss11[0] = "abc";
+ ss11[1] = "def";
+ ss11[2] = "ghi";
+ print_ss(ss11);
+ std::cout << " --> After erasing position1: ";
+ ss11.erase(1);
+ print_ss(ss11);
+ std::cout << "\n";
+
+ assert(~ss11 == 2);
+ assert(ss11[1] == "ghi");
+
return 0;
}
--- /dev/null
+["abc"] + def = ["abc","def"]
+["uvw"]
+["uvw","xyz"]
+def + ["abc"] = ["def","abc"]
+["abc","def"] + ["uvw","xyz"] = ["abc","def","uvw","xyz"]
+["abc","def"] --> After inserting 123: ["abc","123","def"]
+["abc","def","ghi"] --> After erasing position1: ["abc","ghi"]
+PASS superstring_cat (exit status: 0)