Merge pull request #2137 from Exiv2/mainRecoverRecordId
Recover IptDataSets::recordId in the API
This commit is contained in:
commit
5c36c690f9
@ -381,21 +381,6 @@ namespace Exiv2 {
|
|||||||
false, false, 0, 0, Exiv2::unsignedShort, IptcDataSets::application2, ""},
|
false, false, 0, 0, Exiv2::unsignedShort, IptcDataSets::application2, ""},
|
||||||
};
|
};
|
||||||
|
|
||||||
uint16_t recordId(const std::string& recordName)
|
|
||||||
{
|
|
||||||
uint16_t i;
|
|
||||||
for (i = IptcDataSets::application2; i > 0; --i) {
|
|
||||||
if (recordInfo_[i].name_ == recordName)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i == 0) {
|
|
||||||
if (!isHex(recordName, 4, "0x"))
|
|
||||||
throw Error(kerInvalidRecord, recordName);
|
|
||||||
std::istringstream is(recordName);
|
|
||||||
is >> std::hex >> i;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr DataSet unknownDataSet{
|
constexpr DataSet unknownDataSet{
|
||||||
0xffff, "Unknown dataset", N_("Unknown dataset"), N_("Unknown dataset"), false, true, 0,
|
0xffff, "Unknown dataset", N_("Unknown dataset"), N_("Unknown dataset"), false, true, 0,
|
||||||
@ -533,6 +518,21 @@ namespace Exiv2 {
|
|||||||
return recordInfo_[recordId].desc_;
|
return recordInfo_[recordId].desc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t IptcDataSets::recordId(const std::string& recordName)
|
||||||
|
{
|
||||||
|
uint16_t i;
|
||||||
|
for (i = IptcDataSets::application2; i > 0; --i) {
|
||||||
|
if (recordInfo_[i].name_ == recordName)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == 0) {
|
||||||
|
if (!isHex(recordName, 4, "0x"))
|
||||||
|
throw Error(kerInvalidRecord, recordName);
|
||||||
|
std::istringstream is(recordName);
|
||||||
|
is >> std::hex >> i;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
void IptcDataSets::dataSetList(std::ostream& os)
|
void IptcDataSets::dataSetList(std::ostream& os)
|
||||||
{
|
{
|
||||||
@ -629,7 +629,7 @@ namespace Exiv2 {
|
|||||||
std::string dataSetName = key_.substr(posDot2+1);
|
std::string dataSetName = key_.substr(posDot2+1);
|
||||||
|
|
||||||
// Use the parts of the key to find dataSet and recordId
|
// Use the parts of the key to find dataSet and recordId
|
||||||
uint16_t recId = recordId(recordName);
|
uint16_t recId = IptcDataSets::recordId(recordName);
|
||||||
uint16_t dataSet = IptcDataSets::dataSet(dataSetName, recId);
|
uint16_t dataSet = IptcDataSets::dataSet(dataSetName, recId);
|
||||||
|
|
||||||
// Possibly translate hex name parts (0xabcd) to real names
|
// Possibly translate hex name parts (0xabcd) to real names
|
||||||
|
|||||||
@ -210,6 +210,21 @@ TEST(IptcDataSets, recordDesc_)
|
|||||||
ASSERT_STREQ("Unknown dataset", IptcDataSets::recordDesc(3));
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::recordDesc(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, recordId_returnsExpectedIdWithValidRecordName)
|
||||||
|
{
|
||||||
|
ASSERT_EQ(IptcDataSets::envelope, IptcDataSets::recordId("Envelope"));
|
||||||
|
ASSERT_EQ(IptcDataSets::application2, IptcDataSets::recordId("Application2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, recordId_throwsExceptionWithInvalidRecordName)
|
||||||
|
{
|
||||||
|
ASSERT_THROW(IptcDataSets::recordId("NonExistingName"), Exiv2::Error);
|
||||||
|
ASSERT_THROW(IptcDataSets::recordId(""), Exiv2::Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------
|
// ----------------------
|
||||||
|
|
||||||
TEST(IptcDataSets, dataSetLists_printDatasetsIntoOstream)
|
TEST(IptcDataSets, dataSetLists_printDatasetsIntoOstream)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user