Parses a series of space-separated key[=value|="value"] tokens from * str and returns the mappings in a QHash. If str was unable * to be parsed, ok is set to false. */
| 193 | * <b>str</b> and returns the mappings in a QHash. If <b>str</b> was unable |
| 194 | * to be parsed, <b>ok</b> is set to false. */ |
| 195 | QHash<QString,QString> |
| 196 | string_parse_keyvals(const QString &str, bool *ok) |
| 197 | { |
| 198 | int i, len; |
| 199 | bool tmp_ok; |
| 200 | QHash<QString,QString> keyvals; |
| 201 | |
| 202 | i = 0; |
| 203 | len = str.length(); |
| 204 | while (i < len && str[i].isSpace()) |
| 205 | i++; /* Skip initial whitespace */ |
| 206 | while (i < len) { |
| 207 | QString key, val; |
| 208 | |
| 209 | while (i < len && !str[i].isSpace() && str[i] != '=') |
| 210 | key.append(str[i++]); |
| 211 | |
| 212 | if (i < len && str[i] == '=') { |
| 213 | if (++i < len && str[i] == '\"') { |
| 214 | /* The value is wrapped in quotes */ |
| 215 | val.append(str[i]); |
| 216 | while (++i < len) { |
| 217 | val.append(str[i]); |
| 218 | if (str[i] == '\\') { |
| 219 | if (++i == len) |
| 220 | goto error; |
| 221 | val.append(str[i]); |
| 222 | } else if (str[i] == '\"') { |
| 223 | i++; |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | val = string_unescape(val, &tmp_ok); |
| 228 | if (!tmp_ok) |
| 229 | goto error; |
| 230 | keyvals.insert(key, val); |
| 231 | } else { |
| 232 | /* The value was not wrapped in quotes */ |
| 233 | while (i < len && !str[i].isSpace()) |
| 234 | val.append(str[i++]); |
| 235 | keyvals.insert(key, val); |
| 236 | } |
| 237 | } else { |
| 238 | /* The key had no value */ |
| 239 | keyvals.insert(key, QString("")); |
| 240 | } |
| 241 | while (i < len && str[i].isSpace()) |
| 242 | i++; |
| 243 | } |
| 244 | if (ok) |
| 245 | *ok = true; |
| 246 | return keyvals; |
| 247 | |
| 248 | error: |
| 249 | if (ok) |
| 250 | *ok = false; |
| 251 | return QHash<QString,QString>(); |
| 252 | } |
nothing calls this directly
no test coverage detected