MCPcopy Create free account
hub / github.com/OpenFOAM/OpenFOAM-dev / main

Function main

applications/test/string/Test-string.C:39–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37// Main program:
38
39int main(int argc, char *argv[])
40{
41 string test
42 (
43 " $HOME kjhkjhkjh \" \\$HOME/tyetyery $; ${FOAM_RUN} \n $; hkjh;"
44 " $(DONOTSUBST) some other <${USER}> with '${__UNKNOWN:-some default}'"
45 " value "
46 " or with '${HOME:+Home was set}' via :+ alternative"
47 " or with '${__UNKNOWN:+unknown}' empty"
48 );
49
50 dictionary dict;
51 dict.add("HOME", "myHome");
52
53 dictionary subDict;
54 subDict.add("value1", "test1");
55 subDict.add("value2", "test2");
56 dict.add("FOAM_RUN", subDict);
57
58
59 Info<< "string:" << test << nl << "hash:"
60 << unsigned(string::hash()(test)) << endl;
61
62 Info<<"trimLeft: " << stringOps::trimLeft(test) << endl;
63 Info<<"trimRight: " << stringOps::trimRight(test) << endl;
64 Info<<"trim: " << stringOps::trim(test) << endl;
65
66
67 // test sub-strings via iterators
68 string::const_iterator iter = test.end();
69 string::const_iterator iter2 = test.end();
70 string::size_type fnd = test.find('\\');
71
72 if (fnd != string::npos)
73 {
74 iter = test.begin() + fnd;
75 iter2 = iter + 6;
76 }
77
78 Info<< "sub-string via iterators : >";
79 while (iter != iter2)
80 {
81 Info<< *iter;
82 ++iter;
83 }
84 Info<< "<\n";
85
86 Info<< string(test).replace("kj", "zzz") << endl;
87 Info<< string(test).replace("kj", "") << endl;
88 Info<< string(test).replaceAll("kj", "zzz") << endl;
89 Info<< string(test).replaceAll("kj", "z") << endl;
90
91 Info<< "expanded: " << string(test).expand() << endl;
92
93 Info<<"dictionary-based substitution: " << dict << endl;
94 Info<< "expand dict: " << stringOps::expand(test, dict) << endl;
95
96 string test2("~OpenFOAM/controlDict");

Callers

nothing calls this directly

Calls 7

hashClass · 0.50
stringClass · 0.50
addMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
replaceMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected