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

Function processAdd

samples/iptctest.cpp:73–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73void 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
102void processRemove(const std::string& line, int num, IptcData& iptcData) {
103 std::string::size_type keyStart = line.find_first_not_of(" \t", 1);

Callers 1

processLineFunction · 0.85

Calls 7

ErrorFunction · 0.85
getMethod · 0.80
sizeMethod · 0.45
tagMethod · 0.45
recordMethod · 0.45
readMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected