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/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);