diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-17 13:54:29 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-17 09:04:20 -0700 |
commit | 6b1be8c4f6aee3f7793198a9e34af8fefbc2f1cc (patch) | |
tree | 4ba8d347d689bcd17bce8961d8a0e091816e161b | |
parent | c0467422888602b53d673d49a955d1d878cb24d5 (diff) | |
download | subsurface-6b1be8c4f6aee3f7793198a9e34af8fefbc2f1cc.tar.gz |
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>
-rw-r--r-- | core/device.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/core/device.cpp b/core/device.cpp index 1e8e0792c..48d66244f 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -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); |