mirror of https://github.com/YosysHQ/yosys.git
Added next_token() function (strtok() replacement)
This commit is contained in:
parent
986bcc13cb
commit
2c683102be
|
@ -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;
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace RTLIL {
|
|||
|
||||
std::string stringf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
std::string vstringf(const char *fmt, va_list ap);
|
||||
|
||||
std::string next_token(std::string &text, const char *sep);
|
||||
bool patmatch(const char *pattern, const char *string);
|
||||
|
||||
template<typename T> int GetSize(const T &obj) { return obj.size(); }
|
||||
|
|
Loading…
Reference in New Issue