StrBuf::Append( const StrPtr * )
Append a StrPtr
to a StrBuf
. The argument is
passed as a pointer to the StrPtr
. The string pointed to by
the StrPtr
's buffer
is logically appended to
the string pointed to by the StrBuf
's buffer
.
Arguments are commonly addresses of instances of classes derived from the
StrPtr
class, such as StrRef
and
StrBuf
.
Virtual? |
No |
|
Class |
||
Arguments |
|
pointer to the |
Returns |
|
Notes
Initialize the StrBuf
and the StrPtr
before
calling Append()
.
Exactly the number of bytes specified by the length
of the
StrPtr
are appended to the StrBuf
from the
StrPtr
. The length
of the StrBuf
is incremented by the length
of the StrPtr
.
If the memory for the StrBuf
's buffer
is not
large enough, new memory to contiguously contain the results of appending
the StrPtr
is allocated. If new memory is allocated, the old
memory is freed. Any memory allocated is separate from the memory for the
StrPtr
.
Example
#include <iostream> #include <stdhdrs.h> #include <strbuf.h> int main( int argc, char **argv ) { StrRef sr( "zy" ); StrPtr *sp = &sr; StrBuf sba; StrBuf sbb; sba.Set( "xyz" ); sbb.Set( "xyz" ); cout << "sba.Text() after sba.Set( \"xyz\" ) returns "; cout << "\"" << sba.Text() << "\"\n"; cout << "sba.Length() after sba.Set( \"xyz\" ) returns "; cout << sba.Length() << "\n"; cout << "sbb.Text() after sbb.Set( \"xyz\" ) returns "; cout << "\"" << sbb.Text() << "\"\n"; cout << "sbb.Length() after sbb.Set( \"xyz\" ) returns "; cout << sbb.Length() << "\n\n"; sba.Append( sp ); // append StrPtr * to StrBuf cout << "sba.Text() after sba.Append( sp ) returns "; cout << "\"" << sba.Text() << "\"\n"; cout << "sba.Length() after sba.Append( sp ) returns "; cout << sba.Length() << "\n\n"; sbb.Append( &sr ); // append &StrRef to StrBuf cout << "sbb.Text() after sbb.Append( &sr ) returns "; cout << "\"" << sbb.Text() << "\"\n"; cout << "sbb.Length() after sbb.Append( &sr ) returns "; cout << sbb.Length() << "\n\n"; sba.Append( &sbb ); // append &StrBuf to StrBuf cout << "sba.Text() after sba.Append( &sbb ) returns "; cout << "\"" << sba.Text() << "\"\n"; cout << "sba.Length() after sba.Append( &sbb ) returns "; cout << sba.Length() << "\n"; }
Executing the preceding code produces the following output:
sba.Text() after sba.Set( "xyz" ) returns "xyz" sba.Length() after sba.Set( "xyz" ) returns 3 sbb.Text() after sbb.Set( "xyz" ) returns "xyz" sbb.Length() after sbb.Set( "xyz" ) returns 3 sba.Text() after sba.Append( sp ) returns "xyzzy" sba.Length() after sba.Append( sp ) returns 5 sbb.Text() after sbb.Append( &sr ) returns "xyzzy" sbb.Length() after sbb.Append( &sr ) returns 5 sba.Text() after sba.Append( &sbb ) returns "xyzzyxyzzy" sba.Length() after sba.Append( &sbb ) returns 10