| 42 | ResourceQuantities result; |
| 43 | |
| 44 | foreach (const string& token, strings::tokenize(text, ";")) { |
| 45 | vector<string> pair = strings::tokenize(token, ":"); |
| 46 | if (pair.size() != 2) { |
| 47 | return Error("Failed to parse '" + token + "': missing or extra ':'"); |
| 48 | } |
| 49 | |
| 50 | Try<Value> value = internal::values::parse(pair[1]); |
| 51 | if (value.isError()) { |
| 52 | return Error( |
| 53 | "Failed to parse '" + pair[1] + "' to quantity: " + value.error()); |
| 54 | } |
| 55 | |
| 56 | if (value->type() != Value::SCALAR) { |
| 57 | return Error( |
| 58 | "Failed to parse '" + pair[1] + "' to quantity:" |
| 59 | " only scalar values are allowed"); |
| 60 | } |
| 61 | |
| 62 | if (value->scalar().value() < 0) { |
| 63 | return Error( |
| 64 | "Failed to parse '" + pair[1] + "' to quantity:" |
| 65 | " negative values are not allowed"); |
| 66 | } else if (value->scalar().value() > 0) { |
| 67 | result.add(strings::trim(pair[0]), value->scalar()); |
| 68 | } |
| 69 | // Zero value is silently dropped. |
| 70 | } |
| 71 | |
| 72 | return result; |
| 73 | } |
nothing calls this directly
no test coverage detected