mirror of https://github.com/YosysHQ/yosys.git
handle edge cases
This commit is contained in:
parent
146491af22
commit
0bf20fdd19
|
|
@ -24,8 +24,7 @@
|
|||
|
||||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
// Normalize scope path: replace '/' with '.' and remove leading '.'
|
||||
// This allows supporting both Verdi-style (/top/module) and Yosys-style (top.module) scope paths
|
||||
// Normalize scope path: replace '/' with '.' and remove leading and trailing '.'
|
||||
inline std::string normalize_scope(std::string scope)
|
||||
{
|
||||
if (scope.empty())
|
||||
|
|
@ -33,13 +32,19 @@ inline std::string normalize_scope(std::string scope)
|
|||
|
||||
// Replace all '/' with '.'
|
||||
for (size_t i = 0; i < scope.length(); i++) {
|
||||
if (scope[i] == '/')
|
||||
if (scope[i] == '/') {
|
||||
if (i > 0 && scope[i-1] == '\\') continue; // skip escaped '/'
|
||||
scope[i] = '.';
|
||||
}
|
||||
}
|
||||
|
||||
// Remove leading '.' if present
|
||||
if (scope[0] == '.')
|
||||
scope = scope.substr(1);
|
||||
|
||||
// Remove trailing '.' if present (from a trailing '/')
|
||||
if (!scope.empty() && scope.back() == '.')
|
||||
scope = scope.substr(0, scope.size() - 1);
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue