From 1d6c1db4a5808da55b0b49f3d6460f3f10f5e917 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 14 Oct 2020 22:15:32 +0200 Subject: core: use case-insensitive comparison for device models The code in core/libdivecomputer.c used string insensitive comparison for device models, before being merged into core/device.c. Let's reinstate that behavior, since it appears to be more logical. On would assume that two different vendors will not use the same model with different casing (and the same device-ids), so that should be safe. This uses strcoll to correctly sort unicode, which will hopefully never be needed! Signed-off-by: Berthold Stoeger --- core/device.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core/device.cpp') diff --git a/core/device.cpp b/core/device.cpp index 4bfdd3ea4..c35aa74e9 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -205,7 +205,12 @@ bool device::operator==(const device &a) const bool device::operator<(const device &a) const { - return std::tie(deviceId, model) < std::tie(a.deviceId, a.model); + if (deviceId != a.deviceId) + return deviceId < a.deviceId; + + // Use strcoll to compare model-strings, since these might be unicode + // and therefore locale dependent? Let's hope that not, but who knows? + return strcoll(model.c_str(), a.model.c_str()) < 0; } const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc) -- cgit v1.2.3-70-g09d2