Warning, /include/Geant4/tools/sbeg is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sbeg
0005 #define tools_sbeg
0006
0007 #include <string>
0008
0009 namespace tools {
0010
0011 inline bool is_beg(const std::string& a_s,const std::string& a_b,bool a_forward = true){
0012 //look if a_s begin with a_b.
0013 std::string::size_type ls = a_s.size();
0014 std::string::size_type lb = a_b.size();
0015 if(lb>ls) return false;
0016 if(!lb) return false;
0017 if(a_forward) {
0018 const char* ps = a_s.c_str();
0019 const char* pb = a_b.c_str();
0020 for(std::string::size_type index=0;index<lb;index++,ps++,pb++) {
0021 if(*ps!=*pb) return false;
0022 }
0023 } else {
0024 const char* ps = a_s.c_str()+lb-1;
0025 const char* pb = a_b.c_str()+lb-1;
0026 for(std::string::size_type index=0;index<lb;index++,ps--,pb--) {
0027 if(*ps!=*pb) return false;
0028 }
0029 }
0030 return true;
0031 }
0032
0033 inline bool is_beg(const std::string& a_s,const std::string& a_b,std::string& a_cmd,bool a_forward = true){
0034 if(!tools::is_beg(a_s,a_b,a_forward)) {a_cmd.clear();return false;}
0035 if(a_s.size()<(a_b.size()+1)) {a_cmd.clear();return true;}
0036 // a_s.size() >= a_b.size()+1 :
0037 a_cmd = a_s.substr(a_b.size()+1,a_s.size()-(a_b.size()+1));
0038 return true;
0039 }
0040
0041 }
0042
0043 #endif