Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4String Class Reference

#include <G4String.hh>

+ Inheritance diagram for G4String:

Public Types

enum  caseCompare { exact , ignoreCase }
 
enum  stripType { leading , trailing , both }
 

Public Member Functions

 G4String ()=default
 
 G4String (const std::string &)
 
 G4String (const G4String &)
 
 G4String (std::string &&)
 
 G4String (G4String &&)
 
G4Stringoperator= (const G4String &)
 
G4Stringoperator= (G4String &&)
 
 operator const char * () const
 Implicitly convert to const char*
 
std::istream & readline (std::istream &is, G4String &str, G4bool skipWhite=true)
 Override of subscript operator for int to suppress C2666 errors with MSVC.
 

Detailed Description

Definition at line 61 of file G4String.hh.

Member Enumeration Documentation

◆ caseCompare

Deprecated
Will be removed in future release
Enumerator
exact 
ignoreCase 

Definition at line 66 of file G4String.hh.

67 {
68 exact,
70 };
@ ignoreCase
Definition G4String.hh:69

◆ stripType

Deprecated
Will be removed in future release
Enumerator
leading 
trailing 
both 

Definition at line 74 of file G4String.hh.

75 {
76 leading,
78 both
79 };

Constructor & Destructor Documentation

◆ G4String() [1/5]

G4String::G4String ( )
inlinedefault

◆ G4String() [2/5]

G4String::G4String ( const std::string & )
inline

◆ G4String() [3/5]

G4String::G4String ( const G4String & )
inline

◆ G4String() [4/5]

G4String::G4String ( std::string && )
inline

◆ G4String() [5/5]

G4String::G4String ( G4String && )
inline

Member Function Documentation

◆ operator const char *()

G4String::operator const char * ( ) const
inline

Implicitly convert to const char*

Deprecated
Will be removed in future releases for std::string compliance If passing G4String to functions requiring const char*, use std::string::c_str to explicitly convert. G4String also implicitly converts to std::string_view to match the std::string interface.

◆ operator=() [1/2]

G4String & G4String::operator= ( const G4String & )
inline

◆ operator=() [2/2]

G4String & G4String::operator= ( G4String && )
inline

◆ readline()

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

Override of subscript operator for int to suppress C2666 errors with MSVC.

Deprecated
Will be removed at the same time as operator const char* that requires it

This override is required because of G4String's provision of an implicit conversion operator to const char*. Together with the subscript operator and C++'s built-in operator[](const char*, int) operator, use of G4String::operator[] will trigger / [MSVC error C2666](https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2666?view=msvc-170) / This is a known issue with mixing implicit conversion toconst char*and subscript / operators. Provision of the override withint` argument is thus a workaround / until the conversion operator is removed. inline reference operator[](int);

/This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
inline const_reference operator[](int) const;

/ Deprecated function /

Deprecated
Use std::string::compare or G4StrUtil::icompare instead [[deprecated("Use std::string::compare, or G4StrUtil::icompare for case-insensitive comparison")]] inline G4int compareTo(std::string_view, caseCompare mode = exact) const;

/ Deprecated function /

Deprecated
Use std::getline plus G4StrUtil::lstrip instead [[deprecated("Use std::getline instead, plus G4StrUtil::lstrip if required")]] inline std::istream& readLine(std::istream&, G4bool skipWhite = true);

/ Deprecated function /

Deprecated
Use std::string::erase instead [[deprecated("Use std::string::erase instead")]] inline G4String& remove(size_type);

/ Deprecated function /

Deprecated
Use G4StrUtil::contains instead [[deprecated("Use G4StrUtil::contains instead")]] inline G4bool contains(const std::string&) const;

/ Deprecated function /

Deprecated
Use G4StrUtil::contains instead [[deprecated("Use G4StrUtil::contains instead")]] inline G4bool contains(char) const;

/ Deprecated function /

Deprecated
Use G4StrUtil functions instead [[deprecated("Use G4StrUtil::{lstrip,rstrip,strip}_copy instead")]] [[nodiscard]] inline G4String strip(stripType strip_Type = trailing, char ch = ' ');

/ Deprecated function /

Deprecated
Use G4StrUtil functions instead [[deprecated("Use G4StrUtil::to_lower/to_lower_copy instead")]] inline void toLower();

/ Deprecated function /

Deprecated
Use G4StrUtil functions instead [[deprecated("Use G4StrUtil::to_upper/to_upper_copy instead")]] inline void toUpper(); };

/ 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 namespace G4StrUtil { / Convert string to lowercase /
Parameters
[in,out]strthe string to lowercase inline void to_lower(G4String& str);

/ Return lowercased copy of string /

Parameters
[in]strthe string to lowercase /
Returns
lowercased copy of str inline G4String to_lower_copy(G4String str);

/ Convert string to uppercase /

Parameters
[in,out]strthe string to uppercase inline void to_upper(G4String& str);

/ Return uppercase copy of string /

Parameters
[in]strthe string to upper case /
Returns
uppercased copy of str inline G4String to_upper_copy(G4String str);

/ Remove leading characters from string /

Parameters
[in,out]strstring to strip /
[in]chcharacter to remove /
Postcondition
str has any leading sequence of ch removed void lstrip(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 void rstrip(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 void strip(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 G4String lstrip_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 G4String rstrip_copy(G4String str, char ch = ' ');

/ Return copy of string with leading and trailing characters removed /

Parameters
[in]strstring to copy and strip /
[in]chcharacter to remove /
Returns
copy of str with any leading and trailing sequence of ch removed G4String strip_copy(G4String str, char ch = ' ');

/ Check if a string contains a given substring /

Parameters
[in]strstring to be checked /
[in]sssubstring to check for /
Return values
trueif str contains ss /
falseotherwise inline G4bool contains(const G4String& str, std::string_view ss);

/This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. inline 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. inline 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. /

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 inline G4bool contains(const G4String& str, const G4String& ss);

/ 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. inline G4int icompare(std::string_view lhs, std::string_view rhs);

/ 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 inline bool starts_with(const G4String& str, std::string_view ss);

/This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. inline 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. inline 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. /

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 inline bool starts_with(const G4String& str, const G4String& ss);

/ 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 inline bool ends_with(const G4String& str, std::string_view ss);

/This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. inline 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. inline 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. inline bool ends_with(const G4String& str, const G4String& ss);

/ 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 inline void safe_erase(G4String& str, G4String::size_type index = 0, G4String::size_type count = G4String::npos);

/ 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

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