Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4Tokenizer << 27 // 23 // 28 // Class description: << 24 // $Id: G4Tokenizer.hh,v 1.1 2001/10/11 14:04:05 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-04-01 $ 29 // 26 // 30 // String tokenizer. << 27 // 31 // It derives from the implementation of the R << 28 //--------------------------------------------------------------- 32 // It intrinsically uses STL string. << 29 // GEANT 4 class header file 33 << 30 // 34 // Author: G.Cosmo, 11 October 2001 << 31 // G4Tokenizer 35 // ------------------------------------------- << 32 // 36 #ifndef G4Tokenizer_hh << 33 // Class description: 37 #define G4Tokenizer_hh 1 << 34 // >> 35 // String tokenizer. >> 36 // It derives from the implementation of the Rogue Wave >> 37 // RWTokenizer. It intrinsically uses STL string. >> 38 >> 39 //--------------------------------------------------------------- >> 40 >> 41 #ifndef __G4Tokenizer >> 42 #define __G4Tokenizer 38 43 39 #include "G4String.hh" 44 #include "G4String.hh" 40 45 41 class G4Tokenizer << 46 class G4Tokenizer 42 { 47 { 43 public: << 48 public: 44 G4Tokenizer(const G4String& stn) << 49 G4Tokenizer(const G4String& s):string2tokenize(s),actual(0){} 45 : string2tokenize(stn) << 46 , actual(0) << 47 {} << 48 << 49 G4String operator()(const char* str = " \t\n << 50 { << 51 std::size_t i, j, tmp; << 52 G4bool hasws = false; << 53 if(l == 0) << 54 l = strlen(str); << 55 50 56 // Skip leading delimeters << 51 G4SubString operator()(const char* str=" \t\n",size_t l=0) 57 while(actual < string2tokenize.size()) << 58 { 52 { 59 for(i = 0; i < l; ++i) << 53 size_t i,j,tmp; 60 { << 54 G4bool hasws=false; 61 if(string2tokenize[(G4int)actual] == s << 55 if(l==0) l=strlen(str); 62 hasws = true; << 56 //Skip leading delimeters 63 } << 57 while(actual<string2tokenize.size()) 64 if(hasws) << 58 { 65 { << 59 66 ++actual; << 60 for(i=0;i<l;i++) 67 hasws = false; << 61 if(string2tokenize[actual]==str[i]) hasws=true; 68 } << 62 if(hasws) >> 63 { >> 64 actual++; >> 65 hasws=false; >> 66 } >> 67 else >> 68 break; >> 69 } >> 70 >> 71 for(j=actual;j<string2tokenize.size();j++) >> 72 { >> 73 for(i=0;i<l;i++) >> 74 if(string2tokenize[j]==str[i]) break; >> 75 if(i<l) break; >> 76 } >> 77 if(j!=string2tokenize.size()) >> 78 { >> 79 tmp=actual; >> 80 actual=j+1; >> 81 return string2tokenize(tmp,j-tmp); >> 82 } 69 else 83 else 70 break; << 84 { 71 } << 85 tmp=actual; >> 86 actual=j; >> 87 return string2tokenize(tmp,j-tmp); >> 88 } >> 89 } 72 90 73 for(j = actual; j < string2tokenize.size() << 91 private: 74 { << 75 for(i = 0; i < l; ++i) << 76 if(string2tokenize[(G4int)j] == str[i] << 77 break; << 78 if(i < l) << 79 break; << 80 } << 81 if(j != string2tokenize.size()) << 82 { << 83 tmp = actual; << 84 actual = j + 1; << 85 return string2tokenize.substr(tmp, j - t << 86 } << 87 else << 88 { << 89 tmp = actual; << 90 actual = j; << 91 return string2tokenize.substr(tmp, j - t << 92 } << 93 } << 94 92 95 private: << 96 G4String string2tokenize; 93 G4String string2tokenize; 97 std::size_t actual; << 94 size_t actual; >> 95 98 }; 96 }; 99 97 100 #endif 98 #endif >> 99 101 100