![]() |
|
|||
File indexing completed on 2025-08-05 08:19:20
0001 /******************************************************************************* 0002 * Copyright (c) The JETSCAPE Collaboration, 2018 0003 * 0004 * Modular, task-based framework for simulating all aspects of heavy-ion collisions 0005 * 0006 * For the list of contributors see AUTHORS. 0007 * 0008 * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues 0009 * 0010 * or via email to bugs.jetscape@gmail.com 0011 * 0012 * Distributed under the GNU General Public License 3.0 (GPLv3 or later). 0013 * See COPYING for details. 0014 ******************************************************************************/ 0015 // StringTokenizer 0016 // General purpose string tokenizer (C++ string version) 0017 // based on https://github.com/ViDA-NYU/birdvis/blob/master/Tokenizer.cpp 0018 0019 #ifndef STRINGTOKENIZER_H 0020 #define STRINGTOKENIZER_H 0021 0022 #include <string> 0023 #include <vector> 0024 0025 namespace Jetscape { 0026 0027 // default delimiter string (space, tab, newline, carriage return, form feed and =,>,[,]. 0028 const std::string DEFAULT_DELIMITER = " \t\v\n\r\f=>[]"; 0029 0030 class StringTokenizer { 0031 public: 0032 // ctor/dtor 0033 StringTokenizer(){}; 0034 StringTokenizer(const std::string &str, 0035 const std::string &delimiter = DEFAULT_DELIMITER); 0036 ~StringTokenizer(); 0037 0038 // set string and delimiter 0039 void set(const std::string &str, 0040 const std::string &delimiter = DEFAULT_DELIMITER); 0041 void setString(const std::string &str); // set source string only 0042 void setDelimiter(const std::string &delimiter); // set delimiter string only 0043 0044 std::string next(); // return the next token, return "" if it ends 0045 0046 std::vector<std::string> 0047 split(); // return array of tokens from current cursor 0048 0049 bool done() const { return currPos == buffer.end(); } 0050 0051 // Specific to potential JetScape Ascii format ... 0052 bool isGraphEntry() const; 0053 bool isNodeEntry() const; 0054 bool isNodeZero() const; 0055 bool isEdgeEntry() const; 0056 bool isCommentEntry() const; 0057 bool isEventEntry() const; 0058 bool isHadronEntry() const; 0059 0060 private: 0061 void skipDelimiter(); // ignore leading delimiters 0062 bool isDelimiter(char c); // check if the current char is delimiter 0063 0064 std::string buffer; // input string 0065 std::string token; // output string 0066 std::string delimiter; // delimiter string 0067 std::string::const_iterator 0068 currPos; // string iterator pointing the current position 0069 }; 0070 0071 } // end namespace Jetscape 0072 0073 #endif // STRINGTOKENIZER_H 0074 0075 /////////////////////////////////////////////////////////////////////////////// 0076 // Usage of Tokenizer Class: Example program 0077 /////////////////////////////////////////////////////////////////////////////// 0078 0079 /* 0080 // testing Tokenizer class 0081 0082 #include "StringTokenizer.h" 0083 #include <string> 0084 #include <iostream> 0085 0086 0087 using std::string; 0088 using std::cout; 0089 using std::endl; 0090 0091 int main(int argc, char* argv[]) 0092 { 0093 // instanciate Tokenizer class 0094 StringTokenizer str; 0095 string token; 0096 int counter = 0; 0097 0098 string m_str2="[0]-->[1] 100. 0 0 75."; 0099 cout<<m_str2<<endl; 0100 str.set(m_str2); 0101 //str.setDelimiter(" ->[]"); 0102 0103 cout<<str.isGraphEntry()<<endl; 0104 cout<<str.isEdgeEntry()<<endl; 0105 0106 // Two ways ... 0107 //while((token = str.next()) != "") 0108 while (!str.done()) 0109 { 0110 token = str.next(); 0111 ++counter; 0112 cout << counter << ": " << token << endl; 0113 } 0114 0115 string m_str3="#[-->Just --> a Comment [].."; 0116 cout<<m_str3<<endl; 0117 str.set(m_str3); 0118 0119 cout<<str.isGraphEntry()<<endl; 0120 cout<<str.isEdgeEntry()<<endl; 0121 cout<<str.isCommentEntry()<<endl; 0122 0123 return 0; 0124 } 0125 0126 */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |