mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
devices: use case-insensitive comparison for model
Recently, the sorting of the devices was changed to be case-insensitive for models for consistency reasons. However, then the equality-comparison should also be case-insensitive. Break it out into its own function, to avoid that mistake in the future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
c046742288
commit
6b1be8c4f6
1 changed files with 11 additions and 4 deletions
|
@ -203,6 +203,11 @@ bool device::operator==(const device &a) const
|
|||
nickName == a.nickName;
|
||||
}
|
||||
|
||||
static bool same_device(const device &dev1, const device &dev2)
|
||||
{
|
||||
return dev1.deviceId == dev2.deviceId && strcoll(dev1.model.c_str(), dev2.model.c_str()) == 0;
|
||||
}
|
||||
|
||||
bool device::operator<(const device &a) const
|
||||
{
|
||||
if (deviceId != a.deviceId)
|
||||
|
@ -216,8 +221,9 @@ bool device::operator<(const device &a) const
|
|||
const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc)
|
||||
{
|
||||
const std::vector<device> &dcs = table->devices;
|
||||
auto it = std::lower_bound(dcs.begin(), dcs.end(), device{dc->model, dc->deviceid, {}, {}, {}});
|
||||
return it != dcs.end() && it->model == dc->model && it->deviceId == dc->deviceid ? &*it : NULL;
|
||||
device dev { dc->model, dc->deviceid, {}, {}, {} };
|
||||
auto it = std::lower_bound(dcs.begin(), dcs.end(), dev);
|
||||
return it != dcs.end() && same_device(*it, dev) ? &*it : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -263,8 +269,9 @@ static void addDC(std::vector<device> &dcs, const std::string &m, uint32_t d, co
|
|||
{
|
||||
if (m.empty() || d == 0)
|
||||
return;
|
||||
auto it = std::lower_bound(dcs.begin(), dcs.end(), device{m, d, {}, {}, {}});
|
||||
if (it != dcs.end() && it->model == m && it->deviceId == d) {
|
||||
device dev { m, d, {}, {}, {} };
|
||||
auto it = std::lower_bound(dcs.begin(), dcs.end(), dev);
|
||||
if (it != dcs.end() && same_device(*it, dev)) {
|
||||
// debugging: show changes
|
||||
if (verbose)
|
||||
it->showchanges(n, s, f);
|
||||
|
|
Loading…
Add table
Reference in a new issue