Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
|
#include <G4String.hh>
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 &&) | |
G4String & | operator= (const G4String &) |
G4String & | operator= (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. | |
Definition at line 61 of file G4String.hh.
Enumerator | |
---|---|
exact | |
ignoreCase |
Definition at line 66 of file G4String.hh.
enum G4String::stripType |
Enumerator | |
---|---|
leading | |
trailing | |
both |
Definition at line 74 of file G4String.hh.
|
inlinedefault |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Implicitly convert to const char*
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.
|
inline |
Override of subscript operator for int
to suppress C2666 errors with MSVC.
operator const char*
that requires itThis 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 to
const char*and subscript / operators. Provision of the override with
int` 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 /
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 /
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 /
std::string::erase
instead [[deprecated("Use std::string::erase instead")]] inline G4String& remove(size_type);/ Deprecated function /
G4StrUtil::contains
instead [[deprecated("Use G4StrUtil::contains instead")]] inline G4bool contains(const std::string&) const;/ Deprecated function /
G4StrUtil::contains
instead [[deprecated("Use G4StrUtil::contains instead")]] inline G4bool contains(char) const;/ Deprecated function /
G4StrUtil
functions instead [[deprecated("Use G4StrUtil::{lstrip,rstrip,strip}_copy instead")]] [[nodiscard]] inline G4String strip(stripType strip_Type = trailing, char ch = ' ');/ Deprecated function /
G4StrUtil
functions instead [[deprecated("Use G4StrUtil::to_lower/to_lower_copy instead")]] inline void toLower();/ Deprecated function /
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). / /
G4String
namespace G4StrUtil { / Convert string to lowercase /[in,out] | str | the string to lowercase inline void to_lower(G4String& str); |
/ Return lowercased copy of string /
[in] | str | the string to lowercase / |
str
inline G4String to_lower_copy(G4String str);/ Convert string to uppercase /
[in,out] | str | the string to uppercase inline void to_upper(G4String& str); |
/ Return uppercase copy of string /
[in] | str | the string to upper case / |
str
inline G4String to_upper_copy(G4String str);/ Remove leading characters from string /
[in,out] | str | string to strip / |
[in] | ch | character to remove / |
str
has any leading sequence of ch
removed void lstrip(G4String& str, char ch = ' ');/ Remove trailing characters from string /
[in,out] | str | string to strip / |
[in] | ch | character to remove / |
str
has any trailing sequence of ch
removed void rstrip(G4String& str, char ch = ' ');/ Remove leading and trailing characters from string /
[in,out] | str | string to strip / |
[in] | ch | character to remove / |
str
has any leading and trailing sequence of ch
removed void strip(G4String& str, char ch = ' ');/ Return copy of string with leading characters removed /
[in] | str | string to copy and strip / |
[in] | ch | character to remove / |
str
with any leading sequence of ch
removed G4String lstrip_copy(G4String str, char ch = ' ');/ Return copy of string with trailing characters removed /
[in] | str | string to copy and strip / |
[in] | ch | character to remove / |
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 /
[in] | str | string to copy and strip / |
[in] | ch | character to remove / |
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 /
[in] | str | string to be checked / |
[in] | ss | substring to check for / |
true | if str contains ss / |
false | otherwise 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. /
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. / /
[in] | lhs | the first string in the comparison / |
[in] | rhs | the second string in the comparison / |
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 /
[in] | str | string to be checked / |
[in] | ss | prefix to check for / |
true | if str starts with ss / |
false | otherwise 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. /
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 /
[in] | str | string to be checked / |
[in] | ss | suffix to check for / |
true | if str ends with ss / |
false | otherwise 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. / /
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. / /[in,out] | str | string to erase characters from / |
[in] | index | position to start removal from / |
[in] | count | number of characters to remove / |
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 / /
std::getline
instead of this / function, plus G4StrUtil::lstrip
if leading whitespace removal is required. / /[in] | is | input stream to read from / |
[in,out] | str | string to read into / |
[in] | skipWhite | if true, discard leading whitespace from is / |
is