summaryrefslogtreecommitdiff
path: root/tools/aapt2/configuration/ConfigurationParser.cpp
diff options
context:
space:
mode:
authorShane Farmer <safarmer@google.com>2017-07-21 09:42:42 -0700
committerShane Farmer <safarmer@google.com>2017-07-25 00:01:18 +0000
commit1a21b8c04153b5b73a477ebd0622b24f3bbfc603 (patch)
tree8d5c576c1ff90db4f232805749115101497193d2 /tools/aapt2/configuration/ConfigurationParser.cpp
parentbad49cc0f765250336b674bcf3d7b10531a8278c (diff)
AAPT2: Update ReplacePlaceholder for artifact name parser
Update the artifact name parser to ensure that duplicate placeholders are treated as an error. Also applied suggested changes from ag/2447777. Test: ran unit tests Change-Id: Iab8fd9d9b81aa3008177141256ecd16ef04b0c34
Diffstat (limited to 'tools/aapt2/configuration/ConfigurationParser.cpp')
-rw-r--r--tools/aapt2/configuration/ConfigurationParser.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/tools/aapt2/configuration/ConfigurationParser.cpp b/tools/aapt2/configuration/ConfigurationParser.cpp
index d051120b9445..c56492c8af9d 100644
--- a/tools/aapt2/configuration/ConfigurationParser.cpp
+++ b/tools/aapt2/configuration/ConfigurationParser.cpp
@@ -118,21 +118,33 @@ const std::string& AbiToString(Abi abi) {
static bool ReplacePlaceholder(const std::string& placeholder, const Maybe<std::string>& value,
std::string* name, IDiagnostics* diag) {
size_t offset = name->find(placeholder);
- if (value) {
- if (offset == std::string::npos) {
+ bool found = (offset != std::string::npos);
+
+ // Make sure the placeholder was present if the desired value is present.
+ if (!found) {
+ if (value) {
diag->Error(DiagMessage() << "Missing placeholder for artifact: " << placeholder);
return false;
}
- name->replace(offset, placeholder.length(), value.value());
return true;
}
+ DCHECK(found) << "Missing return path for placeholder not found";
+
// Make sure the placeholder was not present if the desired value was not present.
- bool result = (offset == std::string::npos);
- if (!result) {
+ if (!value) {
diag->Error(DiagMessage() << "Placeholder present but no value for artifact: " << placeholder);
+ return false;
}
- return result;
+
+ name->replace(offset, placeholder.length(), value.value());
+
+ // Make sure there was only one instance of the placeholder.
+ if (name->find(placeholder) != std::string::npos) {
+ diag->Error(DiagMessage() << "Placeholder present multiple times: " << placeholder);
+ return false;
+ }
+ return true;
}
Maybe<std::string> Artifact::ToArtifactName(const std::string& format, IDiagnostics* diag) const {