|
29 | 29 |
|
30 | 30 | #include <qfileinfo.h>
|
31 | 31 | #include <qdir.h>
|
32 |
| -#include <qregexp.h> |
33 | 32 |
|
34 | 33 | #include <thread>
|
35 | 34 | #include <algorithm>
|
| 35 | +#include <regex> |
36 | 36 |
|
37 | 37 | #include "configimpl.h"
|
38 | 38 | #include "version.h"
|
@@ -1132,25 +1132,31 @@ void ConfigImpl::emptyValueToDefault()
|
1132 | 1132 | }
|
1133 | 1133 | }
|
1134 | 1134 |
|
1135 |
| -static void substEnvVarsInString(QCString &s) |
| 1135 | +static void substEnvVarsInString(QCString &str) |
1136 | 1136 | {
|
1137 |
| - static QRegExp re("\\$\\([a-z_A-Z0-9.-]+\\)"); |
1138 |
| - static QRegExp re2("\\$\\([a-z_A-Z0-9.-]+\\([a-z_A-Z0-9.-]+\\)\\)"); // For e.g. PROGRAMFILES(X86) |
1139 |
| - if (s.isEmpty()) return; |
1140 |
| - int p=0; |
1141 |
| - int i,l; |
1142 |
| - //printf("substEnvVarInString(%s) start\n",s.data()); |
1143 |
| - while ((i=re.match(s,p,&l))!=-1 || (i=re2.match(s,p,&l))!=-1) |
| 1137 | + if (str.isEmpty()) return; |
| 1138 | + // match e.g. $(HOME) but also $(PROGRAMFILES(X86)) |
| 1139 | + static std::regex re("\\$\\([[:alpha:]_][[:alnum:].-]*(\\([[:alpha:]_][[:alnum:].-]*\\))?\\)"); |
| 1140 | + std::string s = str.str(); |
| 1141 | + std::sregex_iterator it(s.begin(),s.end(),re); |
| 1142 | + std::sregex_iterator end; |
| 1143 | + std::string result; |
| 1144 | + size_t p = 0; |
| 1145 | + for (; it!=end ; ++it) |
1144 | 1146 | {
|
1145 |
| - //printf("Found environment var s.mid(%d,%d)='%s'\n",i+2,l-3,s.mid(i+2,l-3).data()); |
1146 |
| - QCString env=Portable::getenv(s.mid(i+2,l-3)); |
| 1147 | + const auto &match = *it; |
| 1148 | + size_t i = match.position(); |
| 1149 | + size_t l = match.length(); |
| 1150 | + result+=s.substr(p,i-p); |
| 1151 | + std::string matchStr = match.str(); |
| 1152 | + std::string matchContents = matchStr.substr(2,matchStr.length()-3); |
| 1153 | + QCString env=Portable::getenv(matchContents.c_str()); // get content of $(..) match |
1147 | 1154 | substEnvVarsInString(env); // recursively expand variables if needed.
|
1148 |
| - s = s.left(i)+env+s.right(s.length()-i-l); |
1149 |
| - p=i+env.length(); // next time start at the end of the expanded string |
| 1155 | + result+=env.str(); |
| 1156 | + p=i+l; |
1150 | 1157 | }
|
1151 |
| - s=s.stripWhiteSpace(); // to strip the bogus space that was added when an argument |
1152 |
| - // has quotes |
1153 |
| - //printf("substEnvVarInString(%s) end\n",s.data()); |
| 1158 | + result+=s.substr(p); |
| 1159 | + str = QCString(result).stripWhiteSpace(); |
1154 | 1160 | }
|
1155 | 1161 |
|
1156 | 1162 | static void substEnvVarsInStrList(StringVector &sl)
|
@@ -1641,16 +1647,16 @@ void Config::checkAndCorrect()
|
1641 | 1647 | //------------------------
|
1642 | 1648 | // check ALIASES
|
1643 | 1649 | const StringVector &aliasList = Config_getList(ALIASES);
|
1644 |
| - for (const auto &s : aliasList) |
| 1650 | + for (const auto &alias : aliasList) |
1645 | 1651 | {
|
1646 |
| - QRegExp re1("[a-z_A-Z][a-z_A-Z0-9]*[ \t]*="); // alias without argument |
1647 |
| - QRegExp re2("[a-z_A-Z][a-z_A-Z0-9]*{[0-9]+}[ \t]*="); // alias with argument |
1648 |
| - QCString alias=s.c_str(); |
1649 |
| - alias=alias.stripWhiteSpace(); |
1650 |
| - if (alias.find(re1)!=0 && alias.find(re2)!=0) |
| 1652 | + // match aliases of the form 'name=' and 'name{2} =' |
| 1653 | + static std::regex re("[[:alpha:]_][[:alnum:]_]*(\\{[[:digit:]]+\\})?[[:space:]]*="); |
| 1654 | + std::sregex_iterator it(alias.begin(),alias.end(),re); |
| 1655 | + std::sregex_iterator end; |
| 1656 | + if (it==end) |
1651 | 1657 | {
|
1652 | 1658 | err("Illegal ALIASES format '%s'. Use \"name=value\" or \"name{n}=value\", where n is the number of arguments\n",
|
1653 |
| - alias.data()); |
| 1659 | + alias.c_str()); |
1654 | 1660 | }
|
1655 | 1661 | }
|
1656 | 1662 |
|
|
0 commit comments