mirror of
https://github.com/YosysHQ/yosys
synced 2026-03-02 19:56:57 +00:00
Add IdString::unescape() method
We've already talked about adding this as an alternative to `log_id()`, and we'll need it later in this PR.
This commit is contained in:
parent
ac96f318ef
commit
577191e44d
1 changed files with 12 additions and 1 deletions
|
|
@ -275,6 +275,17 @@ struct RTLIL::IdString
|
||||||
*out += std::to_string(-index_);
|
*out += std::to_string(-index_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string unescape() const {
|
||||||
|
if (index_ < 0) {
|
||||||
|
// Must start with "$auto$" so no unescaping required.
|
||||||
|
return str();
|
||||||
|
}
|
||||||
|
std::string_view str = global_id_storage_.at(index_).str_view();
|
||||||
|
if (str.size() < 2 || str[0] != '\\' || str[1] == '$' || str[1] == '\\' || (str[1] >= '0' && str[1] <= '9'))
|
||||||
|
return std::string(str);
|
||||||
|
return std::string(str.substr(1));
|
||||||
|
}
|
||||||
|
|
||||||
class Substrings {
|
class Substrings {
|
||||||
std::string_view first_;
|
std::string_view first_;
|
||||||
int suffix_number;
|
int suffix_number;
|
||||||
|
|
@ -758,7 +769,7 @@ namespace RTLIL {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string unescape_id(RTLIL::IdString str) {
|
static inline std::string unescape_id(RTLIL::IdString str) {
|
||||||
return unescape_id(str.str());
|
return str.unescape();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline const char *id2cstr(RTLIL::IdString str) {
|
static inline const char *id2cstr(RTLIL::IdString str) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue