]> sigrok.org Git - pulseview.git/commitdiff
Fix #1201 by letting more accurate matches replace previous ones
authorSoeren Apel <redacted>
Sun, 27 May 2018 08:00:42 +0000 (10:00 +0200)
committerSoeren Apel <redacted>
Sun, 27 May 2018 08:00:42 +0000 (10:00 +0200)
pv/data/decodesignal.cpp

index fbbdd793952d4ffd578532944ae4cab9c66ecfe5..baef9ce191ddeebd7ea2a480e0e4957b19a5d460 100644 (file)
@@ -279,19 +279,33 @@ void DecodeSignal::auto_assign_signals(const shared_ptr<Decoder> dec)
                if (ch.assigned_signal)
                        continue;
 
+               const QString ch_name = ch.name.toLower();
+
+               shared_ptr<data::SignalBase> match;
                for (shared_ptr<data::SignalBase> 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) {