1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 Collection of static functions to do various simple string-related
34 \*---------------------------------------------------------------------------*/
39 #include "dictionary.H"
40 #include "HashTable.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 /*---------------------------------------------------------------------------*\
48 Namespace stringOps Declaration
49 \*---------------------------------------------------------------------------*/
53 //- Expand occurences of variables according to the mapping
54 // Expansion includes:
58 // Supports default values as per the Bourne/Korn shell.
60 // "${parameter:-defValue}"
62 // If parameter is unset or null, the \c defValue is substituted.
63 // Otherwise, the value of parameter is substituted.
65 // Supports alternative values as per the Bourne/Korn shell.
67 // "${parameter:+altValue}"
69 // If parameter is unset or null, nothing is substituted.
70 // Otherwise the \c altValue is substituted.
72 // Any unknown entries are removed silently.
74 // Malformed entries (eg, brace mismatch, sigil followed by bad character)
77 // \note the leading sigil can be changed to avoid conflicts with other
82 const HashTable<string, word, string::hash>& mapping,
83 const char sigil = '$'
87 //- Inplace expand occurences of variables according to the mapping
88 // Expansion includes:
92 // Supports default values as per the Bourne/Korn shell.
94 // "${parameter:-defValue}"
96 // If parameter is unset or null, the \c defValue is substituted.
97 // Otherwise, the value of parameter is substituted.
99 // Supports alternative values as per the Bourne/Korn shell.
101 // "${parameter:+altValue}"
103 // If parameter is unset or null, nothing is substituted.
104 // Otherwise the \c altValue is substituted.
106 // Any unknown entries are removed silently.
108 // Malformed entries (eg, brace mismatch, sigil followed by bad character)
111 // \note the leading sigil can be changed to avoid conflicts with other
113 string& inplaceExpand
116 const HashTable<string, word, string::hash>& mapping,
117 const char sigil = '$'
120 //- Expand occurences of variables according to the dictionary
121 // Expansion includes:
123 // - "$VAR", "${VAR}"
125 // Any unknown entries are left as-is
127 // \note the leading sigil can be changed to avoid conflicts with other
132 const dictionary& dict,
133 const char sigil = '$'
137 //- Inplace expand occurences of variables according to the dictionary
138 // Expansion includes:
140 // - "$VAR", "${VAR}"
142 // Any unknown entries are left as-is
144 // \note the leading sigil can be changed to avoid conflicts with other
146 string& inplaceExpand
149 const dictionary& dict,
150 const char sigil = '$'
154 //- Expand initial tildes and all occurences of environment variables
155 // Expansion includes:
156 // -# environment variables
157 // - "$VAR", "${VAR}"
158 // -# current directory
159 // - leading "./" : the current directory
160 // -# tilde expansion
161 // - leading "~/" : home directory
162 // - leading "~user" : home directory for specified user
163 // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
165 // Supports default values as per the Bourne/Korn shell.
167 // "${parameter:-defValue}"
169 // If parameter is unset or null, the \c defValue is substituted.
170 // Otherwise, the value of parameter is substituted.
172 // Supports alternative values as per the Bourne/Korn shell.
174 // "${parameter:+altValue}"
176 // If parameter is unset or null, nothing is substituted.
177 // Otherwise the \c altValue is substituted.
179 // Any unknown entries are removed silently, if allowEmpty is true.
181 // Malformed entries (eg, brace mismatch, sigil followed by bad character)
189 const bool allowEmpty = false
193 //- Expand initial tildes and all occurences of environment variables
194 // Expansion includes:
195 // -# environment variables
196 // - "$VAR", "${VAR}"
197 // -# current directory
198 // - leading "./" : the current directory
199 // -# tilde expansion
200 // - leading "~/" : home directory
201 // - leading "~user" : home directory for specified user
202 // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
204 // Supports default values as per the Bourne/Korn shell.
206 // "${parameter:-defValue}"
208 // If parameter is unset or null, the \c defValue is substituted.
209 // Otherwise, the value of parameter is substituted.
211 // Supports alternative values as per the Bourne/Korn shell.
213 // "${parameter:+altValue}"
215 // If parameter is unset or null, nothing is substituted.
216 // Otherwise the \c altValue is substituted.
218 // Any unknown entries are removed silently, if allowEmpty is true.
220 // Malformed entries (eg, brace mismatch, sigil followed by bad character)
223 // Any unknown entries are removed silently if allowEmpty is true.
226 string& inplaceExpand
229 const bool allowEmpty = false
233 //- Return string trimmed of leading whitespace
234 string trimLeft(const string&);
236 //- Trim leading whitespace inplace
237 string& inplaceTrimLeft(string&);
239 //- Return string trimmed of trailing whitespace
240 string trimRight(const string&);
242 //- Trim trailing whitespace inplace
243 string& inplaceTrimRight(string&);
245 //- Return string trimmed of leading and trailing whitespace
246 string trim(const string&);
248 //- Trim leading and trailing whitespace inplace
249 string& inplaceTrim(string&);
252 } // End namespace stringOps
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 } // End namespace Foam
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 // ************************************************************************* //