StrOps::Expand( StrBuf &, StrPtr &, StrDict & )

Expand “`%var%” strings into corresponding “`val” strings from a StrDict.

Virtual?

No

 

Class

StrOps

 

Arguments

StrBuf &o

the output string

 

StrPtr &s

the input string

 

StrDict &d

the var/value pairs to look up

Returns

void

 

Notes

This function provides a way to quickly expand variables from a StrDict into a StrBuf.

Example

This small program demonstrates the Expand() method in an OutputStat() implementation:

void MyClientUser::OutputStat( StrDict *varList )
{
    StrBuf s = StrBuf();
    s.Set( "File: %depotFile%  Rev: %rev%" );
    StrBuf o = StrBuf();
    StrOps::Expand( o, s, *varList );
    StrOps::Dump( o );
}

int main( int argc, char **argv )
{
    ClientApi client;
    MyClientUser ui;
    Error e;

    client.SetProtocol( "tag", "" );
    client.Init( &e );
    client.SetArgv( 1, ++argv );
    client.Run( "files", &ui );
    return client.Final( &e );
}

Executing the preceding code produces the following output:

% a.out *
File: //depot/src/file1.c  Rev: 4
File: //depot/src/file2.c  Rev: 2