]> sigrok.org Git - pulseview.git/commitdiff
HardwareDevice: Only show non-empty device name components.
authorUwe Hermann <redacted>
Tue, 24 Jul 2018 20:07:25 +0000 (22:07 +0200)
committerUwe Hermann <redacted>
Tue, 24 Jul 2018 20:09:51 +0000 (22:09 +0200)
Fields such as vendor, version, serial number etc. are not always
provided by drivers. Avoid printing them, since it causes stray
whitespace to be added to the displayed strings.

pv/devices/hardwaredevice.cpp

index 50cab7b09b7c6f2c63c63549c57f5491297baceb..a3d84d6fadf175973fab3a2a420f190838948fc2 100644 (file)
@@ -54,8 +54,13 @@ HardwareDevice::~HardwareDevice()
 
 string HardwareDevice::full_name() const
 {
-       vector<string> parts = {device_->vendor(), device_->model(),
-               device_->version()};
+       vector<string> parts = {};
+       if (device_->vendor().length() > 0)
+               parts.push_back(device_->vendor());
+       if (device_->model().length() > 0)
+               parts.push_back(device_->model());
+       if (device_->version().length() > 0)
+               parts.push_back(device_->version());
        if (device_->serial_number().length() > 0)
                parts.push_back("[S/N: " + device_->serial_number() + "]");
        if (device_->connection_id().length() > 0)
@@ -86,11 +91,17 @@ string HardwareDevice::display_name(
                                dev->device_ != device_;
                });
 
-       vector<string> parts = {device_->vendor(), device_->model()};
+       vector<string> parts = {};
+       if (device_->vendor().length() > 0)
+               parts.push_back(device_->vendor());
+       if (device_->model().length() > 0)
+               parts.push_back(device_->model());
 
        if (multiple_dev) {
-               parts.push_back(device_->version());
-               parts.push_back("[S/N: " + device_->serial_number() + "]");
+               if (device_->version().length() > 0)
+                       parts.push_back(device_->version());
+               if (device_->serial_number().length() > 0)
+                       parts.push_back("[S/N: " + device_->serial_number() + "]");
 
                if ((device_->serial_number().length() == 0) &&
                        (device_->connection_id().length() > 0))