| 130 | } |
| 131 | |
| 132 | QString Utils::unquote(const QString& str, bool unescapeUnicode, QChar quoteCh) |
| 133 | { |
| 134 | if (str.startsWith(quoteCh) && str.endsWith(quoteCh)) { |
| 135 | QString res; |
| 136 | res.reserve(str.length()); |
| 137 | bool esc = false; |
| 138 | int type = 0; |
| 139 | QString escSeq; |
| 140 | escSeq.reserve(4); |
| 141 | // skip beginning and ending quoteCh, no need for str = str.mid(1, str.length() - 2) |
| 142 | for (int i = 1; i != str.length() - 1; i++) { |
| 143 | auto ch = str[i]; |
| 144 | if (esc) { |
| 145 | switch (ch.unicode()) { |
| 146 | case '\\': |
| 147 | if (type != 0) { |
| 148 | escSeq += ch; |
| 149 | qCDebug(DEBUGGERCOMMON) << "Unrecognized escape sequence:" << escSeq; |
| 150 | res += QLatin1Char('\\'); |
| 151 | res += escSeq; |
| 152 | escSeq.clear(); |
| 153 | esc = false; |
| 154 | type = 0; |
| 155 | } else { |
| 156 | res.append(QLatin1Char('\\')); |
| 157 | // escSeq.clear(); // escSeq must be empty. |
| 158 | esc = false; |
| 159 | } |
| 160 | break; |
| 161 | case 'u': |
| 162 | case 'x': |
| 163 | if (type != 0 || !unescapeUnicode) { |
| 164 | escSeq += ch; |
| 165 | qCDebug(DEBUGGERCOMMON) << "Unrecognized escape sequence:" << escSeq; |
| 166 | res += QLatin1Char('\\'); |
| 167 | res += escSeq; |
| 168 | escSeq.clear(); |
| 169 | esc = false; |
| 170 | type = 0; |
| 171 | } else { |
| 172 | type = ch == QLatin1Char('u') ? 1 : 2; |
| 173 | } |
| 174 | break; |
| 175 | case '0': case '1': case '2': case '3': case '4': |
| 176 | case '5': case '6': case '7': case '8': case '9': |
| 177 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
| 178 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': |
| 179 | escSeq += ch; |
| 180 | if (type == 0) { |
| 181 | qCDebug(DEBUGGERCOMMON) << "Unrecognized escape sequence:" << escSeq; |
| 182 | res += QLatin1Char('\\'); |
| 183 | res += escSeq; |
| 184 | escSeq.clear(); |
| 185 | esc = false; |
| 186 | type = 0; |
| 187 | } else { |
| 188 | // \uNNNN |
| 189 | // \xNN |