Completed chapter about String class.
authorArjen Baart <arjen@andromeda.nl>
Thu, 23 May 2019 20:23:49 +0000 (22:23 +0200)
committerArjen Baart <arjen@andromeda.nl>
Thu, 23 May 2019 20:23:49 +0000 (22:23 +0200)
doc/string.xml

index 6755035..cf53e99 100644 (file)
@@ -137,8 +137,17 @@ x(3,5) = y;           // x = &quot;abc12345678ijkl&quot;
 <para>
 Note that assigning a string to a zero-length substring will simply insert
 the a string into another string. Reversely, assigning an empty string to a
-substring will remove the characters from the original string. This property
-can be used to truncate a string to its first n characters by:
+substring will remove the characters from the original string.
+</para>
+<example>
+String x = &quot;abcdefghijkl&quot;;
+String y = &quot;12345678&quot;;
+
+x(3,0) = y;           // x = &quot;abc12345678defghijkl&quot;
+x(11,5) = "";         // x = &quot;abc12345678ijkl&quot;
+</example>
+<para>
+This property can be used to truncate a string to its first n characters by:
 </para>
 <example>
 x(n, ~x-n) = &quot;&quot;;
@@ -235,8 +244,48 @@ array from an istream. I.e., characters are read from the stream until the
 first whitespace character.
 </para>
 </section>
+
+<section>
+<heading>Regular Expressions</heading>
+<para>
+Regular expressions are handled by objects of class <code>regex</code>.
+Constructors allow the creation of regex objects from <code>String</code> objects,
+literal strings or other regex objects.
+</para>
+<example>
+String pattern("[a-z]+");
+regex  word(pattern);
+regex  number("[0-9]+");
+regex  nr(number);
+</example>
+<para>
+Regular expressions are primarily used to find patterns in text strings.
+The <strong>==</strong> operator performs the pattern matching.
+A relational expression returns true if the String matches the pattern,
+i.e. the pattern matches some part of the text in the String object.
+</para>
+<example>
+regex  nr("[0-9]+");
+String x("abcdef"");
+String y("abc123def");
+
+x == nr;  // false
+nr == y;  // true
+</example>
+<para>
+A regular expression can be used in a substring expression.
+The substring selected from the target string is the first part
+that matches the regular expression.
+</para>
+<example>
+regex  nr("[0-9]+");
+String y("abc123def456ghi");
+
+x = y(nr);  // x = 123
+</example>
+</section>
 <section>
-<heading>SEE ALSO</heading>
+<heading>See Also</heading>
 <itemize>
 <item> Bjarne Stroustrup, Section 6.9 </item>
 <item> DDJ October 1991, pg 24 </item>