Given a quoted string str , this function returns an unquoted, * unescaped string. str must start and end with an unescaped quote. */
| 168 | /** Given a quoted string <b>str</b>, this function returns an unquoted, |
| 169 | * unescaped string. <b>str</b> must start and end with an unescaped quote. */ |
| 170 | QString |
| 171 | string_unescape(const QString &str, bool *ok) |
| 172 | { |
| 173 | QString out; |
| 174 | |
| 175 | /* The string must start and end with an unescaped dquote */ |
| 176 | if (str.length() < 2 || !str.startsWith("\"") || !str.endsWith("\"") || |
| 177 | (str.endsWith("\\\"") && !str.endsWith("\\\\\""))) { |
| 178 | if (ok) |
| 179 | *ok = false; |
| 180 | return QString(); |
| 181 | } |
| 182 | for (int i = 1; i < str.length()-1; i++) { |
| 183 | if (str[i] == '\\') |
| 184 | i++; |
| 185 | out.append(str[i]); |
| 186 | } |
| 187 | if (ok) |
| 188 | *ok = true; |
| 189 | return out; |
| 190 | } |
| 191 | |
| 192 | /** Parses a series of space-separated key[=value|="value"] tokens from |
| 193 | * <b>str</b> and returns the mappings in a QHash. If <b>str</b> was unable |
no test coverage detected