aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/yosys.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-10-10 18:33:55 +0200
committerClifford Wolf <clifford@clifford.at>2014-10-10 18:33:55 +0200
commit2c683102be85b0ee9c03c85ddcf5d7fd0f004ab7 (patch)
treef34f1a7ea05a6bb6d8f192e9f86ca8b3a22d51be /kernel/yosys.cc
parent986bcc13cbe6a085aa826e87f9d56bde22c7e521 (diff)
downloadyosys-2c683102be85b0ee9c03c85ddcf5d7fd0f004ab7.tar.gz
yosys-2c683102be85b0ee9c03c85ddcf5d7fd0f004ab7.tar.bz2
yosys-2c683102be85b0ee9c03c85ddcf5d7fd0f004ab7.zip
Added next_token() function (strtok() replacement)
Diffstat (limited to 'kernel/yosys.cc')
-rw-r--r--kernel/yosys.cc19
1 files changed, 18 insertions, 1 deletions
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index 7272c073b..96fe5446d 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -83,6 +83,23 @@ std::string vstringf(const char *fmt, va_list ap)
return string;
}
+std::string next_token(std::string &text, const char *sep)
+{
+ size_t pos_begin = text.find_first_not_of(sep);
+
+ if (pos_begin == string::npos)
+ pos_begin = text.size();
+
+ size_t pos_end = text.find_first_of(sep, pos_begin);
+
+ if (pos_end == string::npos)
+ pos_end = text.size();
+
+ std::string token = text.substr(pos_begin, pos_end-pos_begin);
+ text = text.substr(pos_end);
+ return token;
+}
+
// this is very similar to fnmatch(). the exact rules used by this
// function are:
//
@@ -94,7 +111,7 @@ std::string vstringf(const char *fmt, va_list ap)
// a backslash may be used to escape the next characters in the
// pattern. each special character can also simply match itself.
//
-static bool patmatch(const char *pattern, const char *string)
+bool patmatch(const char *pattern, const char *string)
{
if (*pattern == 0)
return *string == 0;