Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
StringTokenizer.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file StringTokenizer.cc
1
/*******************************************************************************
2
* Copyright (c) The JETSCAPE Collaboration, 2018
3
*
4
* Modular, task-based framework for simulating all aspects of heavy-ion collisions
5
*
6
* For the list of contributors see AUTHORS.
7
*
8
* Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
9
*
10
* or via email to bugs.jetscape@gmail.com
11
*
12
* Distributed under the GNU General Public License 3.0 (GPLv3 or later).
13
* See COPYING for details.
14
******************************************************************************/
15
// StringTokenizer
16
// General purpose string tokenizer (C++ string version)
17
// based on https://github.com/ViDA-NYU/birdvis/blob/master/Tokenizer.cpp
18
19
#include "
StringTokenizer.h
"
20
#include <iostream>
21
using
std::cout;
22
using
std::endl;
23
24
namespace
Jetscape {
25
26
StringTokenizer::~StringTokenizer
() {}
27
28
bool
StringTokenizer::isGraphEntry
()
const
{
29
if
(
buffer
.length() == 0)
30
return
false
;
31
if
(
buffer
.find(
"["
) < 1)
32
return
true
;
33
return
false
;
34
}
35
36
bool
StringTokenizer::isNodeEntry
()
const
{
37
if
(
buffer
.length() == 0)
38
return
false
;
39
if
(
buffer
.find(
"] V"
) < 100)
40
return
true
;
41
return
false
;
42
}
43
44
bool
StringTokenizer::isNodeZero
()
const
{
45
if
(!
isGraphEntry
())
46
return
false
;
47
if
(!
isNodeEntry
())
48
return
false
;
49
if
(
isHadronEntry
())
50
return
false
;
51
52
if
(
buffer
.find(
"[0]"
) < 3)
53
return
true
;
54
55
return
false
;
56
}
57
58
bool
StringTokenizer::isEdgeEntry
()
const
{
59
if
(
buffer
.length() == 0)
60
return
false
;
61
if
(!
isGraphEntry
())
62
return
false
;
63
if
(
buffer
.find(
"]=>["
) < 100)
64
return
true
;
65
66
return
false
;
67
}
68
69
bool
StringTokenizer::isCommentEntry
()
const
{
70
if
(
buffer
.length() == 0)
71
return
false
;
72
if
(
buffer
.find(
"#"
) < 1)
73
return
true
;
74
return
false
;
75
}
76
77
bool
StringTokenizer::isEventEntry
()
const
{
78
if
(
buffer
.length() == 0)
79
return
false
;
80
if
(
buffer
.find(
"Event"
) < 100)
// && !isCommentEntry())
81
return
true
;
82
83
return
false
;
84
}
85
86
bool
StringTokenizer::isHadronEntry
()
const
{
87
if
(
buffer
.length() == 0)
88
return
false
;
89
if
(
buffer
.find(
"] H"
) < 100)
90
return
true
;
91
return
false
;
92
}
93
95
// reset string buffer, delimiter and the currsor position
97
void
StringTokenizer::set
(
const
std::string
&
str
,
98
const
std::string
&delimiter) {
99
this->
buffer
=
str
;
100
this->delimiter =
delimiter
;
101
this->
currPos
=
buffer
.begin();
102
}
103
104
void
StringTokenizer::setString
(
const
std::string
&
str
) {
105
this->
buffer
=
str
;
106
this->
currPos
=
buffer
.begin();
107
}
108
109
void
StringTokenizer::setDelimiter
(
const
std::string
&delimiter) {
110
this->delimiter =
delimiter
;
111
this->
currPos
=
buffer
.begin();
112
}
113
115
// return the next token
116
// If cannot find a token anymore, return "".
118
std::string
StringTokenizer::next
() {
119
//if(buffer.size() <= 0) return ""; // skip if buffer is empty
120
121
if
(
buffer
.size() <= 0) {
122
this->
currPos
=
buffer
.end();
123
return
""
;
124
}
125
126
token
.clear();
// reset token string
127
128
this->
skipDelimiter
();
// skip leading delimiters
129
130
// append each char to token string until it meets delimiter
131
while
(
currPos
!=
buffer
.end() && !
isDelimiter
(*
currPos
)) {
132
token
+= *
currPos
;
133
++
currPos
;
134
}
135
return
token
;
136
}
137
139
// skip ang leading delimiters
141
void
StringTokenizer::skipDelimiter
() {
142
while
(
currPos
!=
buffer
.end() &&
isDelimiter
(*
currPos
))
143
++
currPos
;
144
}
145
147
// return true if the current character is delimiter
149
bool
StringTokenizer::isDelimiter
(
char
c
) {
150
return
(
delimiter
.find(c) != std::string::npos);
151
}
152
154
// split the input string into multiple tokens
155
// This function scans tokens from the current cursor position.
157
std::vector<std::string>
StringTokenizer::split
() {
158
std::vector<std::string> tokens;
159
std::string
token
;
160
while
((token = this->
next
()) !=
""
) {
161
tokens.push_back(token);
162
}
163
164
return
tokens;
165
}
166
167
}
// end namespace Jetscape
JETSCAPE
blob
main
src
framework
StringTokenizer.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:25
using
1.8.2 with
sPHENIX GitHub integration