From 6b1be8c4f6aee3f7793198a9e34af8fefbc2f1cc Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 17 Oct 2020 13:54:29 +0200 Subject: 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 --- core/device.cpp | 15 +++++++++++---- 1 file 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 &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 &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); -- cgit v1.2.3-70-g09d2