| 71 | } |
| 72 | |
| 73 | void processAdd(const std::string& line, int num, IptcData& iptcData) { |
| 74 | std::string::size_type keyStart = line.find_first_not_of(" \t", 1); |
| 75 | std::string::size_type keyEnd = line.find_first_of(" \t", keyStart + 1); |
| 76 | std::string::size_type dataStart = line.find_first_not_of(" \t", keyEnd + 1); |
| 77 | |
| 78 | if (keyStart == std::string::npos || keyEnd == std::string::npos || dataStart == std::string::npos) { |
| 79 | std::ostringstream os; |
| 80 | os << "Invalid \'a\' command at line " << num; |
| 81 | throw Error(ErrorCode::kerErrorMessage, os.str()); |
| 82 | } |
| 83 | |
| 84 | std::string key(line.substr(keyStart, keyEnd - keyStart)); |
| 85 | IptcKey iptcKey(key); |
| 86 | |
| 87 | std::string data(line.substr(dataStart)); |
| 88 | // if data starts and ends with quotes, remove them |
| 89 | if (data.at(0) == '\"' && data.at(data.size() - 1) == '\"') { |
| 90 | data = data.substr(1, data.size() - 2); |
| 91 | } |
| 92 | TypeId type = IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record()); |
| 93 | Value::UniquePtr value = Value::create(type); |
| 94 | value->read(data); |
| 95 | |
| 96 | int rc = iptcData.add(iptcKey, value.get()); |
| 97 | if (rc) { |
| 98 | throw Error(ErrorCode::kerErrorMessage, "Iptc dataset already exists and is not repeatable"); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | void processRemove(const std::string& line, int num, IptcData& iptcData) { |
| 103 | std::string::size_type keyStart = line.find_first_not_of(" \t", 1); |