Tools.h++ Manual

5-2 104011 Tandem Computers Incorporated
5
Program input:
This text describes V1.2. For more
information see the file install.doc.
The current version V1.2 implements...
Program output:
This text describes V4.0. For more
information see the file install.doc.
The current version V4.0 implements...
This example reads lines from standard input and searches them for a pattern
matching the regular expression "
V[0–9]\.[0–9]+
" (the extra backslash in
the program is to escape the special character '
\
'. This expression matches
"version numbers" between V0 and V9: V1.2, V1.22, but not V12.3. If a match
is found, then the pattern is replaced with the string "
V4.0
." The magic here is
in the expression;
a(re) = "V4.0";
The function call operator (i.e.,
RWCString::operator()
) has been
overloaded to take an argument of type
RWRegexp
—the regular expression. It
returns a "substring" that delimits the regular expression, or a null substring if
a matching expression could not be found. The substring assignment operator
is then called and replaces the delimited string with the contents of the right
hand side, or does nothing if this is the null substring.
Here is another example that reads in two
RWCStrings
, concatenates them,
converts to upper case, and then sends the results to
cout
:
RWCString a;
RWRegexp re("V[0-9]\\.[0-9]+");
while( a.readLine(cin) ){
a(re) = "V4.0";
cout << a << endl;
}
return 0;
}
Code Example 5-1 (Continued)