string Class Reference

A class for handling character strings derived from std::string. More...

Inheritance diagram for string:
Collaboration diagram for string:

Classes

class  hash
 Hashing function class, shared by all the derived classes. More...
 

Public Member Functions

 string ()
 Construct null. More...
 
 string (const std::string &)
 Construct from std::string. More...
 
 string (const string &)
 Copy constructor. More...
 
 string (string &&)
 Move constructor. More...
 
 string (const char *)
 Construct as copy of character array. More...
 
 string (const UList< char > &)
 Construct as copy of UList of character. More...
 
 string (const char *, const size_type)
 Construct as copy of specified number of characters. More...
 
 string (const char)
 Construct from a single character. More...
 
 string (const size_type, const char)
 Construct from copies of a single character. More...
 
 string (Istream &)
 Construct from Istream. More...
 
size_type count (const char) const
 Count and return the number of a given character in the string. More...
 
bool match (const std::string &) const
 True when strings match literally. More...
 
stringreplace (const string &oldStr, const string &newStr, size_type start=0)
 Replace first occurrence of sub-string oldStr with newStr. More...
 
stringreplaceAll (const string &oldStr, const string &newStr, size_type start=0)
 Replace all occurrences of sub-string oldStr with newStr. More...
 
stringexpand (const bool allowEmpty=false)
 Expand initial tildes and all occurrences of environment variables. More...
 
bool removeRepeated (const char)
 Remove repeated characters returning true if string changed. More...
 
string removeRepeated (const char) const
 Return string with repeated characters removed. More...
 
bool removeTrailing (const char)
 Remove trailing character returning true if string changed. More...
 
string removeTrailing (const char) const
 Return string with trailing character removed. More...
 
bool removeTrailing (const string &)
 Remove trailing string returning true if string changed. More...
 
string removeTrailing (const string &) const
 Return string with trailing string removed. More...
 
void strip (const string &)
 Strip characters from the start and end of the string. More...
 
string operator() (const size_type i, const size_type n) const
 Return the sub-string from the i-th character for n characters. More...
 
string operator() (const size_type n) const
 Return the sub-string from the first character for n characters. More...
 
void operator= (const string &)
 
void operator= (string &&)
 
template<class String >
Foam::string quotemeta (const string &str, const char quote)
 

Static Public Member Functions

template<class String >
static bool valid (const string &)
 Is this string type valid? More...
 
template<class String >
static bool meta (const string &, const char quote='\\')
 Does this string have particular meta-characters? More...
 
template<class String >
static bool stripInvalid (string &)
 Strip invalid characters from the given string. More...
 
template<class String >
static String validate (const string &)
 Return a valid String from the given string. More...
 
template<class String >
static string quotemeta (const string &, const char quote='\\')
 Return a String with quoted meta-characters from the given string. More...
 

Static Public Attributes

static const char *const typeName = "string"
 
static int debug
 
static const string null
 An empty string. More...
 

Friends

Istreamoperator>> (Istream &, string &)
 
Ostreamoperator<< (Ostream &, const string &)
 

Detailed Description

A class for handling character strings derived from std::string.

Strings may contain any characters and therefore are delimited by quotes for IO : "any list of characters".

Used as a base class for word and fileName.

See also
Foam::findEtcFile() for information about the site/user OpenFOAM configuration directory
Source files

Definition at line 76 of file string.H.

Constructor & Destructor Documentation

◆ string() [1/10]

string ( )
inline

Construct null.

Definition at line 30 of file stringI.H.

Referenced by fileName::caseName(), and string::hash::hash().

Here is the caller graph for this function:

◆ string() [2/10]

string ( const std::string &  str)
inline

Construct from std::string.

Definition at line 34 of file stringI.H.

◆ string() [3/10]

string ( const string str)
inline

Copy constructor.

Definition at line 40 of file stringI.H.

◆ string() [4/10]

string ( string &&  str)
inline

Move constructor.

Definition at line 46 of file stringI.H.

◆ string() [5/10]

string ( const char *  str)
inline

Construct as copy of character array.

Definition at line 52 of file stringI.H.

◆ string() [6/10]

string ( const UList< char > &  str)

Construct as copy of UList of character.

Definition at line 39 of file string.C.

◆ string() [7/10]

string ( const char *  str,
const size_type  len 
)
inline

Construct as copy of specified number of characters.

Definition at line 58 of file stringI.H.

◆ string() [8/10]

string ( const char  c)
inline

Construct from a single character.

Definition at line 64 of file stringI.H.

◆ string() [9/10]

string ( const size_type  len,
const char  c 
)
inline

Construct from copies of a single character.

Definition at line 70 of file stringI.H.

◆ string() [10/10]

string ( Istream is)

Construct from Istream.

Definition at line 31 of file stringIO.C.

Member Function Documentation

◆ count()

Foam::string::size_type count ( const char  c) const

Count and return the number of a given character in the string.

Definition at line 47 of file string.C.

References string::replace().

Referenced by string::hash::hash(), string::strip(), OSstream::write(), and OSstream::writeQuoted().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid()

bool valid ( const string str)
inlinestatic

Is this string type valid?

Definition at line 79 of file stringI.H.

Referenced by string::hash::hash().

Here is the caller graph for this function:

◆ meta()

bool meta ( const string str,
const char  quote = '\\' 
)
inlinestatic

Does this string have particular meta-characters?

The meta characters can be optionally quoted.

Definition at line 127 of file stringI.H.

Referenced by string::hash::hash().

