Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-xt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ag-ohlberger
dune-community
dune-xt
Commits
0fbcbd33
Commit
0fbcbd33
authored
15 years ago
by
René Fritze
Browse files
Options
Downloads
Patches
Plain Diff
string tokenizer
parent
96ca7231
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
stuff/misc.hh
+54
-2
54 additions, 2 deletions
stuff/misc.hh
with
54 additions
and
2 deletions
stuff/misc.hh
+
54
−
2
View file @
0fbcbd33
...
...
@@ -35,6 +35,7 @@ bool isnan(T x)
#include
<fstream>
#include
<ostream>
#include
<sstream>
#include
<iomanip>
#include
<vector>
#include
<assert.h>
#include
<cmath>
...
...
@@ -621,8 +622,6 @@ bool testCreateDirectory(std::string path)
return
true
;
}
}
// end namepspace stuff
template
<
typename
T
>
std
::
string
getParameterString
(
const
std
::
string
&
prefix
,
T
min
,
T
max
,
T
inc
)
{
...
...
@@ -634,4 +633,57 @@ std::string getParameterString(const std::string& prefix, T min, T max, T inc)
return
ss
.
str
();
}
template
<
class
TokenType
>
class
Tokenizer
{
protected:
typedef
std
::
vector
<
TokenType
>
Tokens
;
typedef
typename
Tokens
::
iterator
TokenIterator
;
public:
Tokenizer
(
const
std
::
string
tokenstring
,
const
std
::
string
delimiters
)
{
// code taken from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html
// Skip delimiters at beginning.
std
::
string
::
size_type
lastPos
=
tokenstring
.
find_first_not_of
(
delimiters
,
0
);
// Find first "non-delimiter".
std
::
string
::
size_type
pos
=
tokenstring
.
find_first_of
(
delimiters
,
lastPos
);
while
(
std
::
string
::
npos
!=
pos
||
std
::
string
::
npos
!=
lastPos
)
{
// Found a token, add it to the vector.
tokens_
.
push_back
(
fromString
<
TokenType
>
(
tokenstring
.
substr
(
lastPos
,
pos
-
lastPos
)));
// Skip delimiters. Note the "not_of"
lastPos
=
tokenstring
.
find_first_not_of
(
delimiters
,
pos
);
// Find next "non-delimiter"
pos
=
tokenstring
.
find_first_of
(
delimiters
,
lastPos
);
}
currentToken_
=
tokens_
.
begin
();
}
Tokens
getTokens
()
{
return
tokens_
;
}
bool
hasMoreTokens
()
{
return
currentToken_
!=
tokens_
.
end
();
}
TokenType
getNextToken
()
{
TokenType
ret
=
*
currentToken_
;
++
currentToken_
;
return
ret
;
}
protected
:
TokenIterator
currentToken_
;
Tokens
tokens_
;
};
typedef
Tokenizer
<
std
::
string
>
StringTokenizer
;
}
// end namepspace stuff
#endif // end of stuff.hh
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment