diff options
author | Adam Lesinski <adamlesinski@google.com> | 2016-07-08 15:00:32 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2016-07-13 17:45:28 -0700 |
commit | d0f116b619feede0cfdb647157ce5ab4d50a1c46 (patch) | |
tree | 5b2a8663602ba2b267890ff85d3cf5618ac922b5 /tools/aapt2/Resource.h | |
parent | aaac91f4a00a9968ef107ea143e6f2f669f762f1 (diff) |
AAPT2: Remove usage of u16string
For legacy reasons, we kept around the use of UTF-16 internally
in AAPT2. We don't need this and this CL removes all instances of
std::u16string and StringPiece16. The only places still needed
are when interacting with the ResTable APIs that only operate in
UTF16.
Change-Id: I492475b84bb9014fa13bf992cff447ee7a5fe588
Diffstat (limited to 'tools/aapt2/Resource.h')
-rw-r--r-- | tools/aapt2/Resource.h | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/tools/aapt2/Resource.h b/tools/aapt2/Resource.h index 03ca42b286d6..22d75a2fb315 100644 --- a/tools/aapt2/Resource.h +++ b/tools/aapt2/Resource.h @@ -24,6 +24,7 @@ #include <iomanip> #include <limits> +#include <sstream> #include <string> #include <tuple> #include <vector> @@ -60,28 +61,28 @@ enum class ResourceType { kXml, }; -StringPiece16 toString(ResourceType type); +StringPiece toString(ResourceType type); /** * Returns a pointer to a valid ResourceType, or nullptr if * the string was invalid. */ -const ResourceType* parseResourceType(const StringPiece16& str); +const ResourceType* parseResourceType(const StringPiece& str); /** * A resource's name. This can uniquely identify * a resource in the ResourceTable. */ struct ResourceName { - std::u16string package; + std::string package; ResourceType type; - std::u16string entry; + std::string entry; ResourceName() : type(ResourceType::kRaw) {} - ResourceName(const StringPiece16& p, ResourceType t, const StringPiece16& e); + ResourceName(const StringPiece& p, ResourceType t, const StringPiece& e); bool isValid() const; - std::u16string toString() const; + std::string toString() const; }; /** @@ -91,15 +92,15 @@ struct ResourceName { * of the original string. */ struct ResourceNameRef { - StringPiece16 package; + StringPiece package; ResourceType type; - StringPiece16 entry; + StringPiece entry; ResourceNameRef() = default; ResourceNameRef(const ResourceNameRef&) = default; ResourceNameRef(ResourceNameRef&&) = default; ResourceNameRef(const ResourceName& rhs); - ResourceNameRef(const StringPiece16& p, ResourceType t, const StringPiece16& e); + ResourceNameRef(const StringPiece& p, ResourceType t, const StringPiece& e); ResourceNameRef& operator=(const ResourceNameRef& rhs) = default; ResourceNameRef& operator=(ResourceNameRef&& rhs) = default; ResourceNameRef& operator=(const ResourceName& rhs); @@ -252,7 +253,7 @@ inline ::std::ostream& operator<<(::std::ostream& out, const ResourceType& val) // ResourceName implementation. // -inline ResourceName::ResourceName(const StringPiece16& p, ResourceType t, const StringPiece16& e) : +inline ResourceName::ResourceName(const StringPiece& p, ResourceType t, const StringPiece& e) : package(p.toString()), type(t), entry(e.toString()) { } @@ -275,14 +276,6 @@ inline bool operator!=(const ResourceName& lhs, const ResourceName& rhs) { != std::tie(rhs.package, rhs.type, rhs.entry); } -inline std::u16string ResourceName::toString() const { - std::u16string result; - if (!package.empty()) { - result = package + u":"; - } - return result + aapt::toString(type).toString() + u"/" + entry; -} - inline ::std::ostream& operator<<(::std::ostream& out, const ResourceName& name) { if (!name.package.empty()) { out << name.package << ":"; @@ -290,6 +283,11 @@ inline ::std::ostream& operator<<(::std::ostream& out, const ResourceName& name) return out << name.type << "/" << name.entry; } +inline std::string ResourceName::toString() const { + std::stringstream stream; + stream << *this; + return stream.str(); +} // // ResourceNameRef implementation. @@ -299,8 +297,8 @@ inline ResourceNameRef::ResourceNameRef(const ResourceName& rhs) : package(rhs.package), type(rhs.type), entry(rhs.entry) { } -inline ResourceNameRef::ResourceNameRef(const StringPiece16& p, ResourceType t, - const StringPiece16& e) : +inline ResourceNameRef::ResourceNameRef(const StringPiece& p, ResourceType t, + const StringPiece& e) : package(p), type(t), entry(e) { } @@ -312,7 +310,7 @@ inline ResourceNameRef& ResourceNameRef::operator=(const ResourceName& rhs) { } inline ResourceName ResourceNameRef::toResourceName() const { - return { package.toString(), type, entry.toString() }; + return ResourceName(package, type, entry); } inline bool ResourceNameRef::isValid() const { |