Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/rcmp 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_rcmp
0005 #define tools_rcmp
0006 
0007 // used in safe cast.
0008 
0009 #include <string>
0010 #include <cstring>
0011 
0012 namespace tools {
0013 
0014 inline bool rcmp(const char* a_1,const char* a_2) {
0015   size_t l1 = ::strlen(a_1);
0016   size_t l2 = ::strlen(a_2);
0017   if(l1!=l2) return false;
0018   if(!l1) return true;
0019   const char* p1 = a_1+l1-1;
0020   const char* p2 = a_2+l2-1;
0021   //ab
0022   //012
0023   for(size_t index=0;index<l1;index++,p1--,p2--) {
0024     if(*p1!=*p2) return false;
0025   }
0026   return true;
0027 }
0028 
0029 inline bool rcmp(const std::string& a_1,const char* a_2) {
0030   std::string::size_type l1 = a_1.size();
0031   size_t l2 = ::strlen(a_2);
0032   if(size_t(l1)!=l2) return false;
0033   if(!l1) return true;
0034   const char* p1 = a_1.c_str()+l1-1;
0035   const char* p2 = a_2+l2-1;
0036   //ab
0037   //012
0038   for(std::string::size_type index=0;index<l1;index++,p1--,p2--) {
0039     if(*p1!=*p2) return false;
0040   }
0041   return true;
0042 }
0043 
0044 inline bool rcmp(const char* a_1,const std::string& a_2) {
0045   size_t l1 = ::strlen(a_1);
0046   std::string::size_type l2 = a_2.size();
0047   if(l1!=size_t(l2)) return false;
0048   if(!l1) return true;
0049   const char* p1 = a_1+l1-1;
0050   const char* p2 = a_2.c_str()+l2-1;
0051   //ab
0052   //012
0053   for(size_t index=0;index<l1;index++,p1--,p2--) {
0054     if(*p1!=*p2) return false;
0055   }
0056   return true;
0057 }
0058 
0059 inline bool rcmp(const std::string& a_1,const std::string& a_2) {
0060   std::string::size_type l1 = a_1.size();
0061   std::string::size_type l2 = a_2.size();
0062   if(l1!=l2) return false;
0063   if(!l1) return true;
0064   const char* p1 = a_1.c_str()+l1-1;
0065   const char* p2 = a_2.c_str()+l2-1;
0066   //ab
0067   //012
0068   for(std::string::size_type index=0;index<l1;index++,p1--,p2--) {
0069     if(*p1!=*p2) return false;
0070   }
0071   return true;
0072 }
0073 
0074 }
0075 
0076 #endif