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

Function parseLine

app/exiv2.cpp:1323–1447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1321#endif
1322
1323bool parseLine(ModifyCmd& modifyCmd, const std::string& line, int num) {
1324 const std::string delim = " \t";
1325
1326 // Skip empty lines and comments
1327 std::string::size_type cmdStart = line.find_first_not_of(delim);
1328 if (cmdStart == std::string::npos || line[cmdStart] == '#')
1329 return false;
1330
1331 // Get command and key
1332 std::string::size_type cmdEnd = line.find_first_of(delim, cmdStart + 1);
1333 std::string::size_type keyStart = line.find_first_not_of(delim, cmdEnd + 1);
1334 std::string::size_type keyEnd = line.find_first_of(delim, keyStart + 1);
1335 if (cmdEnd == std::string::npos || keyStart == std::string::npos) {
1336 std::string cmdLine;
1337#ifdef _WIN32
1338 for (int i = 1; i < __argc; i++) {
1339 cmdLine += std::string(" ") + formatArg(__argv[i]);
1340 }
1341#endif
1342 throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
1343 std::to_string(num) + ": " + _("Invalid command line:") + cmdLine);
1344 }
1345
1346 std::string cmd(line.substr(cmdStart, cmdEnd - cmdStart));
1347 CmdId cmdId = commandId(cmd);
1348 if (cmdId == CmdId::invalid) {
1349 throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
1350 std::to_string(num) + ": " + _("Invalid command") + " `" + cmd + "'");
1351 }
1352
1353 Exiv2::TypeId defaultType = Exiv2::invalidTypeId;
1354 std::string key(line.substr(keyStart, keyEnd - keyStart));
1355 MetadataId metadataId = MetadataId::invalid;
1356 if (cmdId != CmdId::reg) {
1357 try {
1358 Exiv2::IptcKey iptcKey(key);
1359 metadataId = MetadataId::iptc;
1360 defaultType = Exiv2::IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record());
1361 } catch (const Exiv2::Error&) {
1362 }
1363 if (metadataId == MetadataId::invalid) {
1364 try {
1365 Exiv2::ExifKey exifKey(key);
1366 metadataId = MetadataId::exif;
1367 defaultType = exifKey.defaultTypeId();
1368 } catch (const Exiv2::Error&) {
1369 }
1370 }
1371 if (metadataId == MetadataId::invalid) {
1372 try {
1373 Exiv2::XmpKey xmpKey(key);
1374 metadataId = MetadataId::xmp;
1375 defaultType = Exiv2::XmpProperties::propertyType(xmpKey);
1376 } catch (const Exiv2::Error&) {
1377 }
1378 }
1379 if (metadataId == MetadataId::invalid) {
1380 throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,

Callers 2

parseCmdFilesFunction · 0.85
parseCmdLinesFunction · 0.85

Calls 9

formatArgFunction · 0.85
ErrorFunction · 0.85
commandIdFunction · 0.85
typeIdFunction · 0.85
parseEscapesFunction · 0.85
defaultTypeIdMethod · 0.80
tagMethod · 0.45
recordMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected