- String: assign fstream objects to read and write a file
- String: convert to and from std::sstream and std::string
+- SuperString: sort and uniq
+- SuperString: find (regex)
+- SuperString: remove empty elements or elements macthing a pattern
+
- date: test parser for invalid dates and syntax errors
- date: Parser for stream input
- date: Yearday, Weekday and week number
pre.example
{
- background : lightblue ;
+ background : #eeffee ;
+ border-width : 1px ;
width : 80% ;
- margin-left: 5% ;
+ margin-left: 2% ;
padding-left: 2% ;
- padding-top: 100px% ;
+ padding-top: 1% ;
}
span.remark
</section>
<section>
-<heading>Pattern matching</heading>
+<heading>Searching in Strings</heading>
<description>
<item tag="int in(String &x)">
Find the string x within the string. Returns the index where <emph>x</emph> was
</item>
</description>
</section>
+
+<section>
+<heading>Splitting Strings into SuperStrings</heading>
+<description>
+<item tag="SuperString split(String &separator)">
+Return a list of the words in the string, using <emph>separator</emph> as the delimiter string.
+<example>
+String numbers("2,4,7");
+numbers.split(","); // "2" "4" "7"
+</example>
+Splitting an empty string will result in a SuperString with an empty string as its only element.
+The <emph>separator</emph> can be a multiple character string, for example:
+<example>
+String somexml("A&amp;B&amp;C");
+somexml.split("&amp;"); // "A" "B" "C"
+</example>
+Consecutive separators are not grouped together and are deemed to delimit empty strings, for example:
+<example>
+String numbers("3.14 42"); // Note 3 spaces
+numbers.split(" "); // "3.14" "" "" "42"
+</example>
+This also happens with separators at the start and the end of the string.
+</item>
+</description>
+</section>
+
<section>
<heading>Stream I/O</heading>
<para>
std::cout << "Joined with ' ': " << s1 << "\n";
assert(s1 == "The String To Split");
+ String s2("A&B&C");
+ SuperString ss2 = s2.split("&"); // "A" "B" "C"
+ std::cout << "The string \"" << s2 << "\" split on \"&\":\n";
+ print_ss(ss2);
+ std::cout << "\n";
+ assert(~ss2 == 3);
+
+ // Split an empty string
+ String s3("");
+ SuperString ss3 = s3.split(",");
+ std::cout << "The string \"" << s3 << "\" split on \",\":\n";
+ print_ss(ss3);
+ std::cout << "\n";
+ assert(~ss3 == 1);
+
+ // Test consequtive separators
+ String s4("3.14 42"); // Note 3 spaces
+ SuperString ss4 = s4.split(" ");
+ std::cout << "The string \"" << s4 << "\" split on \" \":\n";
+ print_ss(ss4);
+ std::cout << "\n";
+
+ assert(~ss4 == 4);
+ assert(ss4[0] == "3.14");
+ assert(ss4[1] == "");
+ assert(ss4[2] == "");
+ assert(ss4[3] == "42");
+
+ // Test a separator at the start and end of the string
+ String s5("-aaa-bbb-"); // Note 3 spaces
+ SuperString ss5 = s5.split("-");
+ std::cout << "The string \"" << s5 << "\" split on \"-\":\n";
+ print_ss(ss5);
+ std::cout << "\n";
+
+ assert(~ss5 == 4);
+ assert(ss5[0] == "");
+ assert(ss5[1] == "aaa");
+ assert(ss5[2] == "bbb");
+ assert(ss5[3] == "");
+
+
return 0;
}
The string The_String_To_Split split on "_":
["The","String","To","Split"]
Joined with ' ': The String To Split
+The string "A&B&C" split on "&":
+["A","B","C"]
+The string "" split on ",":
+[""]
+The string "3.14 42" split on " ":
+["3.14","","","42"]
+The string "-aaa-bbb-" split on "-":
+["","aaa","bbb",""]
PASS string_split_join (exit status: 0)