Here is the caller graph for this function:

◆ stripInvalid()

bool stripInvalid ( string str)
inlinestatic

Strip invalid characters from the given string.

Definition at line 93 of file stringI.H.

References Foam::constant::universal::c.

Referenced by string::hash::hash().

Here is the caller graph for this function:

◆ validate()

String validate ( const string str)
inlinestatic

Return a valid String from the given string.

Definition at line 187 of file stringI.H.

Referenced by string::hash::hash().

Here is the caller graph for this function:

◆ quotemeta() [1/2]

static string quotemeta ( const string ,
const char  quote = '\\' 
)
inlinestatic

Return a String with quoted meta-characters from the given string.

Referenced by string::hash::hash().

Here is the caller graph for this function:

◆ match()

bool match ( const std::string &  str) const
inline

True when strings match literally.

Definition at line 194 of file stringI.H.

Referenced by string::hash::hash(), and convergenceControl::residualControlIndex().

Here is the caller graph for this function:

◆ replace()

Foam::string & replace ( const string oldStr,
const string newStr,
size_type  start = 0 
)

Replace first occurrence of sub-string oldStr with newStr.

starting at start

Definition at line 64 of file string.C.

References string::replaceAll().

Referenced by fileName::caseName(), string::count(), argList::displayDoc(), string::hash::hash(), objectRegistry::rename(), cellMotionFvPatchField< Type >::updateCoeffs(), and graph::wordify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replaceAll()

Foam::string & replaceAll ( const string oldStr,
const string newStr,
size_type  start = 0 
)

Replace all occurrences of sub-string oldStr with newStr.

starting at start

Definition at line 82 of file string.C.

Referenced by string::hash::hash(), error::operator()(), Foam::printSourceFileAndLine(), and string::replace().

Here is the caller graph for this function:

◆ expand()

Foam::string & expand ( const bool  allowEmpty = false)

Expand initial tildes and all occurrences of environment variables.

Expansion includes:

  1. environment variables
    • "$VAR", "${VAR}"
  2. current directory
    • leading "./" : the current directory
  3. tilde expansion
    • leading "~/" : home directory
    • leading "~user" : home directory for specified user
    • leading "~OpenFOAM" : site/user OpenFOAM configuration directory

Any unknown entries are removed silently if allowEmpty is true

See also
Foam::findEtcFile

Definition at line 103 of file string.C.

References Foam::stringOps::inplaceExpand().

Referenced by argList::displayDoc(), string::hash::hash(), TableFileReader< Type >::read(), and triSurfaceMesh::writeObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeRepeated() [1/2]

bool removeRepeated ( const char  character)

Remove repeated characters returning true if string changed.

Definition at line 110 of file string.C.

References Foam::constant::universal::c, n, and resize().

Referenced by string::hash::hash(), and string::removeRepeated().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeRepeated() [2/2]

Foam::string removeRepeated ( const char  character) const

Return string with repeated characters removed.

Definition at line 146 of file string.C.

References string::removeRepeated().

Here is the call graph for this function:

◆ removeTrailing() [1/4]

bool removeTrailing ( const char  character)

Remove trailing character returning true if string changed.

Definition at line 154 of file string.C.

References n, and resize().

Referenced by string::hash::hash(), Reaction< ReactionThermo >::New(), and string::removeTrailing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeTrailing() [2/4]

Foam::string removeTrailing ( const char  character) const

Return string with trailing character removed.

Definition at line 169 of file string.C.

References string::removeTrailing().

Here is the call graph for this function:

◆ removeTrailing() [3/4]

bool removeTrailing ( const string str)

Remove trailing string returning true if string changed.

Definition at line 177 of file string.C.

References n, string::operator()(), and resize().

Here is the call graph for this function:

◆ removeTrailing() [4/4]

Foam::string removeTrailing ( const string str) const

Return string with trailing string removed.

Definition at line 192 of file string.C.

References string::removeTrailing().

Here is the call graph for this function:

◆ strip()

void strip ( const string str)

Strip characters from the start and end of the string.

Definition at line 200 of file string.C.

References string::count(), and resize().

Referenced by string::hash::hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [1/2]

Foam::string operator() ( const size_type  i,
const size_type  n 
) const
inline

Return the sub-string from the i-th character for n characters.

Definition at line 204 of file stringI.H.

References n.

Referenced by string::removeTrailing().

Here is the caller graph for this function:

◆ operator()() [2/2]

Foam::string operator() ( const size_type  n) const
inline

Return the sub-string from the first character for n characters.

Definition at line 213 of file stringI.H.

◆ operator=() [1/2]

void operator= ( const string str)
inline

◆ operator=() [2/2]

void operator= ( string &&  str)
inline

Definition at line 235 of file stringI.H.

◆ quotemeta() [2/2]

Foam::string quotemeta ( const string str,
const char  quote 
)
inline

Definition at line 151 of file stringI.H.

Friends And Related Function Documentation

◆ operator>>

Istream& operator>> ( Istream ,
string  
)
friend

Referenced by string::hash::hash().

◆ operator<<

Ostream& operator<< ( Ostream ,
const string  
)
friend

Referenced by string::hash::hash().

Member Data Documentation

◆ typeName

const char *const typeName = "string"
static

Definition at line 84 of file string.H.

Referenced by token::anyStringToken(), and token::stringToken().

◆ debug

int debug
static

Definition at line 85 of file string.H.

◆ null

const Foam::string null
static

The documentation for this class was generated from the following files: