dbus-sdr: Remove suffixs appended by dbus-sensors

psusensor in dbus-sensors will append some suffixs in objectpath
and make the name easily exceeds 16 bytes.

This patch remove the suffix according to the appending rule in
psusensor.

See https://github.com/openbmc/intel-ipmi-oem/issues/4 for details.

Tested:

cpu0 pvccinfaon  | 17.224     | Amps       | ok    | na        | -5.176    | na        | na        | 51.048    | na
cpu1 pvccinfaon  | 16.552     | Amps       | ok    | na        | -5.176    | na        | na        | 51.048    | na
cpu0 pvccinfaon  | 23.884     | Watts      | ok    | na        | -9.864    | na        | na        | 57.060    | na
cpu1 pvccinfaon  | 23.026     | Watts      | ok    | na        | -9.864    | na        | na        | 57.060    | na
cpu0 pvccinfaon  | 45.000     | degrees C  | ok    | na        | 0.000     | 3.000     | 90.000    | 95.000    | na
cpu1 pvccinfaon  | 44.000     | degrees C  | ok    | na        | 0.000     | 3.000     | 90.000    | 95.000    | na
cpu0 pvccinfaon  | 1.014      | Volts      | ok    | na        | 0.858     | na        | na        | 1.131     | na
cpu1 pvccinfaon  | 1.014      | Volts      | ok    | na        | 0.858     | na        | na        | 1.131     | na
    │   ├─/xyz/openbmc_project/State/Decorator/cpu0_pvccinfaon_OperationalStatus
    │   ├─/xyz/openbmc_project/State/Decorator/cpu1_pvccinfaon_OperationalStatus
      │ ├─/xyz/openbmc_project/sensors/current/cpu0_pvccinfaon_Output_Current
      │ ├─/xyz/openbmc_project/sensors/current/cpu1_pvccinfaon_Output_Current
      │ ├─/xyz/openbmc_project/sensors/power/cpu0_pvccinfaon_Output_Power
      │ ├─/xyz/openbmc_project/sensors/power/cpu1_pvccinfaon_Output_Power
      │ ├─/xyz/openbmc_project/sensors/temperature/cpu0_pvccinfaon_Temperature
      │ ├─/xyz/openbmc_project/sensors/temperature/cpu1_pvccinfaon_Temperature
        ├─/xyz/openbmc_project/sensors/voltage/cpu0_pvccinfaon_Output_Voltage
        ├─/xyz/openbmc_project/sensors/voltage/cpu1_pvccinfaon_Output_Voltage

Signed-off-by: JeffLin <JeffLin2@quantatw.com>
Change-Id: I66620e6b6cd7088a848b79ea625c9cefa63f2053
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index 854d55f..f0f99a3 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -53,6 +53,9 @@
 } // namespace ipmi
 #endif
 
+constexpr std::array<const char*, 7> suffixes = {
+    "_Output_Voltage", "_Input_Voltage", "_Output_Current", "_Input_Current",
+    "_Output_Power",   "_Input_Power",   "_Temperature"};
 namespace ipmi
 {
 
@@ -416,20 +419,20 @@
         name = path.substr(nameStart + 1, std::string::npos - nameStart);
     }
 
-    std::replace(name.begin(), name.end(), '_', ' ');
     if (name.size() > FULL_RECORD_ID_STR_MAX_LENGTH)
     {
         // try to not truncate by replacing common words
-        constexpr std::array<std::pair<const char*, const char*>, 2>
-            replaceWords = {std::make_pair("Output", "Out"),
-                            std::make_pair("Input", "In")};
-        for (const auto& [find, replace] : replaceWords)
+        for (const auto& suffix : suffixes)
         {
-            boost::replace_all(name, find, replace);
+            if (boost::ends_with(name, suffix))
+            {
+                boost::replace_all(name, suffix, "");
+                break;
+            }
         }
-
         name.resize(FULL_RECORD_ID_STR_MAX_LENGTH);
     }
+    std::replace(name.begin(), name.end(), '_', ' ');
     return name;
 }