Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_words 5 #define tools_words 6 7 #include <string> 8 #include <vector> 9 10 namespace tools { 11 12 inline void words(const std::string& a_string, 13 std::vector<std::string>& a_ 14 // If a_sep is for exa "|" and for "xxx||xx 15 // - a_take_empty false : {"xxx","xxx"} wil 16 // (and NOT {"xxx","","xxx"}). 17 // - a_take_empty true : {"xxx","","xxx"} w 18 if(a_clear) a_words.clear(); 19 if(a_string.empty()) return; 20 std::string::size_type lim = (a_take_empty?0 21 if(a_sep.empty()) { 22 a_words.push_back(a_string); 23 } else { 24 std::string::size_type l = a_string.length 25 std::string::size_type llimiter = a_sep.le 26 std::string::size_type pos = 0; 27 while(true) { 28 std::string::size_type index = a_string. 29 if(index==std::string::npos){ // Last wo 30 if((l-pos)>=lim) a_words.push_back(a_s 31 break; 32 } else { 33 // abcxxxef 34 // 0 3 67 35 if((index-pos)>=lim) a_words.push_back 36 pos = index + llimiter; 37 } 38 } 39 } 40 } 41 42 #ifdef TOOLS_DEPRECATED 43 inline std::vector<std::string> words(const st 44 std::vector<std::string> v; 45 words(a_string,a_limiter,a_take_empty,v); 46 return v; 47 } 48 #endif //TOOLS_DEPRECATED 49 50 inline void words(const std::string& a_string, 51 const std::string& a_sep,boo 52 //output : 53 unsigned int& a_wn, 54 std::string::size_type a_wps 55 std::string::size_type a_wls 56 //used to optimize tools::match(). 57 a_wn = 0; 58 if(a_string.empty()) return; 59 std::string::size_type lim = (a_take_empty?0 60 if(a_sep.empty()) { 61 //a_words.push_back(a_string); 62 a_wps[a_wn] = 0; 63 a_wls[a_wn] = a_string.length(); 64 a_wn++; 65 } else { 66 std::string::size_type l = a_string.length 67 std::string::size_type llimiter = a_sep.le 68 std::string::size_type pos = 0; 69 while(true) { 70 std::string::size_type index = a_string. 71 if(index==std::string::npos){ // Last wo 72 if((l-pos)>=lim) { 73 //a_words.push_back(a_string.substr( 74 a_wps[a_wn] = pos; 75 a_wls[a_wn] = l-pos; 76 a_wn++; 77 } 78 break; 79 } else { 80 // abcxxxef 81 // 0 3 67 82 if((index-pos)>=lim) { 83 //a_words.push_back(a_string.substr( 84 a_wps[a_wn] = pos; 85 a_wls[a_wn] = index-pos; 86 a_wn++; 87 } 88 pos = index + llimiter; 89 } 90 } 91 } 92 } 93 94 } 95 96 #endif