MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / processModify

Function processModify

samples/iptctest.cpp:120–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120void 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}

Callers 1

processLineFunction · 0.85

Calls 10

ErrorFunction · 0.85
getMethod · 0.80
sizeMethod · 0.45
tagMethod · 0.45
recordMethod · 0.45
readMethod · 0.45
findKeyMethod · 0.45
endMethod · 0.45
setValueMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected