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1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/include/G4String.hh (Version 11.3.0) and /global/management/include/G4String.hh (Version 10.2.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4String                                    << 
 27 //                                                 26 //
 28 // Class description:                          <<  27 // $Id: G4String.hh 95426 2016-02-10 14:54:59Z gcosmo $
 29 //                                                 28 //
 30 // Common string type for Geant4               <<  29 // 
                                                   >>  30 //---------------------------------------------------------------
                                                   >>  31 //  GEANT 4 class header file
 31 //                                                 32 //
 32 // Provides a `std::string` compliant implemen <<  33 //  G4String
 33 // strings. It currently inherits from `std::s << 
 34 // not be assumed other than that it will impl << 
 35 // as `std::string` as of the minimum C++ stan << 
 36 // (currently C++17).                          << 
 37 //                                                 34 //
 38 // It can be passed to any function accepting  <<  35 //  Class description:
 39 // arguments. Whilst it currently implements a << 
 40 // this should be considered deprecated for us << 
 41 // non-Geant4 functions taking `const char*` a << 
 42 // `std::string::c_str` member function to exp << 
 43 //                                             << 
 44 // See `std::string` for primary interfaces, ` << 
 45 //                                                 36 //
 46 // Author: G.Cosmo, 11 November 1999           <<  37 //  Definition of a Geant4 string.
 47 //-------------------------------------------- <<  38 //  Derived from the Rogue Wave implementation of RWCString;
                                                   >>  39 //  it uses intrinsically STL string.
 48                                                    40 
 49 #ifndef G4String_hh                            <<  41 //---------------------------------------------------------------
 50 #define G4String_hh 1                          << 
 51                                                    42 
 52 #include "G4Types.hh"                          <<  43 #ifndef __G4String
                                                   >>  44 #define __G4String
 53                                                    45 
 54 #include <algorithm>                           <<  46 #include <stdio.h>
 55 #include <cstdio>                              <<  47 #include <string>
 56 #include <cstring>                                 48 #include <cstring>
                                                   >>  49 
                                                   >>  50 #include "G4Types.hh"
 57 #include <iostream>                                51 #include <iostream>
 58 #include <string>                              <<  52 
 59 #include <string_view>                         <<  53 #ifdef WIN32
                                                   >>  54   #define strcasecmp _stricmp
                                                   >>  55 #endif
                                                   >>  56 
                                                   >>  57 typedef std::string::size_type str_size;
                                                   >>  58 
                                                   >>  59 class G4String;
                                                   >>  60 
                                                   >>  61 class G4SubString
                                                   >>  62 {
                                                   >>  63 public:
                                                   >>  64 
                                                   >>  65   inline G4SubString(const G4SubString&);
                                                   >>  66 
                                                   >>  67   inline G4SubString& operator=(const char*);         
                                                   >>  68 
                                                   >>  69   inline G4SubString& operator=(const G4SubString&);
                                                   >>  70  
                                                   >>  71   inline char& operator()(str_size);
                                                   >>  72   inline char  operator()(str_size) const;
                                                   >>  73   inline char& operator[](str_size);
                                                   >>  74   inline char  operator[](str_size) const;
                                                   >>  75 
                                                   >>  76   inline G4int operator!() const;
                                                   >>  77 
                                                   >>  78   inline G4bool operator==(const G4String&) const;
                                                   >>  79   inline G4bool operator==(const char*) const;
                                                   >>  80   inline G4bool operator!=(const G4String&) const;
                                                   >>  81   inline G4bool operator!=(const char*) const;
                                                   >>  82 
                                                   >>  83   inline str_size length() const;
                                                   >>  84   inline str_size start() const;
                                                   >>  85 
                                                   >>  86   // For detecting null substrings
                                                   >>  87   //
                                                   >>  88   inline G4bool isNull() const;
                                                   >>  89 
                                                   >>  90 private:
                                                   >>  91 
                                                   >>  92   inline G4SubString(G4String&, str_size, str_size);
                                                   >>  93 
                                                   >>  94   G4String*    mystring;     
                                                   >>  95   str_size     mystart;
                                                   >>  96   str_size     extent;
                                                   >>  97 
                                                   >>  98   friend class G4String;
                                                   >>  99 
                                                   >> 100 };
                                                   >> 101  
 60                                                   102 
 61 class G4String : public std::string               103 class G4String : public std::string
 62 {                                                 104 {
 63  public:                                       << 105 
 64   /// @brief                                   << 106   typedef std::string std_string;
 65   /// @deprecated Will be removed in future re << 107 
 66   enum caseCompare                             << 108 public: 
 67   {                                            << 109 
 68     exact,                                     << 110   enum caseCompare { exact, ignoreCase };
 69     ignoreCase                                 << 111   enum stripType { leading, trailing, both };
 70   };                                           << 112 
 71                                                << 113   inline G4String ();
 72   /// @brief                                   << 114   inline G4String ( char );
 73   /// @deprecated Will be removed in future re << 115   inline G4String ( const char * );
 74   enum stripType                               << 116   inline G4String ( const char *, str_size );
 75   {                                            << 117   inline G4String ( const G4String& );
 76     leading,                                   << 118   inline G4String ( const G4SubString& );
 77     trailing,                                  << 119   inline G4String ( const std::string & );
 78     both                                       << 120   ~G4String () {}
 79   };                                           << 121 
 80                                                << 
 81   using std::string::string;                   << 
 82   using std::string::operator=;                << 
 83                                                << 
 84   inline G4String() = default;                 << 
 85   inline G4String(const std::string&);         << 
 86   inline G4String(const G4String&);            << 
 87   inline G4String(std::string&&);              << 
 88   inline G4String(G4String&&);                 << 
 89   inline G4String& operator=(const G4String&);    122   inline G4String& operator=(const G4String&);
 90   inline G4String& operator=(G4String&&);      << 123   inline G4String& operator=(const std::string &);
                                                   >> 124   inline G4String& operator=(const char*);
                                                   >> 125 
                                                   >> 126   inline char operator () (str_size) const; 
                                                   >> 127   inline char& operator () (str_size);
                                                   >> 128 
                                                   >> 129   inline G4String& operator+=(const G4SubString&);
                                                   >> 130   inline G4String& operator+=(const char*);
                                                   >> 131   inline G4String& operator+=(const std::string &);
                                                   >> 132   inline G4String& operator+=(const char&);
                                                   >> 133   inline G4bool operator==(const G4String&) const;
                                                   >> 134   inline G4bool operator==(const char*) const;
                                                   >> 135   inline G4bool operator!=(const G4String&) const;
                                                   >> 136   inline G4bool operator!=(const char*) const;
 91                                                   137 
 92   /// @brief Implicitly convert to `const char << 
 93   /// @deprecated Will be removed in future re << 
 94   ///   If passing `G4String` to functions req << 
 95   ///   to explicitly convert. `G4String` also << 
 96   ///   to match the `std::string` interface.  << 
 97   inline operator const char*() const;            138   inline operator const char*() const;
                                                   >> 139   inline G4SubString operator()(str_size, str_size);
                                                   >> 140 
                                                   >> 141   inline G4int compareTo(const char*, caseCompare mode=exact) const;
                                                   >> 142   inline G4int compareTo(const G4String&, caseCompare mode=exact) const;
 98                                                   143 
 99   /// @brief Override of subscript operator fo << 144   inline G4String& prepend (const char*);
100   /// @deprecated Will be removed at the same  << 145   inline G4String& append (const G4String&);
101   ///                                          << 146 
102   /// This override is required because of G4S << 147   inline std::istream& readLine (std::istream&, G4bool skipWhite=true);
103   /// operator to `const char*`. Together with << 
104   /// `operator[](const char*, int) operator,  << 
105   /// [MSVC error C2666](https://docs.microsof << 
106   /// This is a known issue with mixing implic << 
107   /// operators. Provision of the override wit << 
108   /// until the conversion operator is removed << 
109   inline reference operator[](int);            << 
110                                                << 
111   /// @overload                                << 
112   inline const_reference operator[](int) const << 
113                                                << 
114   /// @brief Deprecated function               << 
115   /// @deprecated Use `std::string::compare` o << 
116   [[deprecated("Use std::string::compare, or G << 
117   inline G4int compareTo(std::string_view, cas << 
118                                                << 
119   /// @brief Deprecated function               << 
120   /// @deprecated Use `std::getline` plus `G4S << 
121   [[deprecated("Use std::getline instead, plus << 
122   inline std::istream& readLine(std::istream&, << 
123                                                   148   
124   /// @brief Deprecated function               << 149   inline G4String& replace (unsigned int, unsigned int, 
125   /// @deprecated Use `std::string::erase` ins << 150                              const char*, unsigned int );
126   [[deprecated("Use std::string::erase instead << 151   inline G4String& replace(str_size, str_size, const char*);
127   inline G4String& remove(size_type);          << 152 
128                                                << 153   inline G4String& remove(str_size);
129   /// @brief Deprecated function               << 154   inline G4String& remove(str_size, str_size);
130   /// @deprecated Use `G4StrUtil::contains` in << 
131   [[deprecated("Use G4StrUtil::contains instea << 
132   inline G4bool contains(const std::string&) c << 
133                                                   155 
134   /// @brief Deprecated function               << 156   inline G4int first(char) const;
135   /// @deprecated Use `G4StrUtil::contains` in << 157   inline G4int last(char) const;
136   [[deprecated("Use G4StrUtil::contains instea << 158 
                                                   >> 159   inline G4bool contains(const std::string&) const;
137   inline G4bool contains(char) const;             160   inline G4bool contains(char) const;
138                                                   161 
139   /// @brief Deprecated function               << 162   // stripType = 0 beginning
140   /// @deprecated Use `G4StrUtil` functions in << 163   // stripType = 1 end
141   [[deprecated("Use G4StrUtil::{lstrip,rstrip, << 164   // stripType = 2 both
142   [[nodiscard]] inline G4String strip(stripTyp << 165   //
143                                                << 166   inline G4String strip (G4int strip_Type=trailing, char c=' ');
144   /// @brief Deprecated function               << 
145   /// @deprecated Use `G4StrUtil` functions in << 
146   [[deprecated("Use G4StrUtil::to_lower/to_low << 
147   inline void toLower();                       << 
148                                                << 
149   /// @brief Deprecated function               << 
150   /// @deprecated Use `G4StrUtil` functions in << 
151   [[deprecated("Use G4StrUtil::to_upper/to_upp << 
152   inline void toUpper();                       << 
153 };                                             << 
154                                                   167 
155 /// @brief Query and manipulation functions fo << 168   inline void toLower ();
156 //                                             << 169   inline void toUpper ();
157 /// Additional free functions that are not par << 170 
158 /// of the minimum C++ standard supported by G << 171   inline G4bool isNull() const;
159 ///                                            << 172 
160 /// @see `G4String`                            << 173   inline str_size index (const char*, G4int pos=0) const; 
161 namespace G4StrUtil                            << 174   inline str_size index (char, G4int pos=0) const; 
162 {                                              << 175   inline str_size index (const G4String&, str_size, str_size, caseCompare) const;
163   /// @brief Convert string to lowercase       << 176 
164   /// @param[in, out] str the string to lowerc << 177   inline const char* data() const;
165   inline void to_lower(G4String& str);         << 178 
166                                                << 179   inline G4int strcasecompare(const char*, const char*) const;
167   /// @brief Return lowercased copy of string  << 180 
168   /// @param[in] str the string to lowercase   << 181   inline unsigned int hash( caseCompare cmp = exact ) const;
169   /// @return lowercased copy of `str`         << 182   inline unsigned int stlhash() const;
170   inline G4String to_lower_copy(G4String str); << 183 };
171                                                << 
172   /// @brief Convert string to uppercase       << 
173   /// @param[in, out] str the string to upperc << 
174   inline void to_upper(G4String& str);         << 
175                                                << 
176   /// @brief Return uppercase copy of string   << 
177   /// @param[in] str the string to upper case  << 
178   /// @return uppercased copy of `str`         << 
179   inline G4String to_upper_copy(G4String str); << 
180                                                << 
181   /// @brief Remove leading characters from st << 
182   /// @param[in,out] str string to strip       << 
183   /// @param[in] ch character to remove        << 
184   /// @post `str` has any leading sequence of  << 
185   void lstrip(G4String& str, char ch = ' ');   << 
186                                                << 
187   /// @brief Remove trailing characters from s << 
188   /// @param[in,out] str string to strip       << 
189   /// @param[in] ch character to remove        << 
190   /// @post `str` has any trailing sequence of << 
191   void rstrip(G4String& str, char ch = ' ');   << 
192                                                << 
193   /// @brief Remove leading and trailing chara << 
194   /// @param[in,out] str string to strip       << 
195   /// @param[in] ch character to remove        << 
196   /// @post `str` has any leading and trailing << 
197   void strip(G4String& str, char ch = ' ');    << 
198                                                << 
199   /// @brief Return copy of string with leadin << 
200   /// @param[in] str string to copy and strip  << 
201   /// @param[in] ch character to remove        << 
202   /// @return copy of `str` with any leading s << 
203   G4String lstrip_copy(G4String str, char ch = << 
204                                                << 
205   /// @brief Return copy of string with traili << 
206   /// @param[in] str string to copy and strip  << 
207   /// @param[in] ch character to remove        << 
208   /// @return copy of `str` with any trailing  << 
209   G4String rstrip_copy(G4String str, char ch = << 
210                                                << 
211   /// @brief Return copy of string with leadin << 
212   /// @param[in] str string to copy and strip  << 
213   /// @param[in] ch character to remove        << 
214   /// @return copy of `str` with any leading a << 
215   G4String strip_copy(G4String str, char ch =  << 
216                                                << 
217   /// @brief Check if a string contains a give << 
218   /// @param[in] str string to be checked      << 
219   /// @param[in] ss substring to check for     << 
220   /// @retval true if `str` contains `ss`      << 
221   /// @retval false otherwise                  << 
222   inline G4bool contains(const G4String& str,  << 
223                                                << 
224   /// @overload                                << 
225   inline G4bool contains(const G4String& str,  << 
226                                                << 
227   /// @overload                                << 
228   inline G4bool contains(const G4String& str,  << 
229                                                << 
230   /// @overload                                << 
231   /// @note this overload is required to resol << 
232   ///   signatures taking `std::string_view` a << 
233   ///   arguments. G4String currently provides << 
234   ///   `const char*`, which makes the calls a << 
235   ///   implicit conversion to `std::string_vi << 
236   inline G4bool contains(const G4String& str,  << 
237                                                << 
238   /// @brief Case insensitive comparison of tw << 
239   ///                                          << 
240   /// Converts both input arguments to lower c << 
241   /// result of `std::string::compare` with th << 
242   ///                                          << 
243   /// @param[in] lhs the first string in the c << 
244   /// @param[in] rhs the second string in the  << 
245   /// @return negative(positive) `G4int` if lo << 
246   ///   before(after) lowercased `rhs` in lexi << 
247   ///   compare equivalent after lowercasing.  << 
248   inline G4int icompare(std::string_view lhs,  << 
249                                                << 
250   /// @brief Return true if a string starts wi << 
251   /// @param[in] str string to be checked      << 
252   /// @param[in] ss prefix to check for        << 
253   /// @retval true if `str` starts with `ss`   << 
254   /// @retval false otherwise                  << 
255   inline bool starts_with(const G4String& str, << 
256                                                << 
257   /// @overload                                << 
258   inline bool starts_with(const G4String& str, << 
259                                                << 
260   /// @overload                                << 
261   inline bool starts_with(const G4String& str, << 
262                                                << 
263   /// @overload                                << 
264   /// @note this overload is required to resol << 
265   ///   signatures taking `std::string_view` a << 
266   ///   arguments. G4String currently provides << 
267   ///   `const char*`, which makes the calls a << 
268   ///   implicit conversion to `std::string_vi << 
269   inline bool starts_with(const G4String& str, << 
270                                                << 
271   /// @brief Return true if a string ends with << 
272   /// @param[in] str string to be checked      << 
273   /// @param[in] ss suffix to check for        << 
274   /// @retval true if `str` ends with `ss`     << 
275   /// @retval false otherwise                  << 
276   inline bool ends_with(const G4String& str, s << 
277                                                << 
278   /// @overload                                << 
279   inline bool ends_with(const G4String& str, G << 
280                                                << 
281   /// @overload                                << 
282   inline bool ends_with(const G4String& str, c << 
283                                                << 
284   /// @overload                                << 
285   inline bool ends_with(const G4String& str, c << 
286                                                << 
287   /// @brief Remove specified in-range charact << 
288   ///                                          << 
289   /// Equivalent to `std::string::erase(index, << 
290   /// if `index <= size()`. When `index > size << 
291   ///                                          << 
292   /// @deprecated It is strongly recommended t << 
293   ///   start index is already checked, or oth << 
294   ///   implement the index-size comparison in << 
295   ///                                          << 
296   /// @param[in,out] str string to erase chara << 
297   /// @param[in] index position to start remov << 
298   /// @param[in] count number of characters to << 
299   /// @post `str` is unchanged if `index > str << 
300   ///   `min(count, str.size() - index)` chara << 
301   inline void safe_erase(G4String& str, G4Stri << 
302                          G4String::size_type c << 
303                                                << 
304   /// @brief Read characters into a G4String f << 
305   ///                                          << 
306   /// @deprecated It is strongly recommended t << 
307   ///   function, plus `G4StrUtil::lstrip` if  << 
308   ///                                          << 
309   /// @param[in] is input stream to read from  << 
310   /// @param[in,out] str string to read into   << 
311   /// @param[in] skipWhite if true, discard le << 
312   /// @return `is`                             << 
313   inline std::istream& readline(std::istream&  << 
314 }  // namespace G4StrUtil                      << 
315                                                   184 
316 #include "G4String.icc"                           185 #include "G4String.icc"
317                                                   186 
318 #endif                                            187 #endif
319                                                   188