diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-06-08 11:41:09 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-06-09 11:14:24 -0700 |
commit | a1ad4a812a87642ad259ff4478159e8cc8194680 (patch) | |
tree | eff82221ed22a3be824ddf40823b2db3af002fb1 /tools/aapt2/Util.cpp | |
parent | b5766468538de200d26012d96019db26bccac5d4 (diff) | |
download | frameworks_base-a1ad4a812a87642ad259ff4478159e8cc8194680.zip frameworks_base-a1ad4a812a87642ad259ff4478159e8cc8194680.tar.gz frameworks_base-a1ad4a812a87642ad259ff4478159e8cc8194680.tar.bz2 |
AAPT2: Proguard rules generation added.
Change-Id: Ifbe79516cd9a1ade471e211a259301c63b62ac67
Diffstat (limited to 'tools/aapt2/Util.cpp')
-rw-r--r-- | tools/aapt2/Util.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/aapt2/Util.cpp b/tools/aapt2/Util.cpp index 7adaf1e..03ecd1a 100644 --- a/tools/aapt2/Util.cpp +++ b/tools/aapt2/Util.cpp @@ -102,6 +102,51 @@ StringPiece16::const_iterator findNonAlphaNumericAndNotInSet(const StringPiece16 return endIter; } +bool isJavaClassName(const StringPiece16& str) { + size_t pieces = 0; + for (const StringPiece16& piece : tokenize(str, u'.')) { + pieces++; + if (piece.empty()) { + return false; + } + + // Can't have starting or trailing $ character. + if (piece.data()[0] == u'$' || piece.data()[piece.size() - 1] == u'$') { + return false; + } + + if (findNonAlphaNumericAndNotInSet(piece, u"$_") != piece.end()) { + return false; + } + } + return pieces >= 2; +} + +Maybe<std::u16string> getFullyQualifiedClassName(const StringPiece16& package, + const StringPiece16& className) { + if (className.empty()) { + return {}; + } + + if (util::isJavaClassName(className)) { + return className.toString(); + } + + if (package.empty()) { + return {}; + } + + std::u16string result(package.data(), package.size()); + if (className.data()[0] != u'.') { + result += u'.'; + } + result.append(className.data(), className.size()); + if (!isJavaClassName(result)) { + return {}; + } + return result; +} + static Maybe<char16_t> parseUnicodeCodepoint(const char16_t** start, const char16_t* end) { char16_t code = 0; for (size_t i = 0; i < 4 && *start != end; i++, (*start)++) { |