File indexing completed on 2025-10-30 08:42:28
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 
0019 
0020 
0021 
0022 
0023 
0024 
0025 
0026 
0027 
0028 
0029 
0030 
0031 inline G4String::G4String(const std::string& str)
0032   : std::string(str)
0033 {}
0034 
0035 inline G4String::G4String(const G4String& str) = default;
0036 
0037 inline G4String::G4String(std::string&& str)
0038   : std::string(std::move(str))
0039 {}
0040 
0041 inline G4String::G4String(G4String&& str)
0042   : std::string(std::move(str))
0043 {}
0044 
0045 inline G4String& G4String::operator=(const G4String& str)
0046 {
0047   if(&str == this)
0048   {
0049     return *this;
0050   }
0051   std::string::operator=(str);
0052   return *this;
0053 }
0054 
0055 inline G4String& G4String::operator=(G4String&& str)
0056 {
0057   std::string::operator=(std::move(str));
0058   return *this;
0059 }
0060 
0061 inline G4String::operator const char*() const { return c_str(); }
0062 
0063 inline G4String::reference G4String::operator[](int pos)
0064 {
0065   return std::string::operator[](pos);
0066 }
0067 
0068 inline G4String::const_reference G4String::operator[](int pos) const
0069 {
0070     return std::string::operator[](pos);
0071 }
0072 
0073 inline G4int G4String::compareTo(std::string_view str, caseCompare mode) const
0074 {
0075   if(mode == exact)
0076   {
0077     return compare(str);
0078   }
0079 
0080   return G4StrUtil::icompare(*this, str);
0081 }
0082 
0083 inline std::istream& G4String::readLine(std::istream& strm, G4bool skipWhite)
0084 {
0085   return G4StrUtil::readline(strm, *this, skipWhite);
0086 }
0087 
0088 inline G4String& G4String::remove(size_type n)
0089 {
0090   G4StrUtil::safe_erase(*this, n);
0091   return *this;
0092 }
0093 
0094 inline G4bool G4String::contains(const std::string& str) const
0095 {
0096   
0097   return G4StrUtil::contains(*this, str.c_str());
0098 }
0099 
0100 inline G4bool G4String::contains(char ch) const
0101 {
0102   return G4StrUtil::contains(*this, ch);
0103 }
0104 
0105 inline G4String G4String::strip(G4String::stripType strip_Type, char ch)
0106 {
0107   if(empty())
0108   {
0109     return "";
0110   }
0111 
0112   G4String retVal = *this;
0113 
0114   switch(strip_Type)
0115   {
0116     case G4String::leading:
0117       G4StrUtil::lstrip(retVal, ch);
0118       break;
0119     case G4String::trailing:
0120       G4StrUtil::rstrip(retVal, ch);
0121       break;
0122     case G4String::both:
0123       G4StrUtil::strip(retVal, ch);
0124       break;
0125     default:
0126       break;
0127   }
0128 
0129   return retVal;
0130 }
0131 
0132 inline void G4String::toLower() { G4StrUtil::to_lower(*this); }
0133 
0134 inline void G4String::toUpper() { G4StrUtil::to_upper(*this); }
0135 
0136 namespace G4StrUtil
0137 {
0138   inline void to_lower(G4String& str)
0139   {
0140     std::transform(str.begin(), str.end(), str.begin(),
0141                    [](unsigned char ch) { return std::tolower(ch); });
0142   }
0143 
0144   inline G4String to_lower_copy(G4String str)
0145   {
0146     to_lower(str);
0147     return str;
0148   }
0149 
0150   inline void to_upper(G4String& str)
0151   {
0152     std::transform(str.begin(), str.end(), str.begin(),
0153                    [](unsigned char ch) { return std::toupper(ch); });
0154   }
0155 
0156   inline G4String to_upper_copy(G4String str)
0157   {
0158     to_upper(str);
0159     return str;
0160   }
0161 
0162   inline void lstrip(G4String& str, char ch)
0163   {
0164     auto startIndex = str.find_first_not_of(ch);
0165     str.erase(0, startIndex);
0166   }
0167 
0168   inline void rstrip(G4String& str, char ch)
0169   {
0170     auto endIndex = str.find_last_not_of(ch);
0171     if(endIndex == G4String::npos)
0172     {
0173       str = "";
0174     }
0175     else
0176     {
0177       str.erase(endIndex + 1);
0178     }
0179   }
0180 
0181   inline void strip(G4String& str, char ch)
0182   {
0183     if(str.empty())
0184     {
0185       return;
0186     }
0187 
0188     lstrip(str, ch);
0189     rstrip(str, ch);
0190   }
0191 
0192   inline G4String lstrip_copy(G4String str, char ch)
0193   {
0194     lstrip(str, ch);
0195     return str;
0196   }
0197 
0198   inline G4String rstrip_copy(G4String str, char ch)
0199   {
0200     rstrip(str, ch);
0201     return str;
0202   }
0203 
0204   inline G4String strip_copy(G4String str, char ch)
0205   {
0206     strip(str, ch);
0207     return str;
0208   }
0209 
0210   inline G4bool contains(const G4String& str, std::string_view ss)
0211   {
0212     return str.find(ss) != G4String::npos;
0213   }
0214 
0215   inline G4bool contains(const G4String& str, char ss)
0216   {
0217     return str.find(ss) != G4String::npos;
0218   }
0219 
0220   inline G4bool contains(const G4String& str, const char* ss)
0221   {
0222     return str.find(ss) != G4String::npos;
0223   }
0224 
0225   inline G4bool contains(const G4String& str, const G4String& ss)
0226   {
0227     return str.find(ss) != G4String::npos;
0228   }
0229 
0230   inline G4int icompare(std::string_view lhs, std::string_view rhs)
0231   {
0232     G4String buf1 = G4StrUtil::to_lower_copy(G4String(lhs.data(), lhs.size()));
0233     G4String buf2 = G4StrUtil::to_lower_copy(G4String(rhs.data(), rhs.size()));
0234     return buf1.compare(buf2);
0235   }
0236 
0237   inline bool starts_with(const G4String& str, std::string_view ss)
0238   {
0239     return str.rfind(ss, 0) == 0;
0240   }
0241 
0242   inline bool starts_with(const G4String& str, G4String::value_type ss)
0243   {
0244     return !str.empty() && (str[0] == ss);
0245   }
0246 
0247   inline bool starts_with(const G4String& str, const char* ss)
0248   {
0249     return str.rfind(ss, 0) == 0;
0250   }
0251 
0252   inline bool starts_with(const G4String& str, const G4String& ss)
0253   {
0254     return str.rfind(ss, 0) == 0;
0255   }
0256 
0257   inline bool ends_with(const G4String& str, std::string_view ss)
0258   {
0259     if(str.length() < ss.length())
0260     {
0261       return false;
0262     }
0263     return str.compare(str.length() - ss.length(), ss.length(), ss) == 0;
0264   }
0265 
0266   inline bool ends_with(const G4String& str, G4String::value_type ss)
0267   {
0268     return !str.empty() && (str.back() == ss);
0269   }
0270 
0271   inline bool ends_with(const G4String& str, const char* ss)
0272   {
0273     std::string_view sv(ss);
0274     return ends_with(str, sv);
0275   }
0276 
0277   inline bool ends_with(const G4String& str, const G4String& ss)
0278   {
0279     return ends_with(str, ss.c_str());
0280   }
0281 
0282   inline void safe_erase(G4String& str, G4String::size_type index,
0283                          G4String::size_type count)
0284   {
0285     if(index < str.size())
0286     {
0287       str.erase(index, count);
0288     }
0289   }
0290 
0291   inline std::istream& readline(std::istream& is, G4String& str,
0292                                 G4bool skipWhite)
0293   {
0294     char tmp[1024];
0295     if(skipWhite)
0296     {
0297       is >> std::ws;
0298     }
0299 
0300     is.getline(tmp, 1024);
0301     str = tmp;
0302 
0303     return is;
0304   }
0305 }