Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/tokenize 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_tokenize
0005 #define tools_tokenize
0006 
0007 #include <string>
0008 #include <vector>
0009 
0010 namespace tools {
0011 
0012 inline bool double_quotes_get_token(const std::string& a_cmd,std::string::size_type a_begIdx,
0013                                     std::string::size_type& a_endIdx,std::string& a_token) {
0014   while ( a_cmd[a_begIdx] == ' ') ++a_begIdx; // Loop checking, 23.06.2015, I. Hrivnacova
0015   if ( a_cmd[a_begIdx] == '"' ) {
0016     a_endIdx = a_cmd.find('"', a_begIdx+1);
0017     if ( a_endIdx == std::string::npos ) a_endIdx = a_cmd.length();
0018     a_token = a_cmd.substr(a_begIdx+1, (a_endIdx-1)-a_begIdx);
0019     ++a_endIdx;
0020   }
0021   else {
0022     a_endIdx = a_cmd.find(' ', a_begIdx);
0023     if ( a_endIdx == std::string::npos ) a_endIdx = a_cmd.length();
0024     a_token = a_cmd.substr(a_begIdx, a_endIdx-a_begIdx);
0025   }
0026   return ( a_token.length() > 0 );
0027 }
0028 
0029 //  From a string, double_quotes_tokenize permits to get arguments
0030 // by taking into account strings enclosed by double quotes and potentially
0031 // containing spaces (for example to specify a file path containing spaces).
0032 //  Example:
0033 //    if a_cmd is the string: aa bbb "ccc ddd" ee "fff gg"
0034 //  Returned a_args string list will be:
0035 //    "aa", "bb", "ccc ddd", "ee", "fff gg"
0036 //  Algorithm from Geant4/G4AnalysisUtilities.cc/Tokenize() done by Ivana Hrivnacova.
0037 
0038 inline void double_quotes_tokenize(const std::string& a_cmd, std::vector<std::string>& a_args) {
0039   std::string::size_type begIdx = 0;
0040   std::string::size_type endIdx = 0;
0041   std::string token;
0042   do {
0043     if ( double_quotes_get_token(a_cmd, begIdx, endIdx, token) ) {
0044       a_args.push_back(token);
0045     }
0046     begIdx = endIdx + 1;
0047   }
0048   while ( endIdx < a_cmd.length() ); // Loop checking, 23.06.2015, I. Hrivnacova
0049 }
0050 
0051 }
0052 
0053 #endif