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5.p1 ] [ 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 /externals/g4tools/include/tools/srep (Version 11.3.0) and /externals/g4tools/include/tools/srep (Version 11.0)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_srep                                  4 #ifndef tools_srep
  5 #define tools_srep                                  5 #define tools_srep
  6                                                     6 
  7 #include <string>                                   7 #include <string>
  8 #include <vector>                                   8 #include <vector>
  9 #include <utility>                             << 
 10                                                     9 
 11 #include "forit"                                   10 #include "forit"
 12                                                    11 
 13 namespace tools {                                  12 namespace tools {
 14                                                    13 
 15 inline void replace(std::string& a_string,char     14 inline void replace(std::string& a_string,char a_old,char a_new){
 16   tools_sforit(a_string,it) {                      15   tools_sforit(a_string,it) {
 17     if((*it)==a_old) *it = a_new;                  16     if((*it)==a_old) *it = a_new;
 18   }                                                17   }
 19 }                                                  18 }
 20                                                    19 
 21 inline bool replace(std::string& a_string,cons     20 inline bool replace(std::string& a_string,const std::string& a_old,const std::string& a_new){
 22   // return true : some replacement done.          21   // return true : some replacement done.
 23   // return false : nothing replaced.              22   // return false : nothing replaced.
 24   if(a_old.empty()) return false;                  23   if(a_old.empty()) return false;
 25   std::string snew;                                24   std::string snew;
 26   std::string::size_type lold = a_old.length()     25   std::string::size_type lold = a_old.length();
 27   bool status = false;                             26   bool status = false;
 28   std::string stmp = a_string;                     27   std::string stmp = a_string;
 29   while(true) {                                    28   while(true) {
 30     std::string::size_type pos = stmp.find(a_o     29     std::string::size_type pos = stmp.find(a_old);
 31     if(pos==std::string::npos){                    30     if(pos==std::string::npos){
 32       snew += stmp;                                31       snew += stmp;
 33       break;                                       32       break;
 34     } else {                                       33     } else {
 35       snew += stmp.substr(0,pos);                  34       snew += stmp.substr(0,pos);
 36       snew += a_new;                               35       snew += a_new;
 37       stmp = stmp.substr(pos+lold,stmp.length(     36       stmp = stmp.substr(pos+lold,stmp.length()-(pos+lold));
 38       status = true;                               37       status = true;
 39     }                                              38     }
 40   }                                                39   }
 41   a_string = std::move(snew);                  <<  40   a_string = snew;
 42   return status;                                   41   return status;
 43 }                                                  42 }
 44                                                    43 
 45 inline bool replace_(std::string& a_string,con     44 inline bool replace_(std::string& a_string,const std::string& a_old,const std::string& a_new) {
 46   return replace(a_string,a_old,a_new);            45   return replace(a_string,a_old,a_new);
 47 }                                                  46 }
 48                                                    47 
 49 inline bool replace(std::vector<std::string>&      48 inline bool replace(std::vector<std::string>& a_strings,const std::string& a_old,const std::string& a_new){
 50   tools_vforit(std::string,a_strings,it) {         49   tools_vforit(std::string,a_strings,it) {
 51     if(!replace(*it,a_old,a_new)) return false     50     if(!replace(*it,a_old,a_new)) return false;
 52   }                                                51   }
 53   return true;                                     52   return true;
 54 }                                                  53 }
 55                                                    54 
 56 inline void toxml(std::string& a_string){          55 inline void toxml(std::string& a_string){
 57   // > : &lt;                                      56   // > : &lt;
 58   // < : &gt;                                      57   // < : &gt;
 59   // & : &amp;                                     58   // & : &amp;
 60   // " : &quot;                                    59   // " : &quot;
 61   // ' : &apos;                                    60   // ' : &apos;
 62   replace(a_string,"&","&amp;"); //must be fir     61   replace(a_string,"&","&amp;"); //must be first.
 63   replace(a_string,"<","&lt;");                    62   replace(a_string,"<","&lt;");
 64   replace(a_string,">","&gt;");                    63   replace(a_string,">","&gt;");
 65   replace(a_string,"\"","&quot;");                 64   replace(a_string,"\"","&quot;");
 66   replace(a_string,"'","&apos;");                  65   replace(a_string,"'","&apos;");
 67 }                                                  66 }
 68                                                    67 
 69 inline std::string to_xml(const std::string& a     68 inline std::string to_xml(const std::string& a_string){
 70   std::string _s = a_string;                   <<  69   std::string s = a_string;
 71   toxml(_s);                                   <<  70   toxml(s);
 72   return _s;                                   <<  71   return s;
 73 }                                                  72 }
 74                                                    73 
 75 inline void to_win(std::string& a_string) {        74 inline void to_win(std::string& a_string) {
 76   replace(a_string,"/cygdrive/c","C:");  // CY     75   replace(a_string,"/cygdrive/c","C:");  // CYGWIN.
 77   replace(a_string,"/mnt/c","C:");       // WS     76   replace(a_string,"/mnt/c","C:");       // WSL.
 78   replace(a_string,'/','\\');                      77   replace(a_string,'/','\\');
 79 }                                                  78 }
 80                                                    79 
 81 inline void to_win_python(std::string& a_strin     80 inline void to_win_python(std::string& a_string) {
 82   replace(a_string,"/cygdrive/c","c:");  // CY     81   replace(a_string,"/cygdrive/c","c:");  // CYGWIN.
 83   replace(a_string,"/mnt/c","c:");       // WS     82   replace(a_string,"/mnt/c","c:");       // WSL. (Python wants c: in lowercase).
 84   replace(a_string,"C:","c:");                     83   replace(a_string,"C:","c:");
 85   replace(a_string,'\\','/');                      84   replace(a_string,'\\','/');
 86 }                                                  85 }
 87                                                    86 
 88 }                                                  87 }
 89                                                    88 
 90 #endif                                             89 #endif