"~username"
) or an shell environment variable ("$VARIABLE"
). Also provided is a function for verifying that an
external program to be invoked is available, and a function for searching the user's path.
Two classes are provided for manipulating
strings,
InfString
, and
StringList,
these classes are summarized in figure
3-8
In fact, InfString
is publicly derived from StringList
, adding only the cast to char*
. StringList
is implemented as a list of strings, where the size of the list is not bounded ahead of time. StringList
is recommended for applications where the list structure is to be preserved. The cast to char*
in InfString
destroys the list structure, consolidating all its strings into one contiguous string.
The most useful methods for both classes are summarized in table . Since InfString
differs by only one operator, we show only that one operator.
A word of warning is in order. If a function or expression returns a StringList
or InfString
, and that value is not assigned to a StringList
or InfString
variable or reference, and the (const char*)
or (char*)
cast is used, it is possible (likely under g++) that the StringList
or InfString
temporary will be destroyed too soon, leaving the const char*
or char*
pointer pointing to garbage. The solution is to assign the returned value to a local StringList
or InfString
before performing the cast. Suppose, for example, that the function foo
returns an InfString
. Further, suppose the function bar
takes a char*
argument. Then the following code will fail:
char*
is implicit). The following code will succeed: