ENH: add stringOps::expandDict

This commit is contained in:
Mark Olesen
2011-02-23 13:38:57 +01:00
parent 23dd3e072b
commit 31f6d9ba5e
3 changed files with 198 additions and 7 deletions

View File

@ -22,11 +22,13 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Test some string functionality
\*---------------------------------------------------------------------------*/
#include "string.H"
#include "stringOps.H"
#include "dictionary.H"
#include "IOstreams.H"
using namespace Foam;
@ -38,9 +40,19 @@ int main(int argc, char *argv[])
{
string test
(
" $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ "
" $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ with "
" $(DONOTSUBST) some other ${USER} entries "
);
dictionary dict;
dict.add("HOME", "myHome");
dictionary subDict;
subDict.add("value1", "test1");
subDict.add("value2", "test2");
dict.add("FOAM_RUN", subDict);
Info<< "string:" << test << nl << "hash:"
<< unsigned(string::hash()(test)) << endl;
@ -73,7 +85,10 @@ int main(int argc, char *argv[])
Info<< string(test).replaceAll("kj", "zzz") << endl;
Info<< string(test).replaceAll("kj", "z") << endl;
Info<< string(test).expand() << endl;
Info<< "expanded: " << string(test).expand() << endl;
Info<<"dictionary-based substitution: " << dict << endl;
Info<< "expandDict: " << stringOps::expandDict(test, dict) << endl;
string test2("~OpenFOAM/controlDict");
Info<< test2 << " => " << test2.expand() << endl;