stringOps.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "stringOps.H"
27 #include "OSspecific.H"
28 #include "etcFiles.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 // Find the type/position of the ":-" or ":+" alternative values
38 static inline int findParameterAlternative
39 (
40  const string& s,
42  string::size_type endPos
43 )
44 {
45  while (pos != std::string::npos)
46  {
47  pos = s.find(':', pos);
48  if (pos != std::string::npos)
49  {
50  if (pos < endPos)
51  {
52  // Nn-range: check for '+' or '-' following the ':'
53  const int altType = s[pos + 1];
54  if (altType == '+' || altType == '-')
55  {
56  return altType;
57  }
58 
59  ++pos; // Unknown/unsupported - continue at next position
60  }
61  else
62  {
63  // Out-of-range: abort
64  pos = std::string::npos;
65  }
66  }
67  }
68 
69  return 0;
70 }
71 
72 
73 // Get dictionary or (optionally) environment variable
75 (
76  const word& name,
77  const dictionary& dict,
78  const bool allowEnvVars,
79  const bool allowEmpty
80 )
81 {
82  const entry* ePtr = dict.lookupScopedEntryPtr(name, true, false);
83 
84  if (ePtr)
85  {
86  OStringStream buf;
87 
88  // Force floating point numbers to be printed with at least
89  // some decimal digits.
90  buf << scientific;
91 
93 
94  // Fail for non-primitiveEntry
95  dynamicCast<const primitiveEntry>(*ePtr).write(buf, true);
96 
97  return buf.str();
98  }
99  else if (allowEnvVars)
100  {
101  string::const_iterator iter = name.begin();
102 
103  // Search for the sub-set of characters in name which are allowed
104  // in environment variables
105  string::size_type begVar = 0;
106  string::size_type endVar = begVar;
107  while (iter != name.end() && (isalnum(*iter) || *iter == '_'))
108  {
109  ++iter;
110  ++endVar;
111  }
112 
113  const word varName(name.substr(begVar, endVar - begVar), false);
114 
115  string varValue = getEnv(varName);
116 
117  if (!allowEmpty && varValue.empty())
118  {
120  (
121  dict
122  ) << "Cannot find dictionary or environment variable "
123  << name << exit(FatalIOError);
124  }
125 
126  varValue += name.substr(endVar, name.size() - endVar);
127 
128  return varValue;
129  }
130  else
131  {
133  (
134  dict
135  ) << "Cannot find dictionary variable "
136  << name << exit(FatalIOError);
137 
138  return string::null;
139  }
140 }
141 
142 
143 // Recursively expands dictionary or environment variable starting at index
144 // in string. Updates index.
145 string expand
146 (
147  const string& s,
148  string::size_type& index,
149  const dictionary& dict,
150  const bool allowEnvVars,
151  const bool allowEmpty
152 )
153 {
154  string newString;
155 
156  while (index < s.size())
157  {
158  if (s[index] == '$' && s[index + 1] == '{')
159  {
160  // Recurse to parse variable name
161  index += 2;
162  string val = expand(s, index, dict, allowEnvVars, allowEmpty);
163  newString.append(val);
164  }
165  else if (s[index] == '}')
166  {
167  return getVariable(newString, dict, allowEnvVars, allowEmpty);
168  }
169  else
170  {
171  newString.append(string(s[index]));
172  }
173  index++;
174  }
175  return newString;
176 }
177 
178 
179 // Expand path parts of a string
181 {
182  if (!s.empty())
183  {
184  if (s[0] == '~')
185  {
186  // Expand initial ~
187  // ~/ => home directory
188  // ~OpenFOAM => site/user OpenFOAM configuration directory
189  // ~user => home directory for specified user
190 
191  string user;
192  fileName file;
193 
194  const string::size_type pos = s.find('/');
195  if (pos != string::npos)
196  {
197  user = s.substr(1, pos - 1);
198  file = s.substr(pos + 1);
199  }
200  else
201  {
202  user = s.substr(1);
203  }
204 
205  // NB: be a bit lazy and expand ~unknownUser as an
206  // empty string rather than leaving it untouched.
207  // otherwise add extra test
208  if (user == "OpenFOAM")
209  {
210  s = findEtcFile(file);
211  }
212  else
213  {
214  s = home(user)/file;
215  }
216  }
217  else if (s[0] == '.')
218  {
219  // Expand a lone '.' and an initial './' into cwd
220  if (s.size() == 1)
221  {
222  s = cwd();
223  }
224  else if (s[1] == '/')
225  {
226  s.std::string::replace(0, 1, cwd());
227  }
228  }
229  }
230 
231  return s;
232 }
233 
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 
236 } // End namespace Foam
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
241 (
242  const string& original,
243  const bool allowEmpty
244 )
245 {
246  string s(original);
247  return inplaceExpandEnvVar(s, allowEmpty);
248 }
249 
250 
252 (
253  string& s,
254  const bool allowEmpty
255 )
256 {
257  string::size_type begVar = 0;
258 
259  // Expand $VARS
260  // Repeat until nothing more is found
261  while
262  (
263  (begVar = s.find('$', begVar)) != string::npos
264  && begVar < s.size() - 1
265  )
266  {
267  if (begVar == 0 || s[begVar - 1] != '\\')
268  {
269  // Find end of first occurrence
270  string::size_type endVar = begVar;
271  string::size_type delim = 0;
272 
273  // The type/position of the ":-" or ":+" alternative values
274  int altType = 0;
275  string::size_type altPos = string::npos;
276 
277  if (s[begVar + 1] == '{')
278  {
279  endVar = s.find('}', begVar);
280  delim = 1;
281 
282  // Check for ${parameter:-word} or ${parameter:+word}
283  if (endVar != string::npos)
284  {
285  altPos = begVar;
286  altType = findParameterAlternative(s, altPos, endVar);
287  }
288  }
289  else
290  {
291  string::iterator iter = s.begin() + begVar + 1;
292 
293  while
294  (
295  iter != s.end()
296  && (isalnum(*iter) || *iter == '_')
297  )
298  {
299  ++iter;
300  ++endVar;
301  }
302  }
303 
304  if (endVar == string::npos)
305  {
306  // Likely parsed '${...' without closing '}' - abort
307  break;
308  }
309  else if (endVar == begVar)
310  {
311  // Parsed '${}' or $badChar - skip over
312  begVar = endVar + 1;
313  }
314  else
315  {
316  const word varName
317  (
318  s.substr
319  (
320  begVar + 1 + delim,
321  (
322  (altPos == string::npos ? endVar : altPos)
323  - begVar - 2*delim
324  )
325  ),
326  false
327  );
328 
329  std::string altValue;
330  if (altPos != string::npos)
331  {
332  // Had ":-" or ":+" alternative value
333  altValue = s.substr
334  (
335  altPos + 2,
336  endVar - altPos - 2*delim
337  );
338  }
339 
340  const string varValue = getEnv(varName);
341  if (varValue.size())
342  {
343  if (altPos != string::npos && altType == '+')
344  {
345  // Was found, use ":+" alternative
346  s.std::string::replace
347  (
348  begVar,
349  endVar - begVar + 1,
350  altValue
351  );
352  begVar += altValue.size();
353  }
354  else
355  {
356  // Was found, use value
357  s.std::string::replace
358  (
359  begVar,
360  endVar - begVar + 1,
361  varValue
362  );
363  begVar += varValue.size();
364  }
365  }
366  else if (altPos != string::npos)
367  {
368  // Use ":-" or ":+" alternative values
369  if (altType == '-')
370  {
371  // Was not found, use ":-" alternative
372  s.std::string::replace
373  (
374  begVar,
375  endVar - begVar + 1,
376  altValue
377  );
378  begVar += altValue.size();
379  }
380  else
381  {
382  // Was not found, ":+" alternative implies
383  // substitute with nothing
384  s.std::string::erase(begVar, endVar - begVar + 1);
385  }
386  }
387  else if (allowEmpty)
388  {
389  s.std::string::erase(begVar, endVar - begVar + 1);
390  }
391  else
392  {
394  << "Unknown variable name '" << varName << "'"
395  << exit(FatalError);
396  }
397  }
398  }
399  else
400  {
401  ++begVar;
402  }
403  }
404 
405  return inplaceExpandPath(s);
406 }
407 
408 
410 (
411  string& s,
412  const dictionary& dict,
413  const word& dictVar,
414  const char sigil
415 )
416 {
417  string::size_type begVar = 0;
418 
419  // Expand $VAR or ${VAR}
420  // Repeat until nothing more is found
421  while
422  (
423  (begVar = s.find(sigil, begVar)) != string::npos
424  && begVar < s.size() - 1
425  )
426  {
427  if (begVar == 0 || s[begVar - 1] != '\\')
428  {
429  // Find end of first occurrence
430  string::size_type endVar = begVar;
431  string::size_type begDelim = 0, endDelim = 0;
432 
433  // Get the type, if any
434  word varType;
435  if (s[begVar + 1] == '<')
436  {
437  begDelim += s.findClosing('>', begVar + 1) - begVar;
438  varType = s.substr(begVar + 2, begDelim - 2);
439  }
440 
441  // Parse any braces and find the end of the variable
442  if (s[begVar+begDelim + 1] == '{')
443  {
444  // endVar = s.find('}', begVar+begDelim);
445  endVar = s.findClosing('}', begVar+begDelim + 1);
446  begDelim += 1;
447  endDelim += 1;
448  }
449  else
450  {
451  endVar = begVar + begDelim;
452 
453  string::iterator iter = s.begin() + begVar + begDelim + 1;
454 
455  // Accept all dictionary and environment variable characters
456  while
457  (
458  iter != s.end()
459  &&
460  (
461  isalnum(*iter)
462  || *iter == '/'
463  || *iter == '!'
464  || *iter == '.'
465  || *iter == ':'
466  || *iter == '_'
467  )
468  )
469  {
470  ++iter;
471  ++endVar;
472  }
473  }
474 
475  if (endVar == string::npos)
476  {
477  // Likely parsed '${...' without closing '}' - abort
478  break;
479  }
480  else if (endVar == begVar)
481  {
482  // Parsed '${}' or $badChar - skip over
483  begVar = endVar + 1;
484  }
485  else
486  {
487  word varName
488  (
489  s.substr
490  (
491  begVar + begDelim + 1,
492  (endVar - endDelim) - (begVar + begDelim)
493  ),
494  false
495  );
496 
497  // Expand any environment variable paths in the variable name
498  inplaceExpandEnvVar(varName);
499 
500  // Lookup in the dictionary
501  const entry* ePtr = dict.lookupScopedEntryPtr
502  (
503  varName,
504  true,
505  false // Wildcards disabled. See primitiveEntry
506  );
507 
508  // Substitute if found
509  if (ePtr)
510  {
511  OStringStream buf;
512  bool compound = false;
513 
514  // Check if variable type can be obtained from the single
515  // token type and if the token is a compound
516  if (!ePtr->isDict())
517  {
518  const primitiveEntry& pe =
519  dynamicCast<const primitiveEntry>(*ePtr);
520 
521  // Check that the primitive entry is a single token
522  if (pe.size() == 1)
523  {
524  // If the variable type is not specified
525  // obtain the variable type from the token type name
526  if (varType.empty())
527  {
528  varType = pe[0].typeName();
529  }
530 
531  // Check if the token is a compound which can be
532  // accessed directly
533  compound = pe[0].isCompound();
534  }
535  }
536 
537  if (!dictVar.empty())
538  {
539  if (!varType.empty())
540  {
541  // If the dictionary is accessible and the variable
542  // type is specified or could be deduced
543  // from the value, then lookup the variable in the
544  // code, rather than substituting its value. That
545  // way we don't need to recompile this string if the
546  // value changes.
547  //
548  // Compound types have special handling
549  // to return as constant reference rather than
550  // constructing the container
551  if (compound)
552  {
553  buf << dictVar
554  << ".lookupCompoundScoped<"
555  << varType << ">"
556  << "(\"" << varName << "\", true, false)";
557  }
558  else
559  {
560  buf << dictVar
561  << ".lookupScoped<" << varType << ">"
562  << "(\"" << varName << "\", true, false)";
563  }
564  }
565  else
566  {
567  // If the dictionary is accessible but the
568  // variable type is not specified and cannot be
569  // deduced from the value issue an error
571  << "Type not specified for variable "
572  << varName << " in code string " << nl
573  << " " << s << nl
574  << "Variable " << varName << " expands to "
575  << nl;
576 
577  if (ePtr->isDict())
578  {
579  ePtr->dict().write(FatalIOError, false);
580  }
581  else
582  {
583  dynamicCast<const primitiveEntry>(*ePtr)
584  .write(FatalIOError, true);
585  }
586 
588  }
589  }
590  else
591  {
592  if (!varType.empty())
593  {
594  // If the dictionary is not accessible but the
595  // type is known, then read the substituted value
596  // from a string
597  buf << "Foam::read<" << varType << ">(\"";
598  }
599 
600  // If the dictionary is not accessible and/or the type
601  // is not known, then we need to substitute the
602  // variable's value
603 
604  // Make sure floating point values print with at least
605  // some decimal points
606  buf << scientific;
607  buf.precision(IOstream::defaultPrecision());
608 
609  // Write the dictionary or primitive entry.
610  // Fail if anything else.
611  if (ePtr->isDict())
612  {
613  ePtr->dict().write(buf, false);
614  }
615  else
616  {
617  dynamicCast<const primitiveEntry>(*ePtr)
618  .write(buf, true);
619  }
620 
621  if (!varType.empty())
622  {
623  // Close the string and read function as necessary
624  buf << "\")";
625  }
626  }
627 
628  s.std::string::replace
629  (
630  begVar,
631  endVar - begVar + 1,
632  buf.str()
633  );
634  begVar += buf.str().size();
635  }
636  else
637  {
638  // Not found. Leave original string untouched.
639  begVar = endVar + 1;
640  }
641  }
642  }
643  else
644  {
645  ++begVar;
646  }
647  }
648 
649  return s;
650 }
651 
652 
654 (
655  string& s,
657  const char sigil
658 )
659 {
660  string::size_type begVar = 0;
661 
662  // Expand $VAR or ${VAR}
663  // Repeat until nothing more is found
664  while
665  (
666  (begVar = s.find(sigil, begVar)) != string::npos
667  && begVar < s.size() - 1
668  )
669  {
670  if (begVar == 0 || s[begVar - 1] != '\\')
671  {
672  // Find end of first occurrence
673  string::size_type endVar = begVar;
674  string::size_type delim = 0;
675 
676  if (s[begVar + 1] == '{')
677  {
678  endVar = s.findClosing('}', begVar + 1);
679  delim = 1;
680  }
681  else
682  {
683  string::iterator iter = s.begin() + begVar + 1;
684 
685  // Accept all dictionary and environment variable characters
686  while
687  (
688  iter != s.end()
689  &&
690  (
691  isalnum(*iter)
692  || *iter == '/'
693  || *iter == '!'
694  || *iter == '.'
695  || *iter == ':'
696  || *iter == '_'
697  )
698  )
699  {
700  ++iter;
701  ++endVar;
702  }
703  }
704 
705  if (endVar == string::npos)
706  {
707  // Likely parsed '${...' without closing '}' - abort
708  break;
709  }
710  else if (endVar == begVar)
711  {
712  // Parsed '${}' or $badChar - skip over
713  begVar = endVar + 1;
714  }
715  else
716  {
717  const word varName
718  (
719  s.substr
720  (
721  begVar + 1 + delim,
722  endVar - begVar - 2*delim
723  ),
724  false
725  );
726 
727  // Lookup in the table
729  mapping.find(varName);
730 
731  // Substitute if found
733  {
734  s.std::string::replace
735  (
736  begVar,
737  endVar - begVar + 1,
738  *fnd
739  );
740  begVar += (*fnd).size();
741  }
742  else
743  {
744  // Not found. Remove.
745  s.std::string::erase(begVar, endVar - begVar + 1);
746  }
747  }
748  }
749  else
750  {
751  ++begVar;
752  }
753  }
754 
755  return s;
756 }
757 
758 
760 (
761  string& s,
762  const dictionary& dict,
763  const bool allowEnvVars,
764  const bool allowEmpty,
765  const char sigil
766 )
767 {
768  string::size_type begVar = 0;
769 
770  // Expand $VAR or ${VAR}
771  // Repeat until nothing more is found
772  while
773  (
774  (begVar = s.find(sigil, begVar)) != string::npos
775  && begVar < s.size() - 1
776  )
777  {
778  if (begVar == 0 || s[begVar - 1] != '\\')
779  {
780  if (s[begVar + 1] == '{')
781  {
782  // Recursive variable expansion mode
783  label stringStart = begVar;
784  begVar += 2;
785  string varValue
786  (
787  expand
788  (
789  s,
790  begVar,
791  dict,
792  allowEnvVars,
793  allowEmpty
794  )
795  );
796 
797  s.std::string::replace
798  (
799  stringStart,
800  begVar - stringStart + 1,
801  varValue
802  );
803 
804  begVar = stringStart+varValue.size();
805  }
806  else
807  {
808  string::iterator iter = s.begin() + begVar + 1;
809 
810  // Accept all dictionary and environment variable characters
811  string::size_type endVar = begVar;
812  while
813  (
814  iter != s.end()
815  &&
816  (
817  isalnum(*iter)
818  || *iter == '/'
819  || *iter == '!'
820  || *iter == '.'
821  || *iter == ':'
822  || *iter == '_'
823  )
824  )
825  {
826  ++iter;
827  ++endVar;
828  }
829 
830  const word varName
831  (
832  s.substr
833  (
834  begVar + 1,
835  endVar - begVar
836  ),
837  false
838  );
839 
840  string varValue
841  (
843  (
844  varName,
845  dict,
846  allowEnvVars,
847  allowEmpty
848  )
849  );
850 
851  s.std::string::replace
852  (
853  begVar,
854  varName.size() + 1,
855  varValue
856  );
857  begVar += varValue.size();
858  }
859  }
860  else
861  {
862  ++begVar;
863  }
864  }
865 
866  return inplaceExpandPath(s);
867 }
868 
869 
871 {
872  if (!s.empty())
873  {
874  string::size_type beg = 0;
875  while (beg < s.size() && isspace(s[beg]))
876  {
877  ++beg;
878  }
879 
880  if (beg)
881  {
882  return s.substr(beg);
883  }
884  }
885 
886  return s;
887 }
888 
889 
891 {
892  if (!s.empty())
893  {
894  string::size_type beg = 0;
895  while (beg < s.size() && isspace(s[beg]))
896  {
897  ++beg;
898  }
899 
900  if (beg)
901  {
902  s.erase(0, beg);
903  }
904  }
905 
906  return s;
907 }
908 
909 
911 {
912  if (!s.empty())
913  {
914  string::size_type sz = s.size();
915  while (sz && isspace(s[sz - 1]))
916  {
917  --sz;
918  }
919 
920  if (sz < s.size())
921  {
922  return s.substr(0, sz);
923  }
924  }
925 
926  return s;
927 }
928 
929 
931 {
932  if (!s.empty())
933  {
934  string::size_type sz = s.size();
935  while (sz && isspace(s[sz - 1]))
936  {
937  --sz;
938  }
939 
940  s.resize(sz);
941  }
942 
943  return s;
944 }
945 
946 
947 Foam::string Foam::stringOps::trim(const string& original)
948 {
949  return trimLeft(trimRight(original));
950 }
951 
952 
954 {
957 
958  return s;
959 }
960 
961 
963 (
964  const string& message,
965  const string::size_type nLength,
966  const string::size_type nIndent
967 )
968 {
969  const string indent(nIndent, token::SPACE);
970 
971  string result;
972 
973  word::size_type i0 = 0, i1 = 0;
974  while (true)
975  {
976  const word::size_type iNewLine =
977  message.find_first_of(token::NL, i1);
978  const word::size_type iSpace =
979  message.find_first_of(token::SPACE, i1);
980 
981  // New line next
982  if
983  (
984  iNewLine != string::npos
985  && (iSpace == string::npos || iNewLine < iSpace)
986  )
987  {
988  result += indent + message.substr(i0, iNewLine - i0) + '\n';
989  i0 = i1 = iNewLine + 1;
990  }
991 
992  // Space next
993  else if (iSpace != string::npos)
994  {
995  if (iSpace - i0 > nLength - nIndent)
996  {
997  result += indent + message.substr(i0, i1 - i0) + '\n';
998  i0 = i1;
999  }
1000  else
1001  {
1002  i1 = iSpace + 1;
1003  }
1004  }
1005 
1006  // End of string
1007  else
1008  {
1009  result += indent + message.substr(i0);
1010  break;
1011  }
1012  }
1013 
1014  return result;
1015 }
1016 
1017 
1018 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
An STL-conforming const_iterator.
Definition: HashTable.H:498
An STL-conforming hash table.
Definition: HashTable.H:127
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:167
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:458
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:262
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:211
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present,.
Definition: dictionary.C:737
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:68
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:156
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
A class for handling file names.
Definition: fileName.H:82
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
A class for handling character strings derived from std::string.
Definition: string.H:79
static const string null
An empty string.
Definition: string.H:88
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
Functions to search 'etc' directories for configuration files etc.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
string & inplaceExpandCodeString(string &, const dictionary &dict, const word &dictVar="dict", const char sigil='$')
Inplace expand occurrences of variables according to the dictionary.
Definition: stringOps.C:410
string & inplaceTrimRight(string &)
Trim trailing whitespace inplace.
Definition: stringOps.C:930
string trim(const string &)
Return string trimmed of leading and trailing whitespace.
Definition: stringOps.C:947
string & inplaceExpandCodeTemplate(string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Inplace expand occurrences of variables according to the mapping.
Definition: stringOps.C:654
string & inplaceExpandEnvVar(string &, const bool allowEmpty=false)
Expand all occurrences of environment variables and paths.
Definition: stringOps.C:252
string expandEnvVar(const string &, const bool allowEmpty=false)
Expand all occurrences of environment variables and paths.
Definition: stringOps.C:241
string & inplaceExpandEntry(string &s, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty, const char sigil='$')
Inplace expand occurrences of variables according to the dictionary.
Definition: stringOps.C:760
string trimRight(const string &)
Return string trimmed of trailing whitespace.
Definition: stringOps.C:910
string breakIntoIndentedLines(const string &str, const string::size_type nLength=80, const string::size_type nIndent=0)
Break a string up into indented lines.
Definition: stringOps.C:963
string trimLeft(const string &)
Return string trimmed of leading whitespace.
Definition: stringOps.C:870
string & inplaceTrim(string &)
Trim leading and trailing whitespace inplace.
Definition: stringOps.C:953
string & inplaceTrimLeft(string &)
Trim leading whitespace inplace.
Definition: stringOps.C:890
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
fileName cwd()
Return current working directory path name.
Definition: POSIX.C:241
dimensionedScalar pos(const dimensionedScalar &ds)
Foam::string & inplaceExpandPath(string &s)
Definition: stringOps.C:180
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
fileName findEtcFile(const fileName &, bool mandatory=false)
Search for a file using findEtcFiles.
Definition: etcFiles.C:252
static int findParameterAlternative(const string &s, string::size_type &pos, string::size_type endPos)
Definition: stringOps.C:39
IOstream & scientific(IOstream &io)
Definition: IOstream.H:579
string getEnv(const word &)
Return environment variable of given name.
Definition: POSIX.C:97
string getVariable(const word &name, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty)
Definition: stringOps.C:75
IOerror FatalIOError
error FatalError
bool isspace(char c)
Definition: char.H:53
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
fileName home()
Return home directory path name for the current user.
Definition: POSIX.C:186
static const char nl
Definition: Ostream.H:266
string expand(const string &s, string::size_type &index, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty)
Definition: stringOps.C:146
dictionary dict