Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4StrUtil Namespace Reference

Query and manipulation functions for G4String. More...

Functions

void to_lower (G4String &str)
 Convert string to lowercase.
 
G4String to_lower_copy (G4String str)
 Return lowercased copy of string.
 
void to_upper (G4String &str)
 Convert string to uppercase.
 
G4String to_upper_copy (G4String str)
 Return uppercase copy of string.
 
void lstrip (G4String &str, char ch=' ')
 Remove leading characters from string.
 
void rstrip (G4String &str, char ch=' ')
 Remove trailing characters from string.
 
void strip (G4String &str, char ch=' ')
 Remove leading and trailing characters from string.
 
G4String lstrip_copy (G4String str, char ch=' ')
 Return copy of string with leading characters removed.
 
G4String rstrip_copy (G4String str, char ch=' ')
 Return copy of string with trailing characters removed.
 
G4String strip_copy (G4String str, char ch=' ')
 Return copy of string with leading and trailing characters removed.
 
G4bool contains (const G4String &str, std::string_view ss)
 Check if a string contains a given substring.
 
G4bool contains (const G4String &str, char ss)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
G4bool contains (const G4String &str, const char *ss)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
G4bool contains (const G4String &str, const G4String &ss)
 
G4int icompare (std::string_view lhs, std::string_view rhs)
 Case insensitive comparison of two strings.
 
bool starts_with (const G4String &str, std::string_view ss)
 Return true if a string starts with a given prefix.
 
bool starts_with (const G4String &str, G4String::value_type ss)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool starts_with (const G4String &str, const char *ss)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool starts_with (const G4String &str, const G4String &ss)
 
bool ends_with (const G4String &str, std::string_view ss)
 Return true if a string ends with a given suffix.
 
bool ends_with (const G4String &str, G4String::value_type ss)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool ends_with (const G4String &str, const char *ss)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool ends_with (const G4String &str, const G4String &ss)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void safe_erase (G4String &str, G4String::size_type index=0, G4String::size_type count=G4String::npos)
 Remove specified in-range characters from string.
 
std::istream & readline (std::istream &is, G4String &str, G4bool skipWhite=true)
 Read characters into a G4String from an input stream until end-of-line.
 

Detailed Description

Query and manipulation functions for G4String.

Additional free functions that are not part of the std::string interface as of the minimum C++ standard supported by Geant4 (currently C++17).

See also
G4String

Function Documentation

◆ contains() [1/4]

G4bool G4StrUtil::contains ( const G4String str,
char  ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ contains() [2/4]

G4bool G4StrUtil::contains ( const G4String str,
const char *  ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ contains() [3/4]

G4bool G4StrUtil::contains ( const G4String str,
const G4String ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note
this overload is required to resolve ambiguity between the signatures taking std::string_view and const char* substring arguments. G4String currently provides implicit conversion to const char*, which makes the calls ambiguous due to std::string's implicit conversion to std::string_view

◆ contains() [4/4]

◆ ends_with() [1/4]

bool G4StrUtil::ends_with ( const G4String str,
const char *  ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ends_with() [2/4]

bool G4StrUtil::ends_with ( const G4String str,
const G4String ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ends_with() [3/4]

bool G4StrUtil::ends_with ( const G4String str,
G4String::value_type  ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ends_with() [4/4]

bool G4StrUtil::ends_with ( const G4String str,
std::string_view  ss 
)
inline

Return true if a string ends with a given suffix.

Parameters
[in]strstring to be checked
[in]sssuffix to check for
Return values
trueif str ends with ss
falseotherwise

◆ icompare()

G4int G4StrUtil::icompare ( std::string_view  lhs,
std::string_view  rhs 
)
inline

Case insensitive comparison of two strings.

Converts both input arguments to lower case and returns the result of std::string::compare with these values.

Parameters
[in]lhsthe first string in the comparison
[in]rhsthe second string in the comparison
Returns
negative(positive) G4int if lowercased lhs appears before(after) lowercased rhs in lexicographical order, zero if both compare equivalent after lowercasing.

Referenced by G4VisCommandSceneHandlerCreate::SetNewValue(), and G4VisCommandsViewerSet::SetNewValue().

◆ lstrip()

void G4StrUtil::lstrip ( G4String str,
char  ch = ' ' 
)

Remove leading characters from string.

Parameters
[in,out]strstring to strip
[in]chcharacter to remove
Postcondition
str has any leading sequence of ch removed

Referenced by G4UItcsh::CompleteCommand(), and G4UItcsh::ListMatchedCommand().

◆ lstrip_copy()

G4String G4StrUtil::lstrip_copy ( G4String  str,
char  ch = ' ' 
)

Return copy of string with leading characters removed.

Parameters
[in]strstring to copy and strip
[in]chcharacter to remove
Returns
copy of str with any leading sequence of ch removed

Referenced by G4VBasicShell::ApplyShellCommand(), G4UItcsh::CompleteCommand(), and G4UItcsh::ListMatchedCommand().

◆ readline()

std::istream & G4StrUtil::readline ( std::istream &  is,
G4String str,
G4bool  skipWhite = true 
)
inline

Read characters into a G4String from an input stream until end-of-line.

Deprecated:
It is strongly recommended to use std::getline instead of this function, plus G4StrUtil::lstrip if leading whitespace removal is required.
Parameters
[in]isinput stream to read from
[in,out]strstring to read into
[in]skipWhiteif true, discard leading whitespace from is
Returns
is

Referenced by G3CLRead(), and G4UIcsh::GetCommandLineString().

◆ rstrip()

void G4StrUtil::rstrip ( G4String str,
char  ch = ' ' 
)

Remove trailing characters from string.

Parameters
[in,out]strstring to strip
[in]chcharacter to remove
Postcondition
str has any trailing sequence of ch removed

Referenced by G4UIcsh::GetCommandLineString(), and G4RadioactiveDecay::LoadDecayTable().

◆ rstrip_copy()

G4String G4StrUtil::rstrip_copy ( G4String  str,
char  ch = ' ' 
)

Return copy of string with trailing characters removed.

Parameters
[in]strstring to copy and strip
[in]chcharacter to remove
Returns
copy of str with any trailing sequence of ch removed

◆ safe_erase()

void G4StrUtil::safe_erase ( G4String str,
G4String::size_type  index = 0,
G4String::size_type  count = G4String::npos 
)
inline

Remove specified in-range characters from string.

Equivalent to std::string::erase(index, count) with erasure only occuring if index <= size(). When index > size() the string is left unmodified.

Deprecated:
It is strongly recommended to use std::string::erase if the start index is already checked, or otherwise known, to be in range. Otherwise, implement the index-size comparison instead of using this function.
Parameters
[in,out]strstring to erase characters from
[in]indexposition to start removal from
[in]countnumber of characters to remove
Postcondition
str is unchanged if index > str.size(), otherwise str has min(count, str.size() - index) characters removed starting at index

◆ starts_with() [1/4]

bool G4StrUtil::starts_with ( const G4String str,
const char *  ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ starts_with() [2/4]

bool G4StrUtil::starts_with ( const G4String str,
const G4String ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note
this overload is required to resolve ambiguity between the signatures taking std::string_view and const char* substring arguments. G4String currently provides implicit conversion to const char*, which makes the calls ambiguous due to std::string's implicit conversion to std::string_view

◆ starts_with() [3/4]

bool G4StrUtil::starts_with ( const G4String str,
G4String::value_type  ss 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ starts_with() [4/4]

bool G4StrUtil::starts_with ( const G4String str,
std::string_view  ss 
)
inline

Return true if a string starts with a given prefix.

Parameters
[in]strstring to be checked
[in]ssprefix to check for
Return values
trueif str starts with ss
falseotherwise

◆ strip()

void G4StrUtil::strip ( G4String str,
char  ch = ' ' 
)

Remove leading and trailing characters from string.

Parameters
[in,out]strstring to strip
[in]chcharacter to remove
Postcondition
str has any leading and trailing sequence of ch removed

Referenced by G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate(), G4VViewer::G4VViewer(), G4VViewer::SetName(), G4VisCommandViewerClone::SetNewValue(), G4VisCommandViewerCreate::SetNewValue(), and G4VBasicShell::TerminalHelp().

◆ strip_copy()

G4String G4StrUtil::strip_copy ( G4String  str,
char  ch = ' ' 
)

◆ to_lower()

void G4StrUtil::to_lower ( G4String str)
inline

Convert string to lowercase.

Parameters
[in,out]strthe string to lowercase

Referenced by G4LatticeReader::ProcessToken(), G4LatticeReader::ReadMapInfo(), and G4INCLXXInterfaceMessenger::SetNewValue().

◆ to_lower_copy()

G4String G4StrUtil::to_lower_copy ( G4String  str)
inline

Return lowercased copy of string.

Parameters
[in]strthe string to lowercase
Returns
lowercased copy of str

Referenced by G4Colour::AddToMap(), G4UIExecutive::G4UIExecutive(), G4Colour::GetColour(), G4BaseFileManager::GetFileType(), G4VisManager::GetVerbosityValue(), and G4VisFilterManager< T >::SetMode().

◆ to_upper()

void G4StrUtil::to_upper ( G4String str)
inline

Convert string to uppercase.

Parameters
[in,out]strthe string to uppercase

◆ to_upper_copy()

G4String G4StrUtil::to_upper_copy ( G4String  str)
inline

Return uppercase copy of string.

Parameters
[in]strthe string to upper case
Returns
uppercased copy of str

Referenced by G4UIcommand::ConvertToBool(), and G4UImessenger::StoB().