diff options
| author | 2019-09-24 13:42:30 +0200 | |
|---|---|---|
| committer | 2019-09-24 23:04:27 +0200 | |
| commit | 79cddf83484b042bbffb95a274abe693a74c5efa (patch) | |
| tree | 9ce5e34a613f7e1334d6c365d91ec3ef2096222e | |
| parent | 7a4f7a1bcc5bd0d677297493452ab79c1ab30efe (diff) | |
| download | OneRoll-79cddf83484b042bbffb95a274abe693a74c5efa.tar.gz OneRoll-79cddf83484b042bbffb95a274abe693a74c5efa.zip | |
Improve alias replacement
| -rw-r--r-- | dicealias.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/dicealias.cpp b/dicealias.cpp index 7c64de9..0378867 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -29,8 +29,33 @@ QString makeReplament(const QString& pattern, const QString& replacement, QStrin auto hasPattern= cmd.contains(pattern); if(hasPattern) { + auto idxPattern= cmd.indexOf(pattern); + std::vector<std::pair<int, int>> quotes; + + int pos= 0; + bool open= true; + while(pos != -1 && pos < cmd.size()) + { + auto oldPos= pos; + pos= cmd.indexOf("\"", pos); + if(open && pos != -1) + open= false; + else if(pos != -1) + { + quotes.push_back({oldPos, pos}); + } + + if(pos != -1) + pos+= 1; + } + auto hasQuote= false; + for(auto range : quotes) + { + if(idxPattern < range.second && idxPattern > range.first) + hasQuote= true; + } + auto hasVariable= cmd.contains("${"); - auto hasQuote= cmd.contains("\""); auto commentPos= cmd.lastIndexOf("#"); if(!hasQuote && !hasVariable) |