| 118 | } |
| 119 | |
| 120 | void processModify(const std::string& line, int num, IptcData& iptcData) { |
| 121 | std::string::size_type keyStart = line.find_first_not_of(" \t", 1); |
| 122 | std::string::size_type keyEnd = line.find_first_of(" \t", keyStart + 1); |
| 123 | std::string::size_type dataStart = line.find_first_not_of(" \t", keyEnd + 1); |
| 124 | |
| 125 | if (keyStart == std::string::npos || keyEnd == std::string::npos || dataStart == std::string::npos) { |
| 126 | std::ostringstream os; |
| 127 | os << "Invalid \'m\' command at line " << num; |
| 128 | throw Error(ErrorCode::kerErrorMessage, os.str()); |
| 129 | } |
| 130 | |
| 131 | std::string key(line.substr(keyStart, keyEnd - keyStart)); |
| 132 | IptcKey iptcKey(key); |
| 133 | |
| 134 | std::string data(line.substr(dataStart)); |
| 135 | // if data starts and ends with quotes, remove them |
| 136 | if (data.at(0) == '\"' && data.at(data.size() - 1) == '\"') { |
| 137 | data = data.substr(1, data.size() - 2); |
| 138 | } |
| 139 | TypeId type = IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record()); |
| 140 | Value::UniquePtr value = Value::create(type); |
| 141 | value->read(data); |
| 142 | |
| 143 | auto iter = iptcData.findKey(iptcKey); |
| 144 | if (iter != iptcData.end()) { |
| 145 | iter->setValue(value.get()); |
| 146 | } else { |
| 147 | int rc = iptcData.add(iptcKey, value.get()); |
| 148 | if (rc) { |
| 149 | throw Error(ErrorCode::kerErrorMessage, "Iptc dataset already exists and is not repeatable"); |
| 150 | } |
| 151 | } |
| 152 | } |