Loading...
Searching...
No Matches
exprString.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2019-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "exprString.H"
29#include "stringOps.H"
30#include "expressionEntry.H"
31#include "error.H"
32
33// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
34
36(
37 std::string& str,
38 const dictionary& dict,
39 const bool stripComments
40)
41{
42 if (stripComments)
43 {
45 }
48}
49
50
51// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52
54(
55 const dictionary& dict,
56 const bool stripComments
57)
58{
59 inplaceExpand(*this, dict, stripComments);
61 #ifdef FULLDEBUG
62 (void)valid();
63 #endif
64}
65
68{
70}
71
72
74(
75 const word& keyword,
76 const dictionary& dict,
78)
79{
80 const bool ok = dict.readEntry(keyword, *this, keyType::LITERAL, readOpt);
81
82 if (ok && !empty())
83 {
84 this->expand(dict, true); // strip comments
85 }
86 else
87 {
89 }
90
91 return ok;
92}
93
94
96(
97 const word& keyword,
98 Ostream& os,
99 bool writeEmpty
100) const
101{
102 const bool ok = (writeEmpty || !empty());
103
104 if (ok)
105 {
106 if (!keyword.empty())
107 {
108 os.writeKeyword(keyword);
109 }
110
111 // Write as regular or verbatim string
112
113 token tok(*this);
114 if (!empty())
115 {
116 tok.setType(token::tokenType::VERBATIM);
117 }
118
119 os.write(tok);
120 os.endEntry();
121 }
122
123 return ok;
124}
125
126
127// ************************************************************************* //
readOption
Enumeration defining read preferences.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
static void inplaceExpand(std::string &s, const dictionary &dict)
Inplace expand expression with dictionary variables/entries.
void trim()
Inplace trim leading and trailing whitespace.
Definition exprString.C:60
bool valid() const
Check for unexpanded '$' entries. Fatal if any exist.
static void inplaceExpand(std::string &str, const dictionary &dict, const bool stripComments=true)
Inplace expansion with dictionary variables, and strip any embedded C/C++ comments.
Definition exprString.C:29
void expand(const dictionary &dict, const bool stripComments=true)
Inplace expansion with dictionary variables, and strip any embedded C/C++ comments.
Definition exprString.C:47
bool readEntry(const word &keyword, const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ)
Read/expand entry with dictionary variables, and strip any embedded C/C++ comments from the input.
Definition exprString.C:67
bool writeEntry(const word &keyword, Ostream &os, bool writeEmpty=false) const
Dictionary entry for expression string, normally suppressing empty strings. Generally uses verbatim o...
Definition exprString.C:89
@ LITERAL
String literal.
Definition keyType.H:82
A token holds an item read from Istream.
Definition token.H:70
bool setType(const tokenType tokType) noexcept
Change the token type, for similar types.
Definition tokenI.H:488
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
surface1 clear()
void inplaceRemoveComments(std::string &s)
Remove C/C++ comments inplace.
void inplaceTrim(std::string &s)
Trim leading and trailing whitespace inplace.
dictionary dict