mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: make fp_get_data return an std::string
No need for manual memory management. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8d96b7557d
commit
898ecd2df5
4 changed files with 17 additions and 12 deletions
|
@ -286,12 +286,20 @@ extern "C" uint32_t fp_get_diveid(struct fingerprint_table *table, unsigned int
|
|||
return table->fingerprints[i].fdiveid;
|
||||
}
|
||||
|
||||
extern "C" char *fp_get_data(struct fingerprint_table *table, unsigned int i)
|
||||
static char to_hex_digit(unsigned char d)
|
||||
{
|
||||
return d <= 9 ? d + '0' : d - 10 + 'a';
|
||||
}
|
||||
|
||||
std::string fp_get_data(struct fingerprint_table *table, unsigned int i)
|
||||
{
|
||||
if (!table || i >= table->fingerprints.size())
|
||||
return 0;
|
||||
return std::string();
|
||||
struct fingerprint_record *fpr = &table->fingerprints[i];
|
||||
// fromRawData() avoids one copy of the raw_data
|
||||
QByteArray hex = QByteArray::fromRawData((char *)fpr->raw_data, fpr->fsize).toHex();
|
||||
return strdup(hex.constData());
|
||||
std::string res(' ', fpr->fsize * 2);
|
||||
for (unsigned int i = 0; i < fpr->fsize; ++i) {
|
||||
res[2 * i] = to_hex_digit((fpr->raw_data[i] >> 4) & 0xf);
|
||||
res[2 * i + 1] = to_hex_digit(fpr->raw_data[i] & 0xf);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue