From: Soeren Apel Date: Sun, 27 May 2018 08:00:42 +0000 (+0200) Subject: Fix #1201 by letting more accurate matches replace previous ones X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a8030bb06fd94fe10a462f84bb8f3a4f51b4a05d;p=pulseview.git Fix #1201 by letting more accurate matches replace previous ones --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index fbbdd793..baef9ce1 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -279,19 +279,33 @@ void DecodeSignal::auto_assign_signals(const shared_ptr dec) if (ch.assigned_signal) continue; + const QString ch_name = ch.name.toLower(); + + shared_ptr match; for (shared_ptr s : session_.signalbases()) { if (!s->enabled()) continue; - const QString ch_name = ch.name.toLower(); const QString s_name = s->name().toLower(); if (s->logic_data() && ((ch_name.contains(s_name)) || (s_name.contains(ch_name)))) { - ch.assigned_signal = s.get(); - new_assignment = true; + if (!match) + match = s; + else { + // Only replace an existing match if it matches more characters + int old_unmatched = ch_name.length() - match->name().length(); + int new_unmatched = ch_name.length() - s->name().length(); + if (abs(new_unmatched) < abs(old_unmatched)) + match = s; + } } } + + if (match) { + ch.assigned_signal = match.get(); + new_assignment = true; + } } if (new_assignment) {