Warning, /include/Geant4/tools/strip 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_strip
0005 #define tools_strip
0006
0007 #include <vector>
0008 #include <string>
0009
0010 namespace tools {
0011
0012 enum what { leading, trailing, both };
0013
0014 inline bool strip(std::string& a_string,what a_type = both,char a_char = ' '){
0015 //return true = some stripping had been done.
0016
0017 std::string::size_type l = a_string.length();
0018 if(l==0) return false;
0019
0020 switch ( a_type ) {
0021 case leading:{
0022 char* pos = (char*)a_string.c_str();
0023 for(std::string::size_type i=0;i<l;i++,pos++) {
0024 if(*pos!=a_char) {
0025 a_string = a_string.substr(i,l-i);
0026 return (i?true:false); //i=0 : same string.
0027 }
0028 }
0029 // all chars are a_char :
0030 a_string.clear();
0031 return true;
0032 }break;
0033 case trailing:{
0034 char* pos = (char*)a_string.c_str();
0035 pos += (l-1);
0036 std::string::size_type i = l-1;
0037 std::string::const_reverse_iterator it;
0038 for(it=a_string.rbegin();it!=a_string.rend();++it,i--,pos--) {
0039 if(*pos!=a_char) {
0040 a_string = a_string.substr(0,i+1);
0041 return (i==(l-1)?false:true); //i==l-1 : same string.
0042 }
0043 }
0044 // all chars are a_char :
0045 a_string.clear();
0046 return true;
0047 }break;
0048 case both:{
0049 bool stat_lead = strip(a_string,leading,a_char);
0050 bool stat_trail = strip(a_string,trailing,a_char);
0051 if(stat_lead) return true;
0052 if(stat_trail) return true;
0053 }break;
0054 //default:break;
0055 }
0056 return false; //nothing done.
0057 }
0058
0059 }
0060
0061 #endif