File indexing completed on 2025-08-05 08:19:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "StringTokenizer.h"
0020 #include <iostream>
0021 using std::cout;
0022 using std::endl;
0023
0024 namespace Jetscape {
0025
0026 StringTokenizer::~StringTokenizer() {}
0027
0028 bool StringTokenizer::isGraphEntry() const {
0029 if (buffer.length() == 0)
0030 return false;
0031 if (buffer.find("[") < 1)
0032 return true;
0033 return false;
0034 }
0035
0036 bool StringTokenizer::isNodeEntry() const {
0037 if (buffer.length() == 0)
0038 return false;
0039 if (buffer.find("] V") < 100)
0040 return true;
0041 return false;
0042 }
0043
0044 bool StringTokenizer::isNodeZero() const {
0045 if (!isGraphEntry())
0046 return false;
0047 if (!isNodeEntry())
0048 return false;
0049 if (isHadronEntry())
0050 return false;
0051
0052 if (buffer.find("[0]") < 3)
0053 return true;
0054
0055 return false;
0056 }
0057
0058 bool StringTokenizer::isEdgeEntry() const {
0059 if (buffer.length() == 0)
0060 return false;
0061 if (!isGraphEntry())
0062 return false;
0063 if (buffer.find("]=>[") < 100)
0064 return true;
0065
0066 return false;
0067 }
0068
0069 bool StringTokenizer::isCommentEntry() const {
0070 if (buffer.length() == 0)
0071 return false;
0072 if (buffer.find("#") < 1)
0073 return true;
0074 return false;
0075 }
0076
0077 bool StringTokenizer::isEventEntry() const {
0078 if (buffer.length() == 0)
0079 return false;
0080 if (buffer.find("Event") < 100)
0081 return true;
0082
0083 return false;
0084 }
0085
0086 bool StringTokenizer::isHadronEntry() const {
0087 if (buffer.length() == 0)
0088 return false;
0089 if (buffer.find("] H") < 100)
0090 return true;
0091 return false;
0092 }
0093
0094
0095
0096
0097 void StringTokenizer::set(const std::string &str,
0098 const std::string &delimiter) {
0099 this->buffer = str;
0100 this->delimiter = delimiter;
0101 this->currPos = buffer.begin();
0102 }
0103
0104 void StringTokenizer::setString(const std::string &str) {
0105 this->buffer = str;
0106 this->currPos = buffer.begin();
0107 }
0108
0109 void StringTokenizer::setDelimiter(const std::string &delimiter) {
0110 this->delimiter = delimiter;
0111 this->currPos = buffer.begin();
0112 }
0113
0114
0115
0116
0117
0118 std::string StringTokenizer::next() {
0119
0120
0121 if (buffer.size() <= 0) {
0122 this->currPos = buffer.end();
0123 return "";
0124 }
0125
0126 token.clear();
0127
0128 this->skipDelimiter();
0129
0130
0131 while (currPos != buffer.end() && !isDelimiter(*currPos)) {
0132 token += *currPos;
0133 ++currPos;
0134 }
0135 return token;
0136 }
0137
0138
0139
0140
0141 void StringTokenizer::skipDelimiter() {
0142 while (currPos != buffer.end() && isDelimiter(*currPos))
0143 ++currPos;
0144 }
0145
0146
0147
0148
0149 bool StringTokenizer::isDelimiter(char c) {
0150 return (delimiter.find(c) != std::string::npos);
0151 }
0152
0153
0154
0155
0156
0157 std::vector<std::string> StringTokenizer::split() {
0158 std::vector<std::string> tokens;
0159 std::string token;
0160 while ((token = this->next()) != "") {
0161 tokens.push_back(token);
0162 }
0163
0164 return tokens;
0165 }
0166
0167 }