Cleaned up use of substr() to get interface's base name.

Bug: 31527442

Test: make at top-level. hidl_test passes.

Change-Id: Ia940a421599dc158e26fb7ea481abeab32620f65
diff --git a/Interface.cpp b/Interface.cpp
index 0fe7e87..a5d3c9b 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -58,8 +58,7 @@
 }
 
 std::string Interface::getBaseName() const {
-    // cut off the leading 'I'.
-    return localName().substr(1);
+    return fqName().getInterfaceBaseName();
 }
 
 std::string Interface::getCppType(StorageMode mode,
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 215d1eb..4987cc1 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -162,9 +162,6 @@
     enterLeaveNamespace(out, true /* enter */);
     out << "\n";
 
-    // cut off the leading 'I'.
-    const std::string baseName = ifaceName.substr(1);
-
     if (isInterface) {
         out << "struct "
             << ifaceName;
@@ -194,6 +191,7 @@
     if (isInterface) {
         const Interface *iface = mRootScope->getInterface();
         const Interface *superType = iface->superType();
+        const std::string baseName = iface->getBaseName();
         out << "constexpr static hidl_version version = {"
             << mPackage.getPackageMajorVersion() << ","
             << mPackage.getPackageMinorVersion() << "};\n";
@@ -283,8 +281,8 @@
         return OK;
     }
 
-    // cut off the leading 'I'.
-    const std::string baseName = ifaceName.substr(1);
+    const Interface *iface = mRootScope->getInterface();
+    const std::string baseName = iface->getBaseName();
 
     const std::string klassName = "IHw" + baseName;
 
@@ -331,8 +329,7 @@
             out << component << "/";
         }
 
-        // cut off the leading I
-        const std::string itemBaseName = item.name().substr(1);
+        const std::string itemBaseName = item.getInterfaceBaseName();
 
         out << "Bn"
             << itemBaseName
@@ -356,7 +353,6 @@
         << " : public "
         << ifaceName;
 
-    const Interface *iface = mRootScope->getInterface();
     const Interface *superType = iface->superType();
 
     out << ", public ::android::hardware::IInterface";
@@ -597,8 +593,8 @@
         return OK;
     }
 
-    // cut off the leading 'I'.
-    const std::string baseName = ifaceName.substr(1);
+    const Interface *iface = mRootScope->getInterface();
+    const std::string baseName = iface->getBaseName();
     const std::string klassName = "Bn" + baseName;
 
     std::string path = outputPath;
@@ -684,8 +680,8 @@
         return OK;
     }
 
-    // cut off the leading 'I'.
-    const std::string baseName = ifaceName.substr(1);
+    const Interface *iface = mRootScope->getInterface();
+    const std::string baseName = iface->getBaseName();
 
     std::string path = outputPath;
     path.append(mCoordinator->convertPackageRootToPath(mPackage));
@@ -771,7 +767,8 @@
         baseName = "types";
         isInterface = false;
     } else {
-        baseName = ifaceName.substr(1); // cut off the leading 'I'.
+        const Interface *iface = mRootScope->getInterface();
+        baseName = iface->getBaseName();
     }
 
     path.append(baseName);
diff --git a/generateCppImpl.cpp b/generateCppImpl.cpp
index bed1d1d..66a35d4 100644
--- a/generateCppImpl.cpp
+++ b/generateCppImpl.cpp
@@ -98,8 +98,7 @@
 
     const Interface *iface = mRootScope->getInterface();
 
-    // cut off the leading 'I'.
-    const std::string baseName = ifaceName.substr(1);
+    const std::string baseName = iface->getBaseName();
 
     std::string path = outputPath;
     path.append(baseName);
@@ -222,8 +221,8 @@
         return OK;
     }
 
-    // cut off the leading 'I'.
-    const std::string baseName = ifaceName.substr(1);
+    const Interface *iface = mRootScope->getInterface();
+    const std::string baseName = iface->getBaseName();
 
     std::string path = outputPath;
     path.append(baseName);
@@ -251,7 +250,6 @@
                     MethodLocation::IMPL_SOURCE,
                     false /* specify namespaces */);
 
-    const Interface *iface = mRootScope->getInterface();
 
     out << ifaceName
         << "* ";
diff --git a/generateJava.cpp b/generateJava.cpp
index df239a2..a5bdce6 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -119,8 +119,7 @@
 
     const Interface *iface = mRootScope->getInterface();
 
-    // cut off the leading 'I'.
-    const std::string baseName = ifaceName.substr(1);
+    const std::string baseName = iface->getBaseName();
 
     std::string path = outputPath;
     path.append(mCoordinator->convertPackageRootToPath(mPackage));
diff --git a/generateVts.cpp b/generateVts.cpp
index fe71487..c830918 100644
--- a/generateVts.cpp
+++ b/generateVts.cpp
@@ -85,7 +85,8 @@
         baseName = "types";
         isInterface = false;
     } else {
-        baseName = ifaceName.substr(1);  // cut off the leading 'I'.
+        const Interface *iface = mRootScope->getInterface();
+        baseName = iface->getBaseName();
     }
 
     path.append(baseName);