Warning, /include/Geant4/tools/get_lines 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_get_lines
0005 #define tools_get_lines
0006
0007 #include "cstr"
0008
0009 #include <string>
0010 #include <vector>
0011
0012 namespace tools {
0013
0014 inline void get_lines(const std::string& a_string,std::vector<std::string>& a_lines){
0015 // a_string is a list separated by "\n" or "\\n".
0016 // For "xxx\n\nxxx", {"xxx","","xxx"} will be created.
0017 // WARNING : if a_string is a Windows file name, it may
0018 // contains a \n which is not a delimiter ; like ..\data\ntuples.hbook.
0019 a_lines.clear();
0020 size_t length = a_string.length();
0021 if(!length) return;
0022 char* cstring = str_dup(a_string.c_str());
0023 if(!cstring) return;
0024 size_t pos = 0;
0025 length++;
0026 for(size_t count=0;count<length;count++) {
0027 if( (cstring[count]=='\n') ||
0028 (cstring[count]=='\0') ||
0029 ( (cstring[count]=='\\') && (cstring[count+1]=='n') ) ) {
0030 char shift_one = (cstring[count]=='\n' ? 1 : 0);
0031 cstring[count] = '\0';
0032 a_lines.push_back(cstring+pos);
0033 if(shift_one==1) {
0034 pos = count+1;
0035 } else {
0036 pos = count+2;
0037 count++;
0038 }
0039 }
0040 }
0041 str_del(cstring);
0042 }
0043
0044 }
0045
0046 #endif