Move StringPiece to libandroidfw
libandroidfw needs to make use of StringPiece, so move it to libandroidfw and update all code referencing StringPiece in aapt2. Test: make libandroidfw_tests libaapt2_tests Change-Id: I68d7f0fc7c651b048d9d1f5e7971f10ef5349fa1
This commit is contained in:
@@ -14,26 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef AAPT_STRING_PIECE_H
|
||||
#define AAPT_STRING_PIECE_H
|
||||
#ifndef ANDROIDFW_STRING_PIECE_H
|
||||
#define ANDROIDFW_STRING_PIECE_H
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "utils/JenkinsHash.h"
|
||||
#include "utils/String8.h"
|
||||
#include "utils/Unicode.h"
|
||||
|
||||
namespace aapt {
|
||||
namespace android {
|
||||
|
||||
/**
|
||||
* Read only wrapper around basic C strings.
|
||||
* Prevents excessive copying.
|
||||
*
|
||||
* WARNING: When creating from std::basic_string<>, moving the original
|
||||
* std::basic_string<> will invalidate the data held in a BasicStringPiece<>.
|
||||
* BasicStringPiece<> should only be used transitively.
|
||||
*/
|
||||
// Read only wrapper around basic C strings. Prevents excessive copying.
|
||||
// StringPiece does not own the data it is wrapping. The lifetime of the underlying
|
||||
// data must outlive this StringPiece.
|
||||
//
|
||||
// WARNING: When creating from std::basic_string<>, moving the original
|
||||
// std::basic_string<> will invalidate the data held in a BasicStringPiece<>.
|
||||
// BasicStringPiece<> should only be used transitively.
|
||||
template <typename TChar>
|
||||
class BasicStringPiece {
|
||||
public:
|
||||
@@ -53,15 +51,14 @@ class BasicStringPiece {
|
||||
BasicStringPiece<TChar>& assign(const TChar* str, size_t len);
|
||||
|
||||
BasicStringPiece<TChar> substr(size_t start, size_t len = npos) const;
|
||||
BasicStringPiece<TChar> substr(
|
||||
BasicStringPiece<TChar>::const_iterator begin,
|
||||
BasicStringPiece<TChar>::const_iterator end) const;
|
||||
BasicStringPiece<TChar> substr(BasicStringPiece<TChar>::const_iterator begin,
|
||||
BasicStringPiece<TChar>::const_iterator end) const;
|
||||
|
||||
const TChar* data() const;
|
||||
size_t length() const;
|
||||
size_t size() const;
|
||||
bool empty() const;
|
||||
std::basic_string<TChar> ToString() const;
|
||||
std::basic_string<TChar> to_string() const;
|
||||
|
||||
bool contains(const BasicStringPiece<TChar>& rhs) const;
|
||||
int compare(const BasicStringPiece<TChar>& rhs) const;
|
||||
@@ -89,17 +86,14 @@ template <typename TChar>
|
||||
constexpr const size_t BasicStringPiece<TChar>::npos;
|
||||
|
||||
template <typename TChar>
|
||||
inline BasicStringPiece<TChar>::BasicStringPiece()
|
||||
: data_(nullptr), length_(0) {}
|
||||
inline BasicStringPiece<TChar>::BasicStringPiece() : data_(nullptr), length_(0) {}
|
||||
|
||||
template <typename TChar>
|
||||
inline BasicStringPiece<TChar>::BasicStringPiece(
|
||||
const BasicStringPiece<TChar>& str)
|
||||
inline BasicStringPiece<TChar>::BasicStringPiece(const BasicStringPiece<TChar>& str)
|
||||
: data_(str.data_), length_(str.length_) {}
|
||||
|
||||
template <typename TChar>
|
||||
inline BasicStringPiece<TChar>::BasicStringPiece(
|
||||
const std::basic_string<TChar>& str)
|
||||
inline BasicStringPiece<TChar>::BasicStringPiece(const std::basic_string<TChar>& str)
|
||||
: data_(str.data()), length_(str.length()) {}
|
||||
|
||||
template <>
|
||||
@@ -123,16 +117,14 @@ inline BasicStringPiece<TChar>& BasicStringPiece<TChar>::operator=(
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline BasicStringPiece<TChar>& BasicStringPiece<TChar>::assign(
|
||||
const TChar* str, size_t len) {
|
||||
inline BasicStringPiece<TChar>& BasicStringPiece<TChar>::assign(const TChar* str, size_t len) {
|
||||
data_ = str;
|
||||
length_ = len;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline BasicStringPiece<TChar> BasicStringPiece<TChar>::substr(
|
||||
size_t start, size_t len) const {
|
||||
inline BasicStringPiece<TChar> BasicStringPiece<TChar>::substr(size_t start, size_t len) const {
|
||||
if (len == npos) {
|
||||
len = length_ - start;
|
||||
}
|
||||
@@ -171,13 +163,12 @@ inline bool BasicStringPiece<TChar>::empty() const {
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline std::basic_string<TChar> BasicStringPiece<TChar>::ToString() const {
|
||||
inline std::basic_string<TChar> BasicStringPiece<TChar>::to_string() const {
|
||||
return std::basic_string<TChar>(data_, length_);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool BasicStringPiece<char>::contains(
|
||||
const BasicStringPiece<char>& rhs) const {
|
||||
inline bool BasicStringPiece<char>::contains(const BasicStringPiece<char>& rhs) const {
|
||||
if (!data_ || !rhs.data_) {
|
||||
return false;
|
||||
}
|
||||
@@ -188,8 +179,7 @@ inline bool BasicStringPiece<char>::contains(
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int BasicStringPiece<char>::compare(
|
||||
const BasicStringPiece<char>& rhs) const {
|
||||
inline int BasicStringPiece<char>::compare(const BasicStringPiece<char>& rhs) const {
|
||||
const char nullStr = '\0';
|
||||
const char* b1 = data_ != nullptr ? data_ : &nullStr;
|
||||
const char* e1 = b1 + length_;
|
||||
@@ -205,15 +195,21 @@ inline int BasicStringPiece<char>::compare(
|
||||
return static_cast<int>(length_ - rhs.length_);
|
||||
}
|
||||
|
||||
inline ::std::ostream& operator<<(::std::ostream& out,
|
||||
const BasicStringPiece<char16_t>& str) {
|
||||
android::String8 utf8(str.data(), str.size());
|
||||
return out.write(utf8.string(), utf8.size());
|
||||
inline ::std::ostream& operator<<(::std::ostream& out, const BasicStringPiece<char16_t>& str) {
|
||||
const ssize_t result_len = utf16_to_utf8_length(str.data(), str.size());
|
||||
if (result_len < 0) {
|
||||
// Empty string.
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string result;
|
||||
result.resize(static_cast<size_t>(result_len));
|
||||
utf16_to_utf8(str.data(), str.length(), &*result.begin(), static_cast<size_t>(result_len) + 1);
|
||||
return out << result;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool BasicStringPiece<char16_t>::contains(
|
||||
const BasicStringPiece<char16_t>& rhs) const {
|
||||
inline bool BasicStringPiece<char16_t>::contains(const BasicStringPiece<char16_t>& rhs) const {
|
||||
if (!data_ || !rhs.data_) {
|
||||
return false;
|
||||
}
|
||||
@@ -224,8 +220,7 @@ inline bool BasicStringPiece<char16_t>::contains(
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int BasicStringPiece<char16_t>::compare(
|
||||
const BasicStringPiece<char16_t>& rhs) const {
|
||||
inline int BasicStringPiece<char16_t>::compare(const BasicStringPiece<char16_t>& rhs) const {
|
||||
const char16_t nullStr = u'\0';
|
||||
const char16_t* b1 = data_ != nullptr ? data_ : &nullStr;
|
||||
const char16_t* b2 = rhs.data_ != nullptr ? rhs.data_ : &nullStr;
|
||||
@@ -233,66 +228,52 @@ inline int BasicStringPiece<char16_t>::compare(
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline bool BasicStringPiece<TChar>::operator<(
|
||||
const BasicStringPiece<TChar>& rhs) const {
|
||||
inline bool BasicStringPiece<TChar>::operator<(const BasicStringPiece<TChar>& rhs) const {
|
||||
return compare(rhs) < 0;
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline bool BasicStringPiece<TChar>::operator>(
|
||||
const BasicStringPiece<TChar>& rhs) const {
|
||||
inline bool BasicStringPiece<TChar>::operator>(const BasicStringPiece<TChar>& rhs) const {
|
||||
return compare(rhs) > 0;
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline bool BasicStringPiece<TChar>::operator==(
|
||||
const BasicStringPiece<TChar>& rhs) const {
|
||||
inline bool BasicStringPiece<TChar>::operator==(const BasicStringPiece<TChar>& rhs) const {
|
||||
return compare(rhs) == 0;
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline bool BasicStringPiece<TChar>::operator!=(
|
||||
const BasicStringPiece<TChar>& rhs) const {
|
||||
inline bool BasicStringPiece<TChar>::operator!=(const BasicStringPiece<TChar>& rhs) const {
|
||||
return compare(rhs) != 0;
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline typename BasicStringPiece<TChar>::const_iterator
|
||||
BasicStringPiece<TChar>::begin() const {
|
||||
inline typename BasicStringPiece<TChar>::const_iterator BasicStringPiece<TChar>::begin() const {
|
||||
return data_;
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
inline typename BasicStringPiece<TChar>::const_iterator
|
||||
BasicStringPiece<TChar>::end() const {
|
||||
inline typename BasicStringPiece<TChar>::const_iterator BasicStringPiece<TChar>::end() const {
|
||||
return data_ + length_;
|
||||
}
|
||||
|
||||
inline ::std::ostream& operator<<(::std::ostream& out,
|
||||
const BasicStringPiece<char>& str) {
|
||||
inline ::std::ostream& operator<<(::std::ostream& out, const BasicStringPiece<char>& str) {
|
||||
return out.write(str.data(), str.size());
|
||||
}
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
inline ::std::ostream& operator<<(::std::ostream& out,
|
||||
const std::u16string& str) {
|
||||
android::String8 utf8(str.data(), str.size());
|
||||
return out.write(utf8.string(), utf8.size());
|
||||
}
|
||||
} // namespace android
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename TChar>
|
||||
struct hash<aapt::BasicStringPiece<TChar>> {
|
||||
size_t operator()(const aapt::BasicStringPiece<TChar>& str) const {
|
||||
struct hash<android::BasicStringPiece<TChar>> {
|
||||
size_t operator()(const android::BasicStringPiece<TChar>& str) const {
|
||||
uint32_t hashCode = android::JenkinsHashMixBytes(
|
||||
0, reinterpret_cast<const uint8_t*>(str.data()),
|
||||
sizeof(TChar) * str.size());
|
||||
0, reinterpret_cast<const uint8_t*>(str.data()), sizeof(TChar) * str.size());
|
||||
return static_cast<size_t>(hashCode);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // AAPT_STRING_PIECE_H
|
||||
#endif // ANDROIDFW_STRING_PIECE_H
|
||||
@@ -32,6 +32,7 @@ testFiles := \
|
||||
Main.cpp \
|
||||
ResTable_test.cpp \
|
||||
Split_test.cpp \
|
||||
StringPiece_test.cpp \
|
||||
TestHelpers.cpp \
|
||||
Theme_test.cpp \
|
||||
TypeWrappers_test.cpp \
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "util/StringPiece.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "test/Test.h"
|
||||
#include "TestHelpers.h"
|
||||
|
||||
namespace aapt {
|
||||
namespace android {
|
||||
|
||||
TEST(StringPieceTest, CompareNonNullTerminatedPiece) {
|
||||
StringPiece a("hello world", 5);
|
||||
@@ -92,4 +92,4 @@ TEST(StringPieceTest, ContainsOtherStringPiece) {
|
||||
EXPECT_FALSE(text16.contains(long_needle16));
|
||||
}
|
||||
|
||||
} // namespace aapt
|
||||
} // namespace android
|
||||
@@ -20,15 +20,16 @@
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/ResourceTypes.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "Locale.h"
|
||||
#include "SdkConstants.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
using android::ResTable_config;
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
static const char* kWildcardName = "any";
|
||||
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
#include <ostream>
|
||||
|
||||
#include "androidfw/ResourceTypes.h"
|
||||
|
||||
#include "util/StringPiece.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -42,7 +41,7 @@ struct ConfigDescription : public android::ResTable_config {
|
||||
* The resulting configuration has the appropriate sdkVersion defined
|
||||
* for backwards compatibility.
|
||||
*/
|
||||
static bool Parse(const StringPiece& str, ConfigDescription* out = nullptr);
|
||||
static bool Parse(const android::StringPiece& str, ConfigDescription* out = nullptr);
|
||||
|
||||
/**
|
||||
* If the configuration uses an axis that was added after
|
||||
|
||||
@@ -18,9 +18,12 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "SdkConstants.h"
|
||||
#include "test/Test.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
#include <string>
|
||||
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "Source.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
namespace aapt {
|
||||
@@ -38,7 +38,7 @@ struct DiagMessage {
|
||||
public:
|
||||
DiagMessage() = default;
|
||||
|
||||
explicit DiagMessage(const StringPiece& src) : source_(src) {}
|
||||
explicit DiagMessage(const android::StringPiece& src) : source_(src) {}
|
||||
|
||||
explicit DiagMessage(const Source& src) : source_(src) {}
|
||||
|
||||
@@ -59,6 +59,12 @@ struct DiagMessage {
|
||||
std::stringstream message_;
|
||||
};
|
||||
|
||||
template <>
|
||||
inline DiagMessage& DiagMessage::operator<<(const ::std::u16string& value) {
|
||||
message_ << android::StringPiece16(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
struct IDiagnostics {
|
||||
virtual ~IDiagnostics() = default;
|
||||
|
||||
|
||||
@@ -21,20 +21,22 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "util/StringPiece.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
Flags& Flags::RequiredFlag(const StringPiece& name,
|
||||
const StringPiece& description, std::string* value) {
|
||||
auto func = [value](const StringPiece& arg) -> bool {
|
||||
*value = arg.ToString();
|
||||
*value = arg.to_string();
|
||||
return true;
|
||||
};
|
||||
|
||||
flags_.push_back(
|
||||
Flag{name.ToString(), description.ToString(), func, true, 1, false});
|
||||
flags_.push_back(Flag{name.to_string(), description.to_string(), func, true, 1, false});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -42,12 +44,11 @@ Flags& Flags::RequiredFlagList(const StringPiece& name,
|
||||
const StringPiece& description,
|
||||
std::vector<std::string>* value) {
|
||||
auto func = [value](const StringPiece& arg) -> bool {
|
||||
value->push_back(arg.ToString());
|
||||
value->push_back(arg.to_string());
|
||||
return true;
|
||||
};
|
||||
|
||||
flags_.push_back(
|
||||
Flag{name.ToString(), description.ToString(), func, true, 1, false});
|
||||
flags_.push_back(Flag{name.to_string(), description.to_string(), func, true, 1, false});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -55,12 +56,11 @@ Flags& Flags::OptionalFlag(const StringPiece& name,
|
||||
const StringPiece& description,
|
||||
Maybe<std::string>* value) {
|
||||
auto func = [value](const StringPiece& arg) -> bool {
|
||||
*value = arg.ToString();
|
||||
*value = arg.to_string();
|
||||
return true;
|
||||
};
|
||||
|
||||
flags_.push_back(
|
||||
Flag{name.ToString(), description.ToString(), func, false, 1, false});
|
||||
flags_.push_back(Flag{name.to_string(), description.to_string(), func, false, 1, false});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -68,12 +68,11 @@ Flags& Flags::OptionalFlagList(const StringPiece& name,
|
||||
const StringPiece& description,
|
||||
std::vector<std::string>* value) {
|
||||
auto func = [value](const StringPiece& arg) -> bool {
|
||||
value->push_back(arg.ToString());
|
||||
value->push_back(arg.to_string());
|
||||
return true;
|
||||
};
|
||||
|
||||
flags_.push_back(
|
||||
Flag{name.ToString(), description.ToString(), func, false, 1, false});
|
||||
flags_.push_back(Flag{name.to_string(), description.to_string(), func, false, 1, false});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -81,12 +80,11 @@ Flags& Flags::OptionalFlagList(const StringPiece& name,
|
||||
const StringPiece& description,
|
||||
std::unordered_set<std::string>* value) {
|
||||
auto func = [value](const StringPiece& arg) -> bool {
|
||||
value->insert(arg.ToString());
|
||||
value->insert(arg.to_string());
|
||||
return true;
|
||||
};
|
||||
|
||||
flags_.push_back(
|
||||
Flag{name.ToString(), description.ToString(), func, false, 1, false});
|
||||
flags_.push_back(Flag{name.to_string(), description.to_string(), func, false, 1, false});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -97,8 +95,7 @@ Flags& Flags::OptionalSwitch(const StringPiece& name,
|
||||
return true;
|
||||
};
|
||||
|
||||
flags_.push_back(
|
||||
Flag{name.ToString(), description.ToString(), func, false, 0, false});
|
||||
flags_.push_back(Flag{name.to_string(), description.to_string(), func, false, 0, false});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -141,7 +138,7 @@ bool Flags::Parse(const StringPiece& command,
|
||||
for (size_t i = 0; i < args.size(); i++) {
|
||||
StringPiece arg = args[i];
|
||||
if (*(arg.data()) != '-') {
|
||||
args_.push_back(arg.ToString());
|
||||
args_.push_back(arg.to_string());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,32 +23,30 @@
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "util/Maybe.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
class Flags {
|
||||
public:
|
||||
Flags& RequiredFlag(const StringPiece& name, const StringPiece& description,
|
||||
Flags& RequiredFlag(const android::StringPiece& name, const android::StringPiece& description,
|
||||
std::string* value);
|
||||
Flags& RequiredFlagList(const StringPiece& name,
|
||||
const StringPiece& description,
|
||||
Flags& RequiredFlagList(const android::StringPiece& name, const android::StringPiece& description,
|
||||
std::vector<std::string>* value);
|
||||
Flags& OptionalFlag(const StringPiece& name, const StringPiece& description,
|
||||
Flags& OptionalFlag(const android::StringPiece& name, const android::StringPiece& description,
|
||||
Maybe<std::string>* value);
|
||||
Flags& OptionalFlagList(const StringPiece& name,
|
||||
const StringPiece& description,
|
||||
Flags& OptionalFlagList(const android::StringPiece& name, const android::StringPiece& description,
|
||||
std::vector<std::string>* value);
|
||||
Flags& OptionalFlagList(const StringPiece& name,
|
||||
const StringPiece& description,
|
||||
Flags& OptionalFlagList(const android::StringPiece& name, const android::StringPiece& description,
|
||||
std::unordered_set<std::string>* value);
|
||||
Flags& OptionalSwitch(const StringPiece& name, const StringPiece& description,
|
||||
Flags& OptionalSwitch(const android::StringPiece& name, const android::StringPiece& description,
|
||||
bool* value);
|
||||
|
||||
void Usage(const StringPiece& command, std::ostream* out);
|
||||
void Usage(const android::StringPiece& command, std::ostream* out);
|
||||
|
||||
bool Parse(const StringPiece& command, const std::vector<StringPiece>& args,
|
||||
bool Parse(const android::StringPiece& command, const std::vector<android::StringPiece>& args,
|
||||
std::ostream* outError);
|
||||
|
||||
const std::vector<std::string>& GetArgs();
|
||||
@@ -57,7 +55,7 @@ class Flags {
|
||||
struct Flag {
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::function<bool(const StringPiece& value)> action;
|
||||
std::function<bool(const android::StringPiece& value)> action;
|
||||
bool required;
|
||||
size_t num_args;
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ static inline bool is_number(const std::string& str) {
|
||||
return std::all_of(std::begin(str), std::end(str), ::isdigit);
|
||||
}
|
||||
|
||||
bool LocaleValue::InitFromFilterString(const StringPiece& str) {
|
||||
bool LocaleValue::InitFromFilterString(const android::StringPiece& str) {
|
||||
// A locale (as specified in the filter) is an underscore separated name such
|
||||
// as "en_US", "en_Latn_US", or "en_US_POSIX".
|
||||
std::vector<std::string> parts = util::SplitAndLowercase(str, '_');
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/ResourceTypes.h"
|
||||
|
||||
#include "util/StringPiece.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -40,7 +39,7 @@ struct LocaleValue {
|
||||
/**
|
||||
* Initialize this LocaleValue from a config string.
|
||||
*/
|
||||
bool InitFromFilterString(const StringPiece& config);
|
||||
bool InitFromFilterString(const android::StringPiece& config);
|
||||
|
||||
/**
|
||||
* Initialize this LocaleValue from parts of a vector.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "util/StringPiece.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -33,10 +33,10 @@ int PrintVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int Compile(const std::vector<StringPiece>& args);
|
||||
extern int Link(const std::vector<StringPiece>& args);
|
||||
extern int Dump(const std::vector<StringPiece>& args);
|
||||
extern int Diff(const std::vector<StringPiece>& args);
|
||||
extern int Compile(const std::vector<android::StringPiece>& args);
|
||||
extern int Link(const std::vector<android::StringPiece>& args);
|
||||
extern int Dump(const std::vector<android::StringPiece>& args);
|
||||
extern int Diff(const std::vector<android::StringPiece>& args);
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
@@ -45,12 +45,12 @@ int main(int argc, char** argv) {
|
||||
argv += 1;
|
||||
argc -= 1;
|
||||
|
||||
std::vector<aapt::StringPiece> args;
|
||||
std::vector<android::StringPiece> args;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
|
||||
aapt::StringPiece command(argv[0]);
|
||||
android::StringPiece command(argv[0]);
|
||||
if (command == "compile" || command == "c") {
|
||||
return aapt::Compile(args);
|
||||
} else if (command == "link" || command == "l") {
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
StringPiece ToString(ResourceType type) {
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "utils/JenkinsHash.h"
|
||||
|
||||
#include "ConfigDescription.h"
|
||||
#include "Source.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -63,13 +63,13 @@ enum class ResourceType {
|
||||
kXml,
|
||||
};
|
||||
|
||||
StringPiece ToString(ResourceType type);
|
||||
android::StringPiece ToString(ResourceType type);
|
||||
|
||||
/**
|
||||
* Returns a pointer to a valid ResourceType, or nullptr if
|
||||
* the string was invalid.
|
||||
*/
|
||||
const ResourceType* ParseResourceType(const StringPiece& str);
|
||||
const ResourceType* ParseResourceType(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* A resource's name. This can uniquely identify
|
||||
@@ -81,7 +81,7 @@ struct ResourceName {
|
||||
std::string entry;
|
||||
|
||||
ResourceName() = default;
|
||||
ResourceName(const StringPiece& p, ResourceType t, const StringPiece& e);
|
||||
ResourceName(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
|
||||
|
||||
int compare(const ResourceName& other) const;
|
||||
|
||||
@@ -96,15 +96,15 @@ struct ResourceName {
|
||||
* of the original string.
|
||||
*/
|
||||
struct ResourceNameRef {
|
||||
StringPiece package;
|
||||
android::StringPiece package;
|
||||
ResourceType type = ResourceType::kRaw;
|
||||
StringPiece entry;
|
||||
android::StringPiece entry;
|
||||
|
||||
ResourceNameRef() = default;
|
||||
ResourceNameRef(const ResourceNameRef&) = default;
|
||||
ResourceNameRef(ResourceNameRef&&) = default;
|
||||
ResourceNameRef(const ResourceName& rhs); // NOLINT(implicit)
|
||||
ResourceNameRef(const StringPiece& p, ResourceType t, const StringPiece& e);
|
||||
ResourceNameRef(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
|
||||
ResourceNameRef& operator=(const ResourceNameRef& rhs) = default;
|
||||
ResourceNameRef& operator=(ResourceNameRef&& rhs) = default;
|
||||
ResourceNameRef& operator=(const ResourceName& rhs);
|
||||
@@ -258,9 +258,9 @@ inline ::std::ostream& operator<<(::std::ostream& out,
|
||||
// ResourceName implementation.
|
||||
//
|
||||
|
||||
inline ResourceName::ResourceName(const StringPiece& p, ResourceType t,
|
||||
const StringPiece& e)
|
||||
: package(p.ToString()), type(t), entry(e.ToString()) {}
|
||||
inline ResourceName::ResourceName(const android::StringPiece& p, ResourceType t,
|
||||
const android::StringPiece& e)
|
||||
: package(p.to_string()), type(t), entry(e.to_string()) {}
|
||||
|
||||
inline int ResourceName::compare(const ResourceName& other) const {
|
||||
int cmp = package.compare(other.package);
|
||||
@@ -311,8 +311,8 @@ inline std::string ResourceName::ToString() const {
|
||||
inline ResourceNameRef::ResourceNameRef(const ResourceName& rhs)
|
||||
: package(rhs.package), type(rhs.type), entry(rhs.entry) {}
|
||||
|
||||
inline ResourceNameRef::ResourceNameRef(const StringPiece& p, ResourceType t,
|
||||
const StringPiece& e)
|
||||
inline ResourceNameRef::ResourceNameRef(const android::StringPiece& p, ResourceType t,
|
||||
const android::StringPiece& e)
|
||||
: package(p), type(t), entry(e) {}
|
||||
|
||||
inline ResourceNameRef& ResourceNameRef::operator=(const ResourceName& rhs) {
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "util/Util.h"
|
||||
#include "xml/XmlPullParser.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
constexpr const char* sXliffNamespaceUri =
|
||||
@@ -101,7 +103,7 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag,
|
||||
StringPiece trimmed_comment = util::TrimWhitespace(res->comment);
|
||||
if (trimmed_comment.size() != res->comment.size()) {
|
||||
// Only if there was a change do we re-assign.
|
||||
res->comment = trimmed_comment.ToString();
|
||||
res->comment = trimmed_comment.to_string();
|
||||
}
|
||||
|
||||
if (res->symbol_state) {
|
||||
@@ -297,7 +299,7 @@ bool ResourceParser::ParseResources(xml::XmlPullParser* parser) {
|
||||
// Extract the product name if it exists.
|
||||
if (Maybe<StringPiece> maybe_product =
|
||||
xml::FindNonEmptyAttribute(parser, "product")) {
|
||||
parsed_resource.product = maybe_product.value().ToString();
|
||||
parsed_resource.product = maybe_product.value().to_string();
|
||||
}
|
||||
|
||||
// Parse the resource regardless of product.
|
||||
@@ -383,7 +385,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
|
||||
// Items have their type encoded in the type attribute.
|
||||
if (Maybe<StringPiece> maybe_type =
|
||||
xml::FindNonEmptyAttribute(parser, "type")) {
|
||||
resource_type = maybe_type.value().ToString();
|
||||
resource_type = maybe_type.value().to_string();
|
||||
} else {
|
||||
diag_->Error(DiagMessage(source_.WithLine(parser->line_number()))
|
||||
<< "<item> must have a 'type' attribute");
|
||||
@@ -419,7 +421,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
|
||||
}
|
||||
|
||||
out_resource->name.type = ResourceType::kId;
|
||||
out_resource->name.entry = maybe_name.value().ToString();
|
||||
out_resource->name.entry = maybe_name.value().to_string();
|
||||
out_resource->value = util::make_unique<Id>();
|
||||
return true;
|
||||
}
|
||||
@@ -436,7 +438,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
|
||||
}
|
||||
|
||||
out_resource->name.type = item_iter->second.type;
|
||||
out_resource->name.entry = maybe_name.value().ToString();
|
||||
out_resource->name.entry = maybe_name.value().to_string();
|
||||
|
||||
// Only use the implicit format for this type if it wasn't overridden.
|
||||
if (!resource_format) {
|
||||
@@ -461,7 +463,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
|
||||
return false;
|
||||
}
|
||||
|
||||
out_resource->name.entry = maybe_name.value().ToString();
|
||||
out_resource->name.entry = maybe_name.value().to_string();
|
||||
}
|
||||
|
||||
// Call the associated parse method. The type will be filled in by the
|
||||
@@ -484,7 +486,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
|
||||
}
|
||||
|
||||
out_resource->name.type = *parsed_type;
|
||||
out_resource->name.entry = maybe_name.value().ToString();
|
||||
out_resource->name.entry = maybe_name.value().to_string();
|
||||
out_resource->value =
|
||||
ParseXml(parser, android::ResTable_map::TYPE_REFERENCE, kNoRawString);
|
||||
if (!out_resource->value) {
|
||||
@@ -718,7 +720,7 @@ bool ResourceParser::ParsePublicGroup(xml::XmlPullParser* parser,
|
||||
const size_t depth = parser->depth();
|
||||
while (xml::XmlPullParser::NextChildNode(parser, depth)) {
|
||||
if (parser->event() == xml::XmlPullParser::Event::kComment) {
|
||||
comment = util::TrimWhitespace(parser->comment()).ToString();
|
||||
comment = util::TrimWhitespace(parser->comment()).to_string();
|
||||
continue;
|
||||
} else if (parser->event() != xml::XmlPullParser::Event::kStartElement) {
|
||||
// Skip text.
|
||||
@@ -754,7 +756,7 @@ bool ResourceParser::ParsePublicGroup(xml::XmlPullParser* parser,
|
||||
|
||||
ParsedResource child_resource;
|
||||
child_resource.name.type = *parsed_type;
|
||||
child_resource.name.entry = maybe_name.value().ToString();
|
||||
child_resource.name.entry = maybe_name.value().to_string();
|
||||
child_resource.id = next_id;
|
||||
child_resource.comment = std::move(comment);
|
||||
child_resource.source = item_source;
|
||||
@@ -899,7 +901,7 @@ bool ResourceParser::ParseAttrImpl(xml::XmlPullParser* parser,
|
||||
const size_t depth = parser->depth();
|
||||
while (xml::XmlPullParser::NextChildNode(parser, depth)) {
|
||||
if (parser->event() == xml::XmlPullParser::Event::kComment) {
|
||||
comment = util::TrimWhitespace(parser->comment()).ToString();
|
||||
comment = util::TrimWhitespace(parser->comment()).to_string();
|
||||
continue;
|
||||
} else if (parser->event() != xml::XmlPullParser::Event::kStartElement) {
|
||||
// Skip text.
|
||||
@@ -1288,7 +1290,7 @@ bool ResourceParser::ParseDeclareStyleable(xml::XmlPullParser* parser,
|
||||
const size_t depth = parser->depth();
|
||||
while (xml::XmlPullParser::NextChildNode(parser, depth)) {
|
||||
if (parser->event() == xml::XmlPullParser::Event::kComment) {
|
||||
comment = util::TrimWhitespace(parser->comment()).ToString();
|
||||
comment = util::TrimWhitespace(parser->comment()).to_string();
|
||||
continue;
|
||||
} else if (parser->event() != xml::XmlPullParser::Event::kStartElement) {
|
||||
// Ignore text.
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "ConfigDescription.h"
|
||||
#include "Diagnostics.h"
|
||||
@@ -27,7 +28,6 @@
|
||||
#include "ResourceValues.h"
|
||||
#include "StringPool.h"
|
||||
#include "util/Maybe.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "xml/XmlPullParser.h"
|
||||
|
||||
namespace aapt {
|
||||
@@ -101,7 +101,7 @@ class ResourceParser {
|
||||
bool ParseAttrImpl(xml::XmlPullParser* parser, ParsedResource* out_resource,
|
||||
bool weak);
|
||||
Maybe<Attribute::Symbol> ParseEnumOrFlagItem(xml::XmlPullParser* parser,
|
||||
const StringPiece& tag);
|
||||
const android::StringPiece& tag);
|
||||
bool ParseStyle(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
||||
bool ParseStyleItem(xml::XmlPullParser* parser, Style* style);
|
||||
bool ParseDeclareStyleable(xml::XmlPullParser* parser,
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "test/Test.h"
|
||||
#include "xml/XmlPullParser.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
constexpr const char* kXmlPreamble =
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
static bool less_than_type(const std::unique_ptr<ResourceTableType>& lhs,
|
||||
@@ -87,7 +89,7 @@ ResourceTablePackage* ResourceTable::FindOrCreatePackage(
|
||||
|
||||
std::unique_ptr<ResourceTablePackage> new_package =
|
||||
util::make_unique<ResourceTablePackage>();
|
||||
new_package->name = name.ToString();
|
||||
new_package->name = name.to_string();
|
||||
return packages.emplace(iter, std::move(new_package))->get();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
#include "StringPool.h"
|
||||
#include "io/File.h"
|
||||
|
||||
#include <android-base/macros.h>
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -68,9 +70,8 @@ class ResourceConfigValue {
|
||||
*/
|
||||
std::unique_ptr<Value> value;
|
||||
|
||||
ResourceConfigValue(const ConfigDescription& config,
|
||||
const StringPiece& product)
|
||||
: config(config), product(product.ToString()) {}
|
||||
ResourceConfigValue(const ConfigDescription& config, const android::StringPiece& product)
|
||||
: config(config), product(product.to_string()) {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ResourceConfigValue);
|
||||
@@ -105,13 +106,13 @@ class ResourceEntry {
|
||||
*/
|
||||
std::vector<std::unique_ptr<ResourceConfigValue>> values;
|
||||
|
||||
explicit ResourceEntry(const StringPiece& name) : name(name.ToString()) {}
|
||||
explicit ResourceEntry(const android::StringPiece& name) : name(name.to_string()) {}
|
||||
|
||||
ResourceConfigValue* FindValue(const ConfigDescription& config);
|
||||
ResourceConfigValue* FindValue(const ConfigDescription& config,
|
||||
const StringPiece& product);
|
||||
const android::StringPiece& product);
|
||||
ResourceConfigValue* FindOrCreateValue(const ConfigDescription& config,
|
||||
const StringPiece& product);
|
||||
const android::StringPiece& product);
|
||||
std::vector<ResourceConfigValue*> findAllValues(
|
||||
const ConfigDescription& config);
|
||||
std::vector<ResourceConfigValue*> FindValuesIf(
|
||||
@@ -150,8 +151,8 @@ class ResourceTableType {
|
||||
|
||||
explicit ResourceTableType(const ResourceType type) : type(type) {}
|
||||
|
||||
ResourceEntry* FindEntry(const StringPiece& name);
|
||||
ResourceEntry* FindOrCreateEntry(const StringPiece& name);
|
||||
ResourceEntry* FindEntry(const android::StringPiece& name);
|
||||
ResourceEntry* FindOrCreateEntry(const android::StringPiece& name);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ResourceTableType);
|
||||
@@ -195,22 +196,19 @@ class ResourceTable {
|
||||
Value* incoming);
|
||||
|
||||
bool AddResource(const ResourceNameRef& name, const ConfigDescription& config,
|
||||
const StringPiece& product, std::unique_ptr<Value> value,
|
||||
const android::StringPiece& product, std::unique_ptr<Value> value,
|
||||
IDiagnostics* diag);
|
||||
|
||||
bool AddResource(const ResourceNameRef& name, const ResourceId& res_id,
|
||||
const ConfigDescription& config, const StringPiece& product,
|
||||
const ConfigDescription& config, const android::StringPiece& product,
|
||||
std::unique_ptr<Value> value, IDiagnostics* diag);
|
||||
|
||||
bool AddFileReference(const ResourceNameRef& name,
|
||||
const ConfigDescription& config, const Source& source,
|
||||
const StringPiece& path, IDiagnostics* diag);
|
||||
bool AddFileReference(const ResourceNameRef& name, const ConfigDescription& config,
|
||||
const Source& source, const android::StringPiece& path, IDiagnostics* diag);
|
||||
|
||||
bool AddFileReferenceAllowMangled(const ResourceNameRef& name,
|
||||
const ConfigDescription& config,
|
||||
const Source& source,
|
||||
const StringPiece& path, io::IFile* file,
|
||||
IDiagnostics* diag);
|
||||
bool AddFileReferenceAllowMangled(const ResourceNameRef& name, const ConfigDescription& config,
|
||||
const Source& source, const android::StringPiece& path,
|
||||
io::IFile* file, IDiagnostics* diag);
|
||||
|
||||
/**
|
||||
* Same as AddResource, but doesn't verify the validity of the name. This is
|
||||
@@ -219,18 +217,13 @@ class ResourceTable {
|
||||
* mangled
|
||||
* names.
|
||||
*/
|
||||
bool AddResourceAllowMangled(const ResourceNameRef& name,
|
||||
const ConfigDescription& config,
|
||||
const StringPiece& product,
|
||||
std::unique_ptr<Value> value,
|
||||
bool AddResourceAllowMangled(const ResourceNameRef& name, const ConfigDescription& config,
|
||||
const android::StringPiece& product, std::unique_ptr<Value> value,
|
||||
IDiagnostics* diag);
|
||||
|
||||
bool AddResourceAllowMangled(const ResourceNameRef& name,
|
||||
const ResourceId& id,
|
||||
const ConfigDescription& config,
|
||||
const StringPiece& product,
|
||||
std::unique_ptr<Value> value,
|
||||
IDiagnostics* diag);
|
||||
bool AddResourceAllowMangled(const ResourceNameRef& name, const ResourceId& id,
|
||||
const ConfigDescription& config, const android::StringPiece& product,
|
||||
std::unique_ptr<Value> value, IDiagnostics* diag);
|
||||
|
||||
bool SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id,
|
||||
const Symbol& symbol, IDiagnostics* diag);
|
||||
@@ -273,28 +266,23 @@ class ResourceTable {
|
||||
* represent the
|
||||
* 'current' package before it is known to the ResourceTable.
|
||||
*/
|
||||
ResourceTablePackage* FindPackage(const StringPiece& name);
|
||||
ResourceTablePackage* FindPackage(const android::StringPiece& name);
|
||||
|
||||
ResourceTablePackage* FindPackageById(uint8_t id);
|
||||
|
||||
ResourceTablePackage* CreatePackage(const StringPiece& name,
|
||||
Maybe<uint8_t> id = {});
|
||||
ResourceTablePackage* CreatePackage(const android::StringPiece& name, Maybe<uint8_t> id = {});
|
||||
|
||||
private:
|
||||
ResourceTablePackage* FindOrCreatePackage(const StringPiece& name);
|
||||
ResourceTablePackage* FindOrCreatePackage(const android::StringPiece& name);
|
||||
|
||||
bool AddResourceImpl(const ResourceNameRef& name, const ResourceId& res_id,
|
||||
const ConfigDescription& config,
|
||||
const StringPiece& product, std::unique_ptr<Value> value,
|
||||
const char* valid_chars,
|
||||
const CollisionResolverFunc& conflict_resolver,
|
||||
IDiagnostics* diag);
|
||||
const ConfigDescription& config, const android::StringPiece& product,
|
||||
std::unique_ptr<Value> value, const char* valid_chars,
|
||||
const CollisionResolverFunc& conflict_resolver, IDiagnostics* diag);
|
||||
|
||||
bool AddFileReferenceImpl(const ResourceNameRef& name,
|
||||
const ConfigDescription& config,
|
||||
const Source& source, const StringPiece& path,
|
||||
io::IFile* file, const char* valid_chars,
|
||||
IDiagnostics* diag);
|
||||
bool AddFileReferenceImpl(const ResourceNameRef& name, const ConfigDescription& config,
|
||||
const Source& source, const android::StringPiece& path, io::IFile* file,
|
||||
const char* valid_chars, IDiagnostics* diag);
|
||||
|
||||
bool SetSymbolStateImpl(const ResourceNameRef& name, const ResourceId& res_id,
|
||||
const Symbol& symbol, const char* valid_chars,
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#include "util/Files.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
using android::StringPiece16;
|
||||
|
||||
namespace aapt {
|
||||
namespace ResourceUtils {
|
||||
|
||||
@@ -59,7 +62,7 @@ Maybe<ResourceName> ToResourceName(
|
||||
name_out.entry =
|
||||
util::Utf16ToUtf8(StringPiece16(name_in.name, name_in.nameLen));
|
||||
} else if (name_in.name8) {
|
||||
name_out.entry = StringPiece(name_in.name8, name_in.nameLen).ToString();
|
||||
name_out.entry.assign(name_in.name8, name_in.nameLen);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
@@ -303,9 +306,7 @@ Maybe<Reference> ParseXmlAttributeName(const StringPiece& str) {
|
||||
p++;
|
||||
}
|
||||
|
||||
ref.name =
|
||||
ResourceName(package.ToString(), ResourceType::kAttr,
|
||||
name.empty() ? trimmed_str.ToString() : name.ToString());
|
||||
ref.name = ResourceName(package, ResourceType::kAttr, name.empty() ? trimmed_str : name);
|
||||
return Maybe<Reference>(std::move(ref));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "NameMangler.h"
|
||||
#include "Resource.h"
|
||||
#include "ResourceValues.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
namespace ResourceUtils {
|
||||
@@ -37,8 +38,8 @@ namespace ResourceUtils {
|
||||
* individual extracted piece to verify that the pieces are valid.
|
||||
* Returns false if there was no package but a ':' was present.
|
||||
*/
|
||||
bool ExtractResourceName(const StringPiece& str, StringPiece* out_package,
|
||||
StringPiece* out_type, StringPiece* out_entry);
|
||||
bool ExtractResourceName(const android::StringPiece& str, android::StringPiece* out_package,
|
||||
android::StringPiece* out_type, android::StringPiece* out_entry);
|
||||
|
||||
/**
|
||||
* Returns true if the string was parsed as a resource name
|
||||
@@ -46,7 +47,7 @@ bool ExtractResourceName(const StringPiece& str, StringPiece* out_package,
|
||||
* `out_resource` set to the parsed resource name and `out_private` set to true
|
||||
* if a '*' prefix was present.
|
||||
*/
|
||||
bool ParseResourceName(const StringPiece& str, ResourceNameRef* out_resource,
|
||||
bool ParseResourceName(const android::StringPiece& str, ResourceNameRef* out_resource,
|
||||
bool* out_private = nullptr);
|
||||
|
||||
/*
|
||||
@@ -57,28 +58,27 @@ bool ParseResourceName(const StringPiece& str, ResourceNameRef* out_resource,
|
||||
* If '+' was present in the reference, `out_create` is set to true.
|
||||
* If '*' was present in the reference, `out_private` is set to true.
|
||||
*/
|
||||
bool ParseReference(const StringPiece& str, ResourceNameRef* out_reference,
|
||||
bool ParseReference(const android::StringPiece& str, ResourceNameRef* out_reference,
|
||||
bool* out_create = nullptr, bool* out_private = nullptr);
|
||||
|
||||
/*
|
||||
* Returns true if the string is in the form of a resource reference
|
||||
* (@[+][package:]type/name).
|
||||
*/
|
||||
bool IsReference(const StringPiece& str);
|
||||
bool IsReference(const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns true if the string was parsed as an attribute reference
|
||||
* (?[package:][type/]name),
|
||||
* with `out_reference` set to the parsed reference.
|
||||
*/
|
||||
bool ParseAttributeReference(const StringPiece& str,
|
||||
ResourceNameRef* out_reference);
|
||||
bool ParseAttributeReference(const android::StringPiece& str, ResourceNameRef* out_reference);
|
||||
|
||||
/**
|
||||
* Returns true if the string is in the form of an attribute
|
||||
* reference(?[package:][type/]name).
|
||||
*/
|
||||
bool IsAttributeReference(const StringPiece& str);
|
||||
bool IsAttributeReference(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* Convert an android::ResTable::resource_name to an aapt::ResourceName struct.
|
||||
@@ -90,22 +90,22 @@ Maybe<ResourceName> ToResourceName(
|
||||
* Returns a boolean value if the string is equal to TRUE, true, True, FALSE,
|
||||
* false, or False.
|
||||
*/
|
||||
Maybe<bool> ParseBool(const StringPiece& str);
|
||||
Maybe<bool> ParseBool(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* Returns a uint32_t if the string is an integer.
|
||||
*/
|
||||
Maybe<uint32_t> ParseInt(const StringPiece& str);
|
||||
Maybe<uint32_t> ParseInt(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* Returns an ID if it the string represented a valid ID.
|
||||
*/
|
||||
Maybe<ResourceId> ParseResourceId(const StringPiece& str);
|
||||
Maybe<ResourceId> ParseResourceId(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* Parses an SDK version, which can be an integer, or a letter from A-Z.
|
||||
*/
|
||||
Maybe<int> ParseSdkVersion(const StringPiece& str);
|
||||
Maybe<int> ParseSdkVersion(const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns a Reference, or None Maybe instance if the string `str` was parsed as
|
||||
@@ -118,8 +118,7 @@ Maybe<int> ParseSdkVersion(const StringPiece& str);
|
||||
* ?[package:]style/<entry> or
|
||||
* <package>:[style/]<entry>
|
||||
*/
|
||||
Maybe<Reference> ParseStyleParentReference(const StringPiece& str,
|
||||
std::string* out_error);
|
||||
Maybe<Reference> ParseStyleParentReference(const android::StringPiece& str, std::string* out_error);
|
||||
|
||||
/*
|
||||
* Returns a Reference if the string `str` was parsed as a valid XML attribute
|
||||
@@ -128,7 +127,7 @@ Maybe<Reference> ParseStyleParentReference(const StringPiece& str,
|
||||
*
|
||||
* package:entry
|
||||
*/
|
||||
Maybe<Reference> ParseXmlAttributeName(const StringPiece& str);
|
||||
Maybe<Reference> ParseXmlAttributeName(const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns a Reference object if the string was parsed as a resource or
|
||||
@@ -137,52 +136,52 @@ Maybe<Reference> ParseXmlAttributeName(const StringPiece& str);
|
||||
* if
|
||||
* the '+' was present in the string.
|
||||
*/
|
||||
std::unique_ptr<Reference> TryParseReference(const StringPiece& str,
|
||||
std::unique_ptr<Reference> TryParseReference(const android::StringPiece& str,
|
||||
bool* out_create = nullptr);
|
||||
|
||||
/*
|
||||
* Returns a BinaryPrimitve object representing @null or @empty if the string
|
||||
* was parsed as one.
|
||||
*/
|
||||
std::unique_ptr<BinaryPrimitive> TryParseNullOrEmpty(const StringPiece& str);
|
||||
std::unique_ptr<BinaryPrimitive> TryParseNullOrEmpty(const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns a BinaryPrimitve object representing a color if the string was parsed
|
||||
* as one.
|
||||
*/
|
||||
std::unique_ptr<BinaryPrimitive> TryParseColor(const StringPiece& str);
|
||||
std::unique_ptr<BinaryPrimitive> TryParseColor(const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns a BinaryPrimitve object representing a boolean if the string was
|
||||
* parsed as one.
|
||||
*/
|
||||
std::unique_ptr<BinaryPrimitive> TryParseBool(const StringPiece& str);
|
||||
std::unique_ptr<BinaryPrimitive> TryParseBool(const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns a BinaryPrimitve object representing an integer if the string was
|
||||
* parsed as one.
|
||||
*/
|
||||
std::unique_ptr<BinaryPrimitive> TryParseInt(const StringPiece& str);
|
||||
std::unique_ptr<BinaryPrimitive> TryParseInt(const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns a BinaryPrimitve object representing a floating point number
|
||||
* (float, dimension, etc) if the string was parsed as one.
|
||||
*/
|
||||
std::unique_ptr<BinaryPrimitive> TryParseFloat(const StringPiece& str);
|
||||
std::unique_ptr<BinaryPrimitive> TryParseFloat(const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns a BinaryPrimitve object representing an enum symbol if the string was
|
||||
* parsed as one.
|
||||
*/
|
||||
std::unique_ptr<BinaryPrimitive> TryParseEnumSymbol(const Attribute* enum_attr,
|
||||
const StringPiece& str);
|
||||
const android::StringPiece& str);
|
||||
|
||||
/*
|
||||
* Returns a BinaryPrimitve object representing a flag symbol if the string was
|
||||
* parsed as one.
|
||||
*/
|
||||
std::unique_ptr<BinaryPrimitive> TryParseFlagSymbol(const Attribute* enum_attr,
|
||||
const StringPiece& str);
|
||||
const android::StringPiece& str);
|
||||
/*
|
||||
* Try to convert a string to an Item for the given attribute. The attribute
|
||||
* will
|
||||
@@ -191,11 +190,11 @@ std::unique_ptr<BinaryPrimitive> TryParseFlagSymbol(const Attribute* enum_attr,
|
||||
* reference to an ID that must be created (@+id/foo).
|
||||
*/
|
||||
std::unique_ptr<Item> TryParseItemForAttribute(
|
||||
const StringPiece& value, const Attribute* attr,
|
||||
const android::StringPiece& value, const Attribute* attr,
|
||||
const std::function<void(const ResourceName&)>& on_create_reference = {});
|
||||
|
||||
std::unique_ptr<Item> TryParseItemForAttribute(
|
||||
const StringPiece& value, uint32_t type_mask,
|
||||
const android::StringPiece& value, uint32_t type_mask,
|
||||
const std::function<void(const ResourceName&)>& on_create_reference = {});
|
||||
|
||||
uint32_t AndroidTypeToAttributeTypeMask(uint16_t type);
|
||||
|
||||
@@ -48,8 +48,7 @@ TEST(ResourceUtilsTest, ParseResourceName) {
|
||||
EXPECT_EQ(ResourceNameRef("android", ResourceType::kColor, "foo"), actual);
|
||||
EXPECT_TRUE(actual_priv);
|
||||
|
||||
EXPECT_FALSE(
|
||||
ResourceUtils::ParseResourceName(StringPiece(), &actual, &actual_priv));
|
||||
EXPECT_FALSE(ResourceUtils::ParseResourceName(android::StringPiece(), &actual, &actual_priv));
|
||||
}
|
||||
|
||||
TEST(ResourceUtilsTest, ParseReferenceWithNoPackage) {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/ResourceTypes.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "Diagnostics.h"
|
||||
#include "Resource.h"
|
||||
@@ -73,7 +74,7 @@ struct Value {
|
||||
*/
|
||||
const std::string& GetComment() const { return comment_; }
|
||||
|
||||
void SetComment(const StringPiece& str) { comment_ = str.ToString(); }
|
||||
void SetComment(const android::StringPiece& str) { comment_ = str.to_string(); }
|
||||
|
||||
void SetComment(std::string&& str) { comment_ = std::move(str); }
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
static const char* sDevelopmentSdkCodeName = "O";
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "Resource.h"
|
||||
|
||||
namespace aapt {
|
||||
@@ -52,7 +54,7 @@ enum {
|
||||
|
||||
size_t FindAttributeSdkLevel(const ResourceId& id);
|
||||
size_t FindAttributeSdkLevel(const ResourceName& name);
|
||||
std::pair<StringPiece, int> GetDevelopmentSdkCodeNameAndVersion();
|
||||
std::pair<android::StringPiece, int> GetDevelopmentSdkCodeNameAndVersion();
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "util/Maybe.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -35,12 +36,11 @@ struct Source {
|
||||
|
||||
Source() = default;
|
||||
|
||||
inline Source(const StringPiece& path)
|
||||
: path(path.ToString()) { // NOLINT(implicit)
|
||||
inline Source(const android::StringPiece& path) : path(path.to_string()) { // NOLINT(implicit)
|
||||
}
|
||||
|
||||
inline Source(const StringPiece& path, size_t line)
|
||||
: path(path.ToString()), line(line) {}
|
||||
inline Source(const android::StringPiece& path, size_t line)
|
||||
: path(path.to_string()), line(line) {}
|
||||
|
||||
inline Source WithLine(size_t line) const { return Source(path, line); }
|
||||
};
|
||||
|
||||
@@ -22,11 +22,13 @@
|
||||
|
||||
#include "android-base/logging.h"
|
||||
#include "androidfw/ResourceTypes.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
StringPool::Ref::Ref() : entry_(nullptr) {}
|
||||
@@ -140,7 +142,7 @@ StringPool::Ref StringPool::MakeRefImpl(const StringPiece& str,
|
||||
}
|
||||
|
||||
Entry* entry = new Entry();
|
||||
entry->value = str.ToString();
|
||||
entry->value = str.to_string();
|
||||
entry->context = context;
|
||||
entry->index = strings_.size();
|
||||
entry->ref_ = 0;
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "ConfigDescription.h"
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -149,14 +150,14 @@ class StringPool {
|
||||
* Adds a string to the pool, unless it already exists. Returns
|
||||
* a reference to the string in the pool.
|
||||
*/
|
||||
Ref MakeRef(const StringPiece& str);
|
||||
Ref MakeRef(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* Adds a string to the pool, unless it already exists, with a context
|
||||
* object that can be used when sorting the string pool. Returns
|
||||
* a reference to the string in the pool.
|
||||
*/
|
||||
Ref MakeRef(const StringPiece& str, const Context& context);
|
||||
Ref MakeRef(const android::StringPiece& str, const Context& context);
|
||||
|
||||
/**
|
||||
* Adds a style to the string pool and returns a reference to it.
|
||||
@@ -208,11 +209,11 @@ class StringPool {
|
||||
|
||||
static bool Flatten(BigBuffer* out, const StringPool& pool, bool utf8);
|
||||
|
||||
Ref MakeRefImpl(const StringPiece& str, const Context& context, bool unique);
|
||||
Ref MakeRefImpl(const android::StringPiece& str, const Context& context, bool unique);
|
||||
|
||||
std::vector<std::unique_ptr<Entry>> strings_;
|
||||
std::vector<std::unique_ptr<StyleEntry>> styles_;
|
||||
std::unordered_multimap<StringPiece, Entry*> indexed_strings_;
|
||||
std::unordered_multimap<android::StringPiece, Entry*> indexed_strings_;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
@@ -18,9 +18,14 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "test/Test.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
using android::StringPiece16;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
TEST(StringPoolTest, InsertOneString) {
|
||||
@@ -236,8 +241,7 @@ TEST(StringPoolTest, Flatten) {
|
||||
EXPECT_EQ(StringPiece16(u"goodbye"), util::GetString16(test, 1));
|
||||
|
||||
EXPECT_EQ(StringPiece(sLongString), util::GetString(test, 2));
|
||||
EXPECT_EQ(util::Utf8ToUtf16(sLongString),
|
||||
util::GetString16(test, 2).ToString());
|
||||
EXPECT_EQ(util::Utf8ToUtf16(sLongString), util::GetString16(test, 2).to_string());
|
||||
|
||||
size_t len;
|
||||
EXPECT_TRUE(test.stringAt(3, &len) != nullptr ||
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "android-base/errors.h"
|
||||
#include "android-base/file.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
|
||||
|
||||
#include "ConfigDescription.h"
|
||||
#include "Diagnostics.h"
|
||||
#include "Flags.h"
|
||||
@@ -38,11 +44,7 @@
|
||||
#include "xml/XmlDom.h"
|
||||
#include "xml/XmlPullParser.h"
|
||||
|
||||
#include "android-base/errors.h"
|
||||
#include "android-base/file.h"
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
|
||||
|
||||
using android::StringPiece;
|
||||
using google::protobuf::io::CopyingOutputStreamAdaptor;
|
||||
using google::protobuf::io::ZeroCopyOutputStream;
|
||||
|
||||
@@ -103,9 +105,8 @@ static Maybe<ResourcePathData> ExtractResourcePathData(const std::string& path,
|
||||
name = name.substr(0, dot_pos);
|
||||
}
|
||||
|
||||
return ResourcePathData{Source(path), dir_str.ToString(),
|
||||
name.ToString(), extension.ToString(),
|
||||
config_str.ToString(), config};
|
||||
return ResourcePathData{Source(path), dir_str.to_string(), name.to_string(),
|
||||
extension.to_string(), config_str.to_string(), config};
|
||||
}
|
||||
|
||||
struct CompileOptions {
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "android-base/macros.h"
|
||||
|
||||
#include "Resource.h"
|
||||
#include "process/IResourceTableConsumer.h"
|
||||
|
||||
#include "android-base/macros.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
/**
|
||||
@@ -40,8 +40,7 @@ class IdAssigner : public IResourceTableConsumer {
|
||||
bool Consume(IAaptContext* context, ResourceTable* table) override;
|
||||
|
||||
private:
|
||||
const std::unordered_map<ResourceName, ResourceId>* assigned_id_map_ =
|
||||
nullptr;
|
||||
const std::unordered_map<ResourceName, ResourceId>* assigned_id_map_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
@@ -21,10 +21,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/ResourceTypes.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "util/StringPiece.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
// Colors in the format 0xAARRGGBB (the way 9-patch expects it).
|
||||
|
||||
@@ -15,18 +15,21 @@
|
||||
*/
|
||||
|
||||
#include "Png.h"
|
||||
#include "Source.h"
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
#include <androidfw/ResourceTypes.h>
|
||||
#include <png.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/ResourceTypes.h"
|
||||
|
||||
#include "Source.h"
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
constexpr bool kDebug = false;
|
||||
|
||||
@@ -56,7 +56,7 @@ class Png {
|
||||
*/
|
||||
class PngChunkFilter : public io::InputStream {
|
||||
public:
|
||||
explicit PngChunkFilter(const StringPiece& data);
|
||||
explicit PngChunkFilter(const android::StringPiece& data);
|
||||
|
||||
bool Next(const void** buffer, int* len) override;
|
||||
void BackUp(int count) override;
|
||||
@@ -71,7 +71,7 @@ class PngChunkFilter : public io::InputStream {
|
||||
private:
|
||||
bool ConsumeWindow(const void** buffer, int* len);
|
||||
|
||||
StringPiece data_;
|
||||
android::StringPiece data_;
|
||||
size_t window_start_ = 0;
|
||||
size_t window_end_ = 0;
|
||||
bool error_ = false;
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
#include "compile/Png.h"
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "io/Io.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "ValueVisitor.h"
|
||||
#include "compile/Pseudolocalizer.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
std::unique_ptr<StyledString> PseudolocalizeStyledString(
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
// String basis to generate expansion
|
||||
@@ -40,10 +42,8 @@ static const char kArgEnd = '}';
|
||||
|
||||
class PseudoMethodNone : public PseudoMethodImpl {
|
||||
public:
|
||||
std::string Text(const StringPiece& text) override { return text.ToString(); }
|
||||
std::string Placeholder(const StringPiece& text) override {
|
||||
return text.ToString();
|
||||
}
|
||||
std::string Text(const StringPiece& text) override { return text.to_string(); }
|
||||
std::string Placeholder(const StringPiece& text) override { return text.to_string(); }
|
||||
};
|
||||
|
||||
class PseudoMethodBidi : public PseudoMethodImpl {
|
||||
@@ -116,7 +116,7 @@ std::string Pseudolocalizer::Text(const StringPiece& text) {
|
||||
}
|
||||
size_t size = nextpos - lastpos;
|
||||
if (size) {
|
||||
std::string chunk = text.substr(lastpos, size).ToString();
|
||||
std::string chunk = text.substr(lastpos, size).to_string();
|
||||
if (pseudo) {
|
||||
chunk = impl_->Text(chunk);
|
||||
} else if (str[lastpos] == kArgStart && str[nextpos - 1] == kArgEnd) {
|
||||
@@ -437,7 +437,7 @@ std::string PseudoMethodAccent::Text(const StringPiece& source) {
|
||||
|
||||
std::string PseudoMethodAccent::Placeholder(const StringPiece& source) {
|
||||
// Surround a placeholder with brackets
|
||||
return kPlaceholderOpen + source.ToString() + kPlaceholderClose;
|
||||
return kPlaceholderOpen + source.to_string() + kPlaceholderClose;
|
||||
}
|
||||
|
||||
std::string PseudoMethodBidi::Text(const StringPiece& source) {
|
||||
@@ -467,7 +467,7 @@ std::string PseudoMethodBidi::Text(const StringPiece& source) {
|
||||
|
||||
std::string PseudoMethodBidi::Placeholder(const StringPiece& source) {
|
||||
// Surround a placeholder with directionality change sequence
|
||||
return kRlm + kRlo + source.ToString() + kPdf + kRlm;
|
||||
return kRlm + kRlo + source.to_string() + kPdf + kRlm;
|
||||
}
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
#include <memory>
|
||||
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "ResourceValues.h"
|
||||
#include "StringPool.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -32,8 +32,8 @@ class PseudoMethodImpl {
|
||||
virtual ~PseudoMethodImpl() {}
|
||||
virtual std::string Start() { return {}; }
|
||||
virtual std::string End() { return {}; }
|
||||
virtual std::string Text(const StringPiece& text) = 0;
|
||||
virtual std::string Placeholder(const StringPiece& text) = 0;
|
||||
virtual std::string Text(const android::StringPiece& text) = 0;
|
||||
virtual std::string Placeholder(const android::StringPiece& text) = 0;
|
||||
};
|
||||
|
||||
class Pseudolocalizer {
|
||||
@@ -48,7 +48,7 @@ class Pseudolocalizer {
|
||||
void SetMethod(Method method);
|
||||
std::string Start() { return impl_->Start(); }
|
||||
std::string End() { return impl_->End(); }
|
||||
std::string Text(const StringPiece& text);
|
||||
std::string Text(const android::StringPiece& text);
|
||||
|
||||
private:
|
||||
std::unique_ptr<PseudoMethodImpl> impl_;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "test/Test.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
// In this context, 'Axis' represents a particular field in the configuration,
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "process/SymbolTable.h"
|
||||
#include "unflatten/BinaryResourceParser.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
class DiffContext : public IAaptContext {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "Debug.h"
|
||||
#include "Diagnostics.h"
|
||||
#include "Flags.h"
|
||||
@@ -24,7 +26,8 @@
|
||||
#include "proto/ProtoSerialize.h"
|
||||
#include "unflatten/BinaryResourceParser.h"
|
||||
#include "util/Files.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
|
||||
@@ -22,10 +22,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "ziparchive/zip_writer.h"
|
||||
|
||||
#include "util/Files.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -36,7 +38,7 @@ class DirectoryWriter : public IArchiveWriter {
|
||||
DirectoryWriter() = default;
|
||||
|
||||
bool Open(IDiagnostics* diag, const StringPiece& out_dir) {
|
||||
dir_ = out_dir.ToString();
|
||||
dir_ = out_dir.to_string();
|
||||
file::FileType type = file::GetFileType(dir_);
|
||||
if (type == file::FileType::kNonexistant) {
|
||||
diag->Error(DiagMessage() << "directory " << dir_ << " does not exist");
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
|
||||
|
||||
#include "Diagnostics.h"
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/Files.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -46,7 +46,7 @@ class IArchiveWriter : public google::protobuf::io::CopyingOutputStream {
|
||||
public:
|
||||
virtual ~IArchiveWriter() = default;
|
||||
|
||||
virtual bool StartEntry(const StringPiece& path, uint32_t flags) = 0;
|
||||
virtual bool StartEntry(const android::StringPiece& path, uint32_t flags) = 0;
|
||||
virtual bool WriteEntry(const BigBuffer& buffer) = 0;
|
||||
virtual bool WriteEntry(const void* data, size_t len) = 0;
|
||||
virtual bool FinishEntry() = 0;
|
||||
@@ -57,11 +57,11 @@ class IArchiveWriter : public google::protobuf::io::CopyingOutputStream {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<IArchiveWriter> CreateDirectoryArchiveWriter(
|
||||
IDiagnostics* diag, const StringPiece& path);
|
||||
std::unique_ptr<IArchiveWriter> CreateDirectoryArchiveWriter(IDiagnostics* diag,
|
||||
const android::StringPiece& path);
|
||||
|
||||
std::unique_ptr<IArchiveWriter> CreateZipFileArchiveWriter(
|
||||
IDiagnostics* diag, const StringPiece& path);
|
||||
std::unique_ptr<IArchiveWriter> CreateZipFileArchiveWriter(IDiagnostics* diag,
|
||||
const android::StringPiece& path);
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece16;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
class XmlFlattenerTest : public ::testing::Test {
|
||||
|
||||
@@ -110,7 +110,7 @@ class IFileCollection {
|
||||
public:
|
||||
virtual ~IFileCollection() = default;
|
||||
|
||||
virtual IFile* FindFile(const StringPiece& path) = 0;
|
||||
virtual IFile* FindFile(const android::StringPiece& path) = 0;
|
||||
virtual std::unique_ptr<IFileCollectionIterator> Iterator() = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,14 +16,16 @@
|
||||
|
||||
#include "io/FileSystem.h"
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "utils/FileMap.h"
|
||||
|
||||
#include "Source.h"
|
||||
#include "util/Files.h"
|
||||
#include "util/Maybe.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
namespace io {
|
||||
|
||||
@@ -54,13 +56,11 @@ IFile* FileCollectionIterator::Next() {
|
||||
}
|
||||
|
||||
IFile* FileCollection::InsertFile(const StringPiece& path) {
|
||||
return (files_[path.ToString()] =
|
||||
util::make_unique<RegularFile>(Source(path)))
|
||||
.get();
|
||||
return (files_[path.to_string()] = util::make_unique<RegularFile>(Source(path))).get();
|
||||
}
|
||||
|
||||
IFile* FileCollection::FindFile(const StringPiece& path) {
|
||||
auto iter = files_.find(path.ToString());
|
||||
auto iter = files_.find(path.to_string());
|
||||
if (iter != files_.end()) {
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ class FileCollection : public IFileCollection {
|
||||
/**
|
||||
* Adds a file located at path. Returns the IFile representation of that file.
|
||||
*/
|
||||
IFile* InsertFile(const StringPiece& path);
|
||||
IFile* FindFile(const StringPiece& path) override;
|
||||
IFile* InsertFile(const android::StringPiece& path);
|
||||
IFile* FindFile(const android::StringPiece& path) override;
|
||||
std::unique_ptr<IFileCollectionIterator> Iterator() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "Source.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
namespace io {
|
||||
|
||||
@@ -107,7 +109,7 @@ std::unique_ptr<ZipFileCollection> ZipFileCollection::Create(
|
||||
std::string zip_entry_path =
|
||||
std::string(reinterpret_cast<const char*>(zip_entry_name.name),
|
||||
zip_entry_name.name_length);
|
||||
std::string nested_path = path.ToString() + "@" + zip_entry_path;
|
||||
std::string nested_path = path.to_string() + "@" + zip_entry_path;
|
||||
collection->files_[zip_entry_path] = util::make_unique<ZipFile>(
|
||||
collection->handle_, zip_data, Source(nested_path));
|
||||
}
|
||||
@@ -120,7 +122,7 @@ std::unique_ptr<ZipFileCollection> ZipFileCollection::Create(
|
||||
}
|
||||
|
||||
IFile* ZipFileCollection::FindFile(const StringPiece& path) {
|
||||
auto iter = files_.find(path.ToString());
|
||||
auto iter = files_.find(path.to_string());
|
||||
if (iter != files_.end()) {
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "io/File.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
namespace io {
|
||||
@@ -64,10 +65,10 @@ class ZipFileCollectionIterator : public IFileCollectionIterator {
|
||||
*/
|
||||
class ZipFileCollection : public IFileCollection {
|
||||
public:
|
||||
static std::unique_ptr<ZipFileCollection> Create(const StringPiece& path,
|
||||
static std::unique_ptr<ZipFileCollection> Create(const android::StringPiece& path,
|
||||
std::string* outError);
|
||||
|
||||
io::IFile* FindFile(const StringPiece& path) override;
|
||||
io::IFile* FindFile(const android::StringPiece& path) override;
|
||||
std::unique_ptr<IFileCollectionIterator> Iterator() override;
|
||||
|
||||
~ZipFileCollection() override;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
void AnnotationProcessor::AppendCommentLine(std::string& comment) {
|
||||
@@ -54,7 +56,7 @@ void AnnotationProcessor::AppendComment(const StringPiece& comment) {
|
||||
for (StringPiece line : util::Tokenize(comment, '\n')) {
|
||||
line = util::TrimWhitespace(line);
|
||||
if (!line.empty()) {
|
||||
std::string lineCopy = line.ToString();
|
||||
std::string lineCopy = line.to_string();
|
||||
AppendCommentLine(lineCopy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "util/StringPiece.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -58,7 +58,7 @@ class AnnotationProcessor {
|
||||
* configurations,
|
||||
* we need to collect all the comments.
|
||||
*/
|
||||
void AppendComment(const StringPiece& comment);
|
||||
void AppendComment(const android::StringPiece& comment);
|
||||
|
||||
void AppendNewLine();
|
||||
|
||||
@@ -66,7 +66,7 @@ class AnnotationProcessor {
|
||||
* Writes the comments and annotations to the stream, with the given prefix
|
||||
* before each line.
|
||||
*/
|
||||
void WriteToStream(std::ostream* out, const StringPiece& prefix) const;
|
||||
void WriteToStream(std::ostream* out, const android::StringPiece& prefix) const;
|
||||
|
||||
private:
|
||||
enum : uint32_t {
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
#include "java/ClassDefinition.h"
|
||||
|
||||
#include "util/StringPiece.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -43,7 +45,7 @@ void ClassDefinition::WriteToStream(const StringPiece& prefix, bool final,
|
||||
}
|
||||
*out << "final class " << name_ << " {\n";
|
||||
|
||||
std::string new_prefix = prefix.ToString();
|
||||
std::string new_prefix = prefix.to_string();
|
||||
new_prefix.append(kIndent);
|
||||
|
||||
for (const std::unique_ptr<ClassMember>& member : members_) {
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
#include <string>
|
||||
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "Resource.h"
|
||||
#include "java/AnnotationProcessor.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
namespace aapt {
|
||||
@@ -41,7 +41,7 @@ class ClassMember {
|
||||
|
||||
virtual bool empty() const = 0;
|
||||
|
||||
virtual void WriteToStream(const StringPiece& prefix, bool final,
|
||||
virtual void WriteToStream(const android::StringPiece& prefix, bool final,
|
||||
std::ostream* out) const {
|
||||
processor_.WriteToStream(out, prefix);
|
||||
}
|
||||
@@ -53,12 +53,12 @@ class ClassMember {
|
||||
template <typename T>
|
||||
class PrimitiveMember : public ClassMember {
|
||||
public:
|
||||
PrimitiveMember(const StringPiece& name, const T& val)
|
||||
: name_(name.ToString()), val_(val) {}
|
||||
PrimitiveMember(const android::StringPiece& name, const T& val)
|
||||
: name_(name.to_string()), val_(val) {}
|
||||
|
||||
bool empty() const override { return false; }
|
||||
|
||||
void WriteToStream(const StringPiece& prefix, bool final,
|
||||
void WriteToStream(const android::StringPiece& prefix, bool final,
|
||||
std::ostream* out) const override {
|
||||
ClassMember::WriteToStream(prefix, final, out);
|
||||
|
||||
@@ -79,12 +79,12 @@ class PrimitiveMember : public ClassMember {
|
||||
template <>
|
||||
class PrimitiveMember<std::string> : public ClassMember {
|
||||
public:
|
||||
PrimitiveMember(const StringPiece& name, const std::string& val)
|
||||
: name_(name.ToString()), val_(val) {}
|
||||
PrimitiveMember(const android::StringPiece& name, const std::string& val)
|
||||
: name_(name.to_string()), val_(val) {}
|
||||
|
||||
bool empty() const override { return false; }
|
||||
|
||||
void WriteToStream(const StringPiece& prefix, bool final,
|
||||
void WriteToStream(const android::StringPiece& prefix, bool final,
|
||||
std::ostream* out) const override {
|
||||
ClassMember::WriteToStream(prefix, final, out);
|
||||
|
||||
@@ -106,14 +106,13 @@ using StringMember = PrimitiveMember<std::string>;
|
||||
template <typename T>
|
||||
class PrimitiveArrayMember : public ClassMember {
|
||||
public:
|
||||
explicit PrimitiveArrayMember(const StringPiece& name)
|
||||
: name_(name.ToString()) {}
|
||||
explicit PrimitiveArrayMember(const android::StringPiece& name) : name_(name.to_string()) {}
|
||||
|
||||
void AddElement(const T& val) { elements_.push_back(val); }
|
||||
|
||||
bool empty() const override { return false; }
|
||||
|
||||
void WriteToStream(const StringPiece& prefix, bool final,
|
||||
void WriteToStream(const android::StringPiece& prefix, bool final,
|
||||
std::ostream* out) const override {
|
||||
ClassMember::WriteToStream(prefix, final, out);
|
||||
|
||||
@@ -147,22 +146,18 @@ enum class ClassQualifier { None, Static };
|
||||
|
||||
class ClassDefinition : public ClassMember {
|
||||
public:
|
||||
static bool WriteJavaFile(const ClassDefinition* def,
|
||||
const StringPiece& package, bool final,
|
||||
std::ostream* out);
|
||||
static bool WriteJavaFile(const ClassDefinition* def, const android::StringPiece& package,
|
||||
bool final, std::ostream* out);
|
||||
|
||||
ClassDefinition(const StringPiece& name, ClassQualifier qualifier,
|
||||
bool createIfEmpty)
|
||||
: name_(name.ToString()),
|
||||
qualifier_(qualifier),
|
||||
create_if_empty_(createIfEmpty) {}
|
||||
ClassDefinition(const android::StringPiece& name, ClassQualifier qualifier, bool createIfEmpty)
|
||||
: name_(name.to_string()), qualifier_(qualifier), create_if_empty_(createIfEmpty) {}
|
||||
|
||||
void AddMember(std::unique_ptr<ClassMember> member) {
|
||||
members_.push_back(std::move(member));
|
||||
}
|
||||
|
||||
bool empty() const override;
|
||||
void WriteToStream(const StringPiece& prefix, bool final,
|
||||
void WriteToStream(const android::StringPiece& prefix, bool final,
|
||||
std::ostream* out) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <tuple>
|
||||
|
||||
#include "android-base/logging.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "NameMangler.h"
|
||||
#include "Resource.h"
|
||||
@@ -32,7 +33,8 @@
|
||||
#include "java/AnnotationProcessor.h"
|
||||
#include "java/ClassDefinition.h"
|
||||
#include "process/SymbolTable.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -58,7 +60,7 @@ static bool IsValidSymbol(const StringPiece& symbol) {
|
||||
* Replace those with '_'.
|
||||
*/
|
||||
static std::string Transform(const StringPiece& symbol) {
|
||||
std::string output = symbol.ToString();
|
||||
std::string output = symbol.to_string();
|
||||
for (char& c : output) {
|
||||
if (c == '.' || c == '-') {
|
||||
c = '_';
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "ResourceTable.h"
|
||||
#include "ResourceValues.h"
|
||||
#include "process/IResourceTableConsumer.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
|
||||
@@ -69,22 +70,20 @@ class JavaClassGenerator {
|
||||
* We need to generate these symbols in a separate file.
|
||||
* Returns true on success.
|
||||
*/
|
||||
bool Generate(const StringPiece& packageNameToGenerate, std::ostream* out);
|
||||
bool Generate(const android::StringPiece& packageNameToGenerate, std::ostream* out);
|
||||
|
||||
bool Generate(const StringPiece& packageNameToGenerate,
|
||||
const StringPiece& outputPackageName, std::ostream* out);
|
||||
bool Generate(const android::StringPiece& packageNameToGenerate,
|
||||
const android::StringPiece& outputPackageName, std::ostream* out);
|
||||
|
||||
const std::string& getError() const;
|
||||
|
||||
private:
|
||||
bool AddMembersToTypeClass(const StringPiece& packageNameToGenerate,
|
||||
const ResourceTablePackage* package,
|
||||
const ResourceTableType* type,
|
||||
bool AddMembersToTypeClass(const android::StringPiece& packageNameToGenerate,
|
||||
const ResourceTablePackage* package, const ResourceTableType* type,
|
||||
ClassDefinition* outTypeClassDef);
|
||||
|
||||
void AddMembersToStyleableClass(const StringPiece& packageNameToGenerate,
|
||||
const std::string& entryName,
|
||||
const Styleable* styleable,
|
||||
void AddMembersToStyleableClass(const android::StringPiece& packageNameToGenerate,
|
||||
const std::string& entryName, const Styleable* styleable,
|
||||
ClassDefinition* outStyleableClassDef);
|
||||
|
||||
bool SkipSymbol(SymbolState state);
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "test/Test.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
TEST(JavaClassGeneratorTest, FailWhenEntryIsJavaKeyword) {
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "util/Maybe.h"
|
||||
#include "xml/XmlDom.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
static Maybe<StringPiece> ExtractJavaIdentifier(IDiagnostics* diag,
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
extern int Compile(const std::vector<StringPiece> &args);
|
||||
extern int Link(const std::vector<StringPiece> &args);
|
||||
@@ -65,9 +67,8 @@ static std::vector<ScopedUtfChars> list_to_utfchars(JNIEnv *env, jobject obj) {
|
||||
* The returned pieces can only be used while the original ones have not been
|
||||
* destroyed.
|
||||
*/
|
||||
static std::vector<aapt::StringPiece> extract_pieces(
|
||||
const std::vector<ScopedUtfChars> &strings) {
|
||||
std::vector<aapt::StringPiece> pieces;
|
||||
static std::vector<StringPiece> extract_pieces(const std::vector<ScopedUtfChars> &strings) {
|
||||
std::vector<StringPiece> pieces;
|
||||
|
||||
std::for_each(
|
||||
strings.begin(), strings.end(),
|
||||
@@ -80,8 +81,7 @@ JNIEXPORT void JNICALL Java_com_android_tools_aapt2_Aapt2Jni_nativeCompile(
|
||||
JNIEnv *env, jclass aapt_obj, jobject arguments_obj) {
|
||||
std::vector<ScopedUtfChars> compile_args_jni =
|
||||
list_to_utfchars(env, arguments_obj);
|
||||
std::vector<aapt::StringPiece> compile_args =
|
||||
extract_pieces(compile_args_jni);
|
||||
std::vector<StringPiece> compile_args = extract_pieces(compile_args_jni);
|
||||
aapt::Compile(compile_args);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ JNIEXPORT void JNICALL Java_com_android_tools_aapt2_Aapt2Jni_nativeLink(
|
||||
JNIEnv *env, jclass aapt_obj, jobject arguments_obj) {
|
||||
std::vector<ScopedUtfChars> link_args_jni =
|
||||
list_to_utfchars(env, arguments_obj);
|
||||
std::vector<aapt::StringPiece> link_args = extract_pieces(link_args_jni);
|
||||
std::vector<StringPiece> link_args = extract_pieces(link_args_jni);
|
||||
aapt::Link(link_args);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "android-base/errors.h"
|
||||
#include "android-base/file.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
|
||||
#include "AppInfo.h"
|
||||
@@ -51,9 +52,9 @@
|
||||
#include "split/TableSplitter.h"
|
||||
#include "unflatten/BinaryResourceParser.h"
|
||||
#include "util/Files.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "xml/XmlDom.h"
|
||||
|
||||
using android::StringPiece;
|
||||
using ::google::protobuf::io::CopyingOutputStreamAdaptor;
|
||||
|
||||
namespace aapt {
|
||||
@@ -121,7 +122,7 @@ class LinkContext : public IAaptContext {
|
||||
}
|
||||
|
||||
void SetCompilationPackage(const StringPiece& package_name) {
|
||||
compilation_package_ = package_name.ToString();
|
||||
compilation_package_ = package_name.to_string();
|
||||
}
|
||||
|
||||
uint8_t GetPackageId() override { return package_id_; }
|
||||
@@ -2011,14 +2012,14 @@ int Link(const std::vector<StringPiece>& args) {
|
||||
for (std::string& extra_package : extra_java_packages) {
|
||||
// A given package can actually be a colon separated list of packages.
|
||||
for (StringPiece package : util::Split(extra_package, ':')) {
|
||||
options.extra_java_packages.insert(package.ToString());
|
||||
options.extra_java_packages.insert(package.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
if (product_list) {
|
||||
for (StringPiece product : util::Tokenize(product_list.value(), ',')) {
|
||||
if (product != "" && product != "default") {
|
||||
options.products.insert(product.ToString());
|
||||
options.products.insert(product.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "xml/XmlActionExecutor.h"
|
||||
#include "xml/XmlDom.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
/**
|
||||
@@ -293,7 +295,7 @@ static bool RenameManifestPackage(const StringPiece& package_override,
|
||||
CHECK(attr != nullptr);
|
||||
|
||||
std::string original_package = std::move(attr->value);
|
||||
attr->value = package_override.ToString();
|
||||
attr->value = package_override.to_string();
|
||||
|
||||
FullyQualifiedClassNameVisitor visitor(original_package);
|
||||
manifest_el->Accept(&visitor);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "test/Test.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
struct ManifestFixerTest : public ::testing::Test {
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include "util/Util.h"
|
||||
#include "xml/XmlUtil.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
namespace {
|
||||
@@ -192,8 +194,7 @@ class EmptyDeclStack : public xml::IPackageDeclStack {
|
||||
const StringPiece& alias,
|
||||
const StringPiece& local_package) const override {
|
||||
if (alias.empty()) {
|
||||
return xml::ExtractedPackage{local_package.ToString(),
|
||||
true /* private */};
|
||||
return xml::ExtractedPackage{local_package.to_string(), true /* private */};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "ValueVisitor.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
TableMerger::TableMerger(IAaptContext* context, ResourceTable* out_table,
|
||||
@@ -351,9 +353,8 @@ std::unique_ptr<FileReference> TableMerger::CloneAndMangleFile(
|
||||
const std::string& package, const FileReference& file_ref) {
|
||||
StringPiece prefix, entry, suffix;
|
||||
if (util::ExtractResFilePathParts(*file_ref.path, &prefix, &entry, &suffix)) {
|
||||
std::string mangled_entry =
|
||||
NameMangler::MangleEntry(package, entry.ToString());
|
||||
std::string newPath = prefix.ToString() + mangled_entry + suffix.ToString();
|
||||
std::string mangled_entry = NameMangler::MangleEntry(package, entry.to_string());
|
||||
std::string newPath = prefix.to_string() + mangled_entry + suffix.to_string();
|
||||
std::unique_ptr<FileReference> new_file_ref =
|
||||
util::make_unique<FileReference>(
|
||||
master_table_->string_pool.MakeRef(newPath));
|
||||
|
||||
@@ -96,8 +96,8 @@ class TableMerger {
|
||||
* An io::IFileCollection is needed in order to find the referenced Files and
|
||||
* process them.
|
||||
*/
|
||||
bool MergeAndMangle(const Source& src, const StringPiece& package,
|
||||
ResourceTable* table, io::IFileCollection* collection);
|
||||
bool MergeAndMangle(const Source& src, const android::StringPiece& package, ResourceTable* table,
|
||||
io::IFileCollection* collection);
|
||||
|
||||
/**
|
||||
* Merges a compiled file that belongs to this same or empty package. This is
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "test/Test.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
static std::unique_ptr<ResourceTable> BuildTableWithConfigs(
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "ValueVisitor.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
void SymbolTable::AppendSource(std::unique_ptr<ISymbolSource> source) {
|
||||
|
||||
@@ -154,7 +154,7 @@ class AssetManagerSymbolSource : public ISymbolSource {
|
||||
public:
|
||||
AssetManagerSymbolSource() = default;
|
||||
|
||||
bool AddAssetPath(const StringPiece& path);
|
||||
bool AddAssetPath(const android::StringPiece& path);
|
||||
|
||||
std::unique_ptr<SymbolTable::Symbol> FindByName(
|
||||
const ResourceName& name) override;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "proto/ProtoSerialize.h"
|
||||
#include "util/BigBuffer.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include "android-base/logging.h"
|
||||
|
||||
using google::protobuf::io::CodedOutputStream;
|
||||
using google::protobuf::io::CodedInputStream;
|
||||
@@ -239,7 +239,7 @@ std::unique_ptr<pb::ResourceTable> SerializeTableToPb(ResourceTable* table) {
|
||||
if (type->id) {
|
||||
pb_type->set_id(type->id.value());
|
||||
}
|
||||
pb_type->set_name(ToString(type->type).ToString());
|
||||
pb_type->set_name(ToString(type->type).to_string());
|
||||
|
||||
for (auto& entry : type->entries) {
|
||||
pb::Entry* pb_entry = pb_type->add_entries();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "android-base/logging.h"
|
||||
|
||||
#include "ConfigDescription.h"
|
||||
|
||||
@@ -37,95 +37,86 @@ class ResourceTableBuilder {
|
||||
|
||||
StringPool* string_pool() { return &table_->string_pool; }
|
||||
|
||||
ResourceTableBuilder& SetPackageId(const StringPiece& package_name,
|
||||
uint8_t id) {
|
||||
ResourceTableBuilder& SetPackageId(const android::StringPiece& package_name, uint8_t id) {
|
||||
ResourceTablePackage* package = table_->CreatePackage(package_name, id);
|
||||
CHECK(package != nullptr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddSimple(const StringPiece& name,
|
||||
const ResourceId& id = {}) {
|
||||
ResourceTableBuilder& AddSimple(const android::StringPiece& name, const ResourceId& id = {}) {
|
||||
return AddValue(name, id, util::make_unique<Id>());
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddSimple(const StringPiece& name,
|
||||
const ConfigDescription& config,
|
||||
ResourceTableBuilder& AddSimple(const android::StringPiece& name, const ConfigDescription& config,
|
||||
const ResourceId& id = {}) {
|
||||
return AddValue(name, config, id, util::make_unique<Id>());
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddReference(const StringPiece& name,
|
||||
const StringPiece& ref) {
|
||||
ResourceTableBuilder& AddReference(const android::StringPiece& name,
|
||||
const android::StringPiece& ref) {
|
||||
return AddReference(name, {}, ref);
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddReference(const StringPiece& name,
|
||||
const ResourceId& id,
|
||||
const StringPiece& ref) {
|
||||
ResourceTableBuilder& AddReference(const android::StringPiece& name, const ResourceId& id,
|
||||
const android::StringPiece& ref) {
|
||||
return AddValue(name, id,
|
||||
util::make_unique<Reference>(ParseNameOrDie(ref)));
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddString(const StringPiece& name,
|
||||
const StringPiece& str) {
|
||||
ResourceTableBuilder& AddString(const android::StringPiece& name,
|
||||
const android::StringPiece& str) {
|
||||
return AddString(name, {}, str);
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddString(const StringPiece& name, const ResourceId& id,
|
||||
const StringPiece& str) {
|
||||
ResourceTableBuilder& AddString(const android::StringPiece& name, const ResourceId& id,
|
||||
const android::StringPiece& str) {
|
||||
return AddValue(
|
||||
name, id, util::make_unique<String>(table_->string_pool.MakeRef(str)));
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddString(const StringPiece& name, const ResourceId& id,
|
||||
ResourceTableBuilder& AddString(const android::StringPiece& name, const ResourceId& id,
|
||||
const ConfigDescription& config,
|
||||
const StringPiece& str) {
|
||||
const android::StringPiece& str) {
|
||||
return AddValue(name, config, id, util::make_unique<String>(
|
||||
table_->string_pool.MakeRef(str)));
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddFileReference(const StringPiece& name,
|
||||
const StringPiece& path) {
|
||||
ResourceTableBuilder& AddFileReference(const android::StringPiece& name,
|
||||
const android::StringPiece& path) {
|
||||
return AddFileReference(name, {}, path);
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddFileReference(const StringPiece& name,
|
||||
const ResourceId& id,
|
||||
const StringPiece& path) {
|
||||
ResourceTableBuilder& AddFileReference(const android::StringPiece& name, const ResourceId& id,
|
||||
const android::StringPiece& path) {
|
||||
return AddValue(name, id, util::make_unique<FileReference>(
|
||||
table_->string_pool.MakeRef(path)));
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddFileReference(const StringPiece& name,
|
||||
const StringPiece& path,
|
||||
ResourceTableBuilder& AddFileReference(const android::StringPiece& name,
|
||||
const android::StringPiece& path,
|
||||
const ConfigDescription& config) {
|
||||
return AddValue(name, config, {}, util::make_unique<FileReference>(
|
||||
table_->string_pool.MakeRef(path)));
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddValue(const StringPiece& name,
|
||||
std::unique_ptr<Value> value) {
|
||||
ResourceTableBuilder& AddValue(const android::StringPiece& name, std::unique_ptr<Value> value) {
|
||||
return AddValue(name, {}, std::move(value));
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddValue(const StringPiece& name, const ResourceId& id,
|
||||
ResourceTableBuilder& AddValue(const android::StringPiece& name, const ResourceId& id,
|
||||
std::unique_ptr<Value> value) {
|
||||
return AddValue(name, {}, id, std::move(value));
|
||||
}
|
||||
|
||||
ResourceTableBuilder& AddValue(const StringPiece& name,
|
||||
const ConfigDescription& config,
|
||||
const ResourceId& id,
|
||||
std::unique_ptr<Value> value) {
|
||||
ResourceTableBuilder& AddValue(const android::StringPiece& name, const ConfigDescription& config,
|
||||
const ResourceId& id, std::unique_ptr<Value> value) {
|
||||
ResourceName res_name = ParseNameOrDie(name);
|
||||
CHECK(table_->AddResourceAllowMangled(res_name, id, config, {},
|
||||
std::move(value), &diagnostics_));
|
||||
return *this;
|
||||
}
|
||||
|
||||
ResourceTableBuilder& SetSymbolState(const StringPiece& name,
|
||||
const ResourceId& id,
|
||||
ResourceTableBuilder& SetSymbolState(const android::StringPiece& name, const ResourceId& id,
|
||||
SymbolState state) {
|
||||
ResourceName res_name = ParseNameOrDie(name);
|
||||
Symbol symbol;
|
||||
@@ -144,8 +135,8 @@ class ResourceTableBuilder {
|
||||
std::unique_ptr<ResourceTable> table_ = util::make_unique<ResourceTable>();
|
||||
};
|
||||
|
||||
inline std::unique_ptr<Reference> BuildReference(
|
||||
const StringPiece& ref, const Maybe<ResourceId>& id = {}) {
|
||||
inline std::unique_ptr<Reference> BuildReference(const android::StringPiece& ref,
|
||||
const Maybe<ResourceId>& id = {}) {
|
||||
std::unique_ptr<Reference> reference =
|
||||
util::make_unique<Reference>(ParseNameOrDie(ref));
|
||||
reference->id = id;
|
||||
@@ -174,7 +165,7 @@ class ValueBuilder {
|
||||
return *this;
|
||||
}
|
||||
|
||||
ValueBuilder& SetComment(const StringPiece& str) {
|
||||
ValueBuilder& SetComment(const android::StringPiece& str) {
|
||||
value_->SetComment(str);
|
||||
return *this;
|
||||
}
|
||||
@@ -199,7 +190,7 @@ class AttributeBuilder {
|
||||
return *this;
|
||||
}
|
||||
|
||||
AttributeBuilder& AddItem(const StringPiece& name, uint32_t value) {
|
||||
AttributeBuilder& AddItem(const android::StringPiece& name, uint32_t value) {
|
||||
attr_->symbols.push_back(Attribute::Symbol{
|
||||
Reference(ResourceName({}, ResourceType::kId, name)), value});
|
||||
return *this;
|
||||
@@ -217,18 +208,18 @@ class StyleBuilder {
|
||||
public:
|
||||
StyleBuilder() = default;
|
||||
|
||||
StyleBuilder& SetParent(const StringPiece& str) {
|
||||
StyleBuilder& SetParent(const android::StringPiece& str) {
|
||||
style_->parent = Reference(ParseNameOrDie(str));
|
||||
return *this;
|
||||
}
|
||||
|
||||
StyleBuilder& AddItem(const StringPiece& str, std::unique_ptr<Item> value) {
|
||||
StyleBuilder& AddItem(const android::StringPiece& str, std::unique_ptr<Item> value) {
|
||||
style_->entries.push_back(
|
||||
Style::Entry{Reference(ParseNameOrDie(str)), std::move(value)});
|
||||
return *this;
|
||||
}
|
||||
|
||||
StyleBuilder& AddItem(const StringPiece& str, const ResourceId& id,
|
||||
StyleBuilder& AddItem(const android::StringPiece& str, const ResourceId& id,
|
||||
std::unique_ptr<Item> value) {
|
||||
AddItem(str, std::move(value));
|
||||
style_->entries.back().key.id = id;
|
||||
@@ -247,8 +238,7 @@ class StyleableBuilder {
|
||||
public:
|
||||
StyleableBuilder() = default;
|
||||
|
||||
StyleableBuilder& AddItem(const StringPiece& str,
|
||||
const Maybe<ResourceId>& id = {}) {
|
||||
StyleableBuilder& AddItem(const android::StringPiece& str, const Maybe<ResourceId>& id = {}) {
|
||||
styleable_->entries.push_back(Reference(ParseNameOrDie(str)));
|
||||
styleable_->entries.back().id = id;
|
||||
return *this;
|
||||
@@ -262,7 +252,7 @@ class StyleableBuilder {
|
||||
std::unique_ptr<Styleable> styleable_ = util::make_unique<Styleable>();
|
||||
};
|
||||
|
||||
inline std::unique_ptr<xml::XmlResource> BuildXmlDom(const StringPiece& str) {
|
||||
inline std::unique_ptr<xml::XmlResource> BuildXmlDom(const android::StringPiece& str) {
|
||||
std::stringstream in;
|
||||
in << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" << str;
|
||||
StdErrDiagnostics diag;
|
||||
@@ -273,7 +263,7 @@ inline std::unique_ptr<xml::XmlResource> BuildXmlDom(const StringPiece& str) {
|
||||
}
|
||||
|
||||
inline std::unique_ptr<xml::XmlResource> BuildXmlDomForPackageName(
|
||||
IAaptContext* context, const StringPiece& str) {
|
||||
IAaptContext* context, const android::StringPiece& str) {
|
||||
std::unique_ptr<xml::XmlResource> doc = BuildXmlDom(str);
|
||||
doc->file.name.package = context->GetCompilationPackage();
|
||||
return doc;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "android-base/logging.h"
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "ConfigDescription.h"
|
||||
@@ -30,7 +31,6 @@
|
||||
#include "ValueVisitor.h"
|
||||
#include "io/File.h"
|
||||
#include "process/IResourceTableConsumer.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
//
|
||||
// GTEST 1.7 doesn't explicitly cast to bool, which causes explicit operators to
|
||||
@@ -68,23 +68,22 @@ inline IDiagnostics* GetDiagnostics() {
|
||||
return &diag;
|
||||
}
|
||||
|
||||
inline ResourceName ParseNameOrDie(const StringPiece& str) {
|
||||
inline ResourceName ParseNameOrDie(const android::StringPiece& str) {
|
||||
ResourceNameRef ref;
|
||||
CHECK(ResourceUtils::ParseResourceName(str, &ref)) << "invalid resource name";
|
||||
return ref.ToResourceName();
|
||||
}
|
||||
|
||||
inline ConfigDescription ParseConfigOrDie(const StringPiece& str) {
|
||||
inline ConfigDescription ParseConfigOrDie(const android::StringPiece& str) {
|
||||
ConfigDescription config;
|
||||
CHECK(ConfigDescription::Parse(str, &config)) << "invalid configuration";
|
||||
return config;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* GetValueForConfigAndProduct(ResourceTable* table,
|
||||
const StringPiece& res_name,
|
||||
T* GetValueForConfigAndProduct(ResourceTable* table, const android::StringPiece& res_name,
|
||||
const ConfigDescription& config,
|
||||
const StringPiece& product) {
|
||||
const android::StringPiece& product) {
|
||||
Maybe<ResourceTable::SearchResult> result =
|
||||
table->FindResource(ParseNameOrDie(res_name));
|
||||
if (result) {
|
||||
@@ -98,19 +97,19 @@ T* GetValueForConfigAndProduct(ResourceTable* table,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* GetValueForConfig(ResourceTable* table, const StringPiece& res_name,
|
||||
T* GetValueForConfig(ResourceTable* table, const android::StringPiece& res_name,
|
||||
const ConfigDescription& config) {
|
||||
return GetValueForConfigAndProduct<T>(table, res_name, config, {});
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* GetValue(ResourceTable* table, const StringPiece& res_name) {
|
||||
T* GetValue(ResourceTable* table, const android::StringPiece& res_name) {
|
||||
return GetValueForConfig<T>(table, res_name, {});
|
||||
}
|
||||
|
||||
class TestFile : public io::IFile {
|
||||
public:
|
||||
explicit TestFile(const StringPiece& path) : source_(path) {}
|
||||
explicit TestFile(const android::StringPiece& path) : source_(path) {}
|
||||
|
||||
std::unique_ptr<io::IData> OpenAsData() override { return {}; }
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ class Context : public IAaptContext {
|
||||
|
||||
class ContextBuilder {
|
||||
public:
|
||||
ContextBuilder& SetCompilationPackage(const StringPiece& package) {
|
||||
context_->compilation_package_ = package.ToString();
|
||||
ContextBuilder& SetCompilationPackage(const android::StringPiece& package) {
|
||||
context_->compilation_package_ = package.to_string();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -103,9 +103,8 @@ class ContextBuilder {
|
||||
|
||||
class StaticSymbolSourceBuilder {
|
||||
public:
|
||||
StaticSymbolSourceBuilder& AddPublicSymbol(
|
||||
const StringPiece& name, ResourceId id,
|
||||
std::unique_ptr<Attribute> attr = {}) {
|
||||
StaticSymbolSourceBuilder& AddPublicSymbol(const android::StringPiece& name, ResourceId id,
|
||||
std::unique_ptr<Attribute> attr = {}) {
|
||||
std::unique_ptr<SymbolTable::Symbol> symbol =
|
||||
util::make_unique<SymbolTable::Symbol>(id, std::move(attr), true);
|
||||
symbol_source_->name_map_[ParseNameOrDie(name)] = symbol.get();
|
||||
@@ -114,7 +113,7 @@ class StaticSymbolSourceBuilder {
|
||||
return *this;
|
||||
}
|
||||
|
||||
StaticSymbolSourceBuilder& AddSymbol(const StringPiece& name, ResourceId id,
|
||||
StaticSymbolSourceBuilder& AddSymbol(const android::StringPiece& name, ResourceId id,
|
||||
std::unique_ptr<Attribute> attr = {}) {
|
||||
std::unique_ptr<SymbolTable::Symbol> symbol =
|
||||
util::make_unique<SymbolTable::Symbol>(id, std::move(attr), false);
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
namespace file {
|
||||
|
||||
@@ -72,10 +74,9 @@ FileType GetFileType(const StringPiece& path) {
|
||||
|
||||
inline static int MkdirImpl(const StringPiece& path) {
|
||||
#ifdef _WIN32
|
||||
return _mkdir(path.ToString().c_str());
|
||||
return _mkdir(path.to_string().c_str());
|
||||
#else
|
||||
return mkdir(path.ToString().c_str(),
|
||||
S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP);
|
||||
return mkdir(path.to_string().c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -184,7 +185,7 @@ bool AppendArgsFromFile(const StringPiece& path,
|
||||
std::vector<std::string>* out_arglist,
|
||||
std::string* out_error) {
|
||||
std::string contents;
|
||||
if (!android::base::ReadFileToString(path.ToString(), &contents)) {
|
||||
if (!android::base::ReadFileToString(path.to_string(), &contents)) {
|
||||
if (out_error) *out_error = "failed to read argument-list file";
|
||||
return false;
|
||||
}
|
||||
@@ -192,7 +193,7 @@ bool AppendArgsFromFile(const StringPiece& path,
|
||||
for (StringPiece line : util::Tokenize(contents, ' ')) {
|
||||
line = util::TrimWhitespace(line);
|
||||
if (!line.empty()) {
|
||||
out_arglist->push_back(line.ToString());
|
||||
out_arglist->push_back(line.to_string());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "utils/FileMap.h"
|
||||
|
||||
#include "Diagnostics.h"
|
||||
#include "Maybe.h"
|
||||
#include "Source.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
namespace aapt {
|
||||
namespace file {
|
||||
@@ -50,51 +50,49 @@ enum class FileType {
|
||||
kSocket,
|
||||
};
|
||||
|
||||
FileType GetFileType(const StringPiece& path);
|
||||
FileType GetFileType(const android::StringPiece& path);
|
||||
|
||||
/*
|
||||
* Appends a path to `base`, separated by the directory separator.
|
||||
*/
|
||||
void AppendPath(std::string* base, StringPiece part);
|
||||
void AppendPath(std::string* base, android::StringPiece part);
|
||||
|
||||
/*
|
||||
* Makes all the directories in `path`. The last element in the path
|
||||
* is interpreted as a directory.
|
||||
*/
|
||||
bool mkdirs(const StringPiece& path);
|
||||
bool mkdirs(const android::StringPiece& path);
|
||||
|
||||
/**
|
||||
* Returns all but the last part of the path.
|
||||
*/
|
||||
StringPiece GetStem(const StringPiece& path);
|
||||
android::StringPiece GetStem(const android::StringPiece& path);
|
||||
|
||||
/**
|
||||
* Returns the last part of the path with extension.
|
||||
*/
|
||||
StringPiece GetFilename(const StringPiece& path);
|
||||
android::StringPiece GetFilename(const android::StringPiece& path);
|
||||
|
||||
/**
|
||||
* Returns the extension of the path. This is the entire string after
|
||||
* the first '.' of the last part of the path.
|
||||
*/
|
||||
StringPiece GetExtension(const StringPiece& path);
|
||||
android::StringPiece GetExtension(const android::StringPiece& path);
|
||||
|
||||
/**
|
||||
* Converts a package name (com.android.app) to a path: com/android/app
|
||||
*/
|
||||
std::string PackageToPath(const StringPiece& package);
|
||||
std::string PackageToPath(const android::StringPiece& package);
|
||||
|
||||
/**
|
||||
* Creates a FileMap for the file at path.
|
||||
*/
|
||||
Maybe<android::FileMap> MmapPath(const StringPiece& path,
|
||||
std::string* out_error);
|
||||
Maybe<android::FileMap> MmapPath(const android::StringPiece& path, std::string* out_error);
|
||||
|
||||
/**
|
||||
* Reads the file at path and appends each line to the outArgList vector.
|
||||
*/
|
||||
bool AppendArgsFromFile(const StringPiece& path,
|
||||
std::vector<std::string>* out_arglist,
|
||||
bool AppendArgsFromFile(const android::StringPiece& path, std::vector<std::string>* out_arglist,
|
||||
std::string* out_error);
|
||||
|
||||
/*
|
||||
@@ -120,7 +118,7 @@ class FileFilter {
|
||||
* - Otherwise the full string is matched.
|
||||
* - match is not case-sensitive.
|
||||
*/
|
||||
bool SetPattern(const StringPiece& pattern);
|
||||
bool SetPattern(const android::StringPiece& pattern);
|
||||
|
||||
/**
|
||||
* Applies the filter, returning true for pass, false for fail.
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
|
||||
#include "util/Util.h"
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/Maybe.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
#include <utils/Unicode.h>
|
||||
#include <algorithm>
|
||||
@@ -25,6 +22,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/Maybe.h"
|
||||
|
||||
using android::StringPiece;
|
||||
using android::StringPiece16;
|
||||
|
||||
namespace aapt {
|
||||
namespace util {
|
||||
|
||||
@@ -36,7 +41,7 @@ static std::vector<std::string> SplitAndTransform(
|
||||
StringPiece::const_iterator current;
|
||||
do {
|
||||
current = std::find(start, end, sep);
|
||||
parts.emplace_back(str.substr(start, current).ToString());
|
||||
parts.emplace_back(str.substr(start, current).to_string());
|
||||
if (f) {
|
||||
std::string& part = parts.back();
|
||||
std::transform(part.begin(), part.end(), part.begin(), f);
|
||||
@@ -162,7 +167,7 @@ Maybe<std::string> GetFullyQualifiedClassName(const StringPiece& package,
|
||||
}
|
||||
|
||||
if (util::IsJavaClassName(classname)) {
|
||||
return classname.ToString();
|
||||
return classname.to_string();
|
||||
}
|
||||
|
||||
if (package.empty()) {
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/ResourceTypes.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
#include "utils/ByteOrder.h"
|
||||
|
||||
#include "util/BigBuffer.h"
|
||||
#include "util/Maybe.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
// TODO(adamlesinski): remove once http://b/32447322 is resolved.
|
||||
@@ -44,26 +44,24 @@
|
||||
namespace aapt {
|
||||
namespace util {
|
||||
|
||||
std::vector<std::string> Split(const StringPiece& str, char sep);
|
||||
std::vector<std::string> SplitAndLowercase(const StringPiece& str, char sep);
|
||||
std::vector<std::string> Split(const android::StringPiece& str, char sep);
|
||||
std::vector<std::string> SplitAndLowercase(const android::StringPiece& str, char sep);
|
||||
|
||||
/**
|
||||
* Returns true if the string starts with prefix.
|
||||
*/
|
||||
bool StartsWith(const StringPiece& str, const StringPiece& prefix);
|
||||
bool StartsWith(const android::StringPiece& str, const android::StringPiece& prefix);
|
||||
|
||||
/**
|
||||
* Returns true if the string ends with suffix.
|
||||
*/
|
||||
bool EndsWith(const StringPiece& str, const StringPiece& suffix);
|
||||
bool EndsWith(const android::StringPiece& str, const android::StringPiece& suffix);
|
||||
|
||||
/**
|
||||
* Creates a new StringPiece16 that points to a substring
|
||||
* of the original string without leading or trailing whitespace.
|
||||
*/
|
||||
StringPiece TrimWhitespace(const StringPiece& str);
|
||||
|
||||
StringPiece TrimWhitespace(const StringPiece& str);
|
||||
android::StringPiece TrimWhitespace(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* UTF-16 isspace(). It basically checks for lower range characters that are
|
||||
@@ -75,18 +73,18 @@ inline bool isspace16(char16_t c) { return c < 0x0080 && isspace(c); }
|
||||
* Returns an iterator to the first character that is not alpha-numeric and that
|
||||
* is not in the allowedChars set.
|
||||
*/
|
||||
StringPiece::const_iterator FindNonAlphaNumericAndNotInSet(
|
||||
const StringPiece& str, const StringPiece& allowed_chars);
|
||||
android::StringPiece::const_iterator FindNonAlphaNumericAndNotInSet(
|
||||
const android::StringPiece& str, const android::StringPiece& allowed_chars);
|
||||
|
||||
/**
|
||||
* Tests that the string is a valid Java class name.
|
||||
*/
|
||||
bool IsJavaClassName(const StringPiece& str);
|
||||
bool IsJavaClassName(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* Tests that the string is a valid Java package name.
|
||||
*/
|
||||
bool IsJavaPackageName(const StringPiece& str);
|
||||
bool IsJavaPackageName(const android::StringPiece& str);
|
||||
|
||||
/**
|
||||
* Converts the class name to a fully qualified class name from the given
|
||||
@@ -97,8 +95,8 @@ bool IsJavaPackageName(const StringPiece& str);
|
||||
* .a.b --> package.a.b
|
||||
* asdf.adsf --> asdf.adsf
|
||||
*/
|
||||
Maybe<std::string> GetFullyQualifiedClassName(const StringPiece& package,
|
||||
const StringPiece& class_name);
|
||||
Maybe<std::string> GetFullyQualifiedClassName(const android::StringPiece& package,
|
||||
const android::StringPiece& class_name);
|
||||
|
||||
/**
|
||||
* Makes a std::unique_ptr<> with the template parameter inferred by the
|
||||
@@ -138,7 +136,7 @@ template <typename Container>
|
||||
* stored as UTF-8,
|
||||
* the conversion to UTF-16 happens within ResStringPool.
|
||||
*/
|
||||
StringPiece16 GetString16(const android::ResStringPool& pool, size_t idx);
|
||||
android::StringPiece16 GetString16(const android::ResStringPool& pool, size_t idx);
|
||||
|
||||
/**
|
||||
* Helper method to extract a UTF-8 string from a StringPool. If the string is
|
||||
@@ -159,11 +157,11 @@ std::string GetString(const android::ResStringPool& pool, size_t idx);
|
||||
* which will
|
||||
* break the string interpolation.
|
||||
*/
|
||||
bool VerifyJavaStringFormat(const StringPiece& str);
|
||||
bool VerifyJavaStringFormat(const android::StringPiece& str);
|
||||
|
||||
class StringBuilder {
|
||||
public:
|
||||
StringBuilder& Append(const StringPiece& str);
|
||||
StringBuilder& Append(const android::StringPiece& str);
|
||||
const std::string& ToString() const;
|
||||
const std::string& Error() const;
|
||||
|
||||
@@ -194,8 +192,8 @@ inline StringBuilder::operator bool() const { return error_.empty(); }
|
||||
/**
|
||||
* Converts a UTF8 string to a UTF16 string.
|
||||
*/
|
||||
std::u16string Utf8ToUtf16(const StringPiece& utf8);
|
||||
std::string Utf16ToUtf8(const StringPiece16& utf16);
|
||||
std::u16string Utf8ToUtf16(const android::StringPiece& utf8);
|
||||
std::string Utf16ToUtf8(const android::StringPiece16& utf16);
|
||||
|
||||
/**
|
||||
* Writes the entire BigBuffer to the output stream.
|
||||
@@ -220,22 +218,22 @@ class Tokenizer {
|
||||
|
||||
iterator& operator++();
|
||||
|
||||
StringPiece operator*() { return token_; }
|
||||
android::StringPiece operator*() { return token_; }
|
||||
bool operator==(const iterator& rhs) const;
|
||||
bool operator!=(const iterator& rhs) const;
|
||||
|
||||
private:
|
||||
friend class Tokenizer;
|
||||
|
||||
iterator(StringPiece s, char sep, StringPiece tok, bool end);
|
||||
iterator(android::StringPiece s, char sep, android::StringPiece tok, bool end);
|
||||
|
||||
StringPiece str_;
|
||||
android::StringPiece str_;
|
||||
char separator_;
|
||||
StringPiece token_;
|
||||
android::StringPiece token_;
|
||||
bool end_;
|
||||
};
|
||||
|
||||
Tokenizer(StringPiece str, char sep);
|
||||
Tokenizer(android::StringPiece str, char sep);
|
||||
|
||||
iterator begin() { return begin_; }
|
||||
|
||||
@@ -246,9 +244,7 @@ class Tokenizer {
|
||||
const iterator end_;
|
||||
};
|
||||
|
||||
inline Tokenizer Tokenize(const StringPiece& str, char sep) {
|
||||
return Tokenizer(str, sep);
|
||||
}
|
||||
inline Tokenizer Tokenize(const android::StringPiece& str, char sep) { return Tokenizer(str, sep); }
|
||||
|
||||
inline uint16_t HostToDevice16(uint16_t value) { return htods(value); }
|
||||
|
||||
@@ -267,8 +263,8 @@ inline uint32_t DeviceToHost32(uint32_t value) { return dtohl(value); }
|
||||
*
|
||||
* Returns true if successful.
|
||||
*/
|
||||
bool ExtractResFilePathParts(const StringPiece& path, StringPiece* out_prefix,
|
||||
StringPiece* out_entry, StringPiece* out_suffix);
|
||||
bool ExtractResFilePathParts(const android::StringPiece& path, android::StringPiece* out_prefix,
|
||||
android::StringPiece* out_entry, android::StringPiece* out_suffix);
|
||||
|
||||
} // namespace util
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "test/Test.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
TEST(UtilTest, TrimOnlyWhitespace) {
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
#include "XmlPullParser.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
using android::StringPiece16;
|
||||
|
||||
namespace aapt {
|
||||
namespace xml {
|
||||
|
||||
@@ -52,10 +55,10 @@ static void SplitName(const char* name, std::string* out_ns,
|
||||
|
||||
if (*p == 0) {
|
||||
out_ns->clear();
|
||||
*out_name = StringPiece(name).ToString();
|
||||
out_name->assign(name);
|
||||
} else {
|
||||
*out_ns = StringPiece(name, (p - name)).ToString();
|
||||
*out_name = StringPiece(p + 1).ToString();
|
||||
out_ns->assign(name, (p - name));
|
||||
out_name->assign(p + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,11 +86,11 @@ static void XMLCALL StartNamespaceHandler(void* user_data, const char* prefix,
|
||||
|
||||
std::unique_ptr<Namespace> ns = util::make_unique<Namespace>();
|
||||
if (prefix) {
|
||||
ns->namespace_prefix = StringPiece(prefix).ToString();
|
||||
ns->namespace_prefix = prefix;
|
||||
}
|
||||
|
||||
if (uri) {
|
||||
ns->namespace_uri = StringPiece(uri).ToString();
|
||||
ns->namespace_uri = uri;
|
||||
}
|
||||
|
||||
AddToStack(stack, parser, std::move(ns));
|
||||
@@ -117,7 +120,7 @@ static void XMLCALL StartElementHandler(void* user_data, const char* name,
|
||||
while (*attrs) {
|
||||
Attribute attribute;
|
||||
SplitName(*attrs++, &attribute.namespace_uri, &attribute.name);
|
||||
attribute.value = StringPiece(*attrs++).ToString();
|
||||
attribute.value = *attrs++;
|
||||
|
||||
// Insert in sorted order.
|
||||
auto iter = std::lower_bound(el->attributes.begin(), el->attributes.end(),
|
||||
@@ -153,14 +156,14 @@ static void XMLCALL CharacterDataHandler(void* user_data, const char* s,
|
||||
if (!currentParent->children.empty()) {
|
||||
Node* last_child = currentParent->children.back().get();
|
||||
if (Text* text = NodeCast<Text>(last_child)) {
|
||||
text->text += StringPiece(s, len).ToString();
|
||||
text->text.append(s, len);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Text> text = util::make_unique<Text>();
|
||||
text->text = StringPiece(s, len).ToString();
|
||||
text->text.assign(s, len);
|
||||
AddToStack(stack, parser, std::move(text));
|
||||
}
|
||||
|
||||
@@ -495,15 +498,14 @@ void PackageAwareVisitor::Visit(Namespace* ns) {
|
||||
Maybe<ExtractedPackage> PackageAwareVisitor::TransformPackageAlias(
|
||||
const StringPiece& alias, const StringPiece& local_package) const {
|
||||
if (alias.empty()) {
|
||||
return ExtractedPackage{local_package.ToString(), false /* private */};
|
||||
return ExtractedPackage{local_package.to_string(), false /* private */};
|
||||
}
|
||||
|
||||
const auto rend = package_decls_.rend();
|
||||
for (auto iter = package_decls_.rbegin(); iter != rend; ++iter) {
|
||||
if (alias == iter->prefix) {
|
||||
if (iter->package.package.empty()) {
|
||||
return ExtractedPackage{local_package.ToString(),
|
||||
iter->package.private_namespace};
|
||||
return ExtractedPackage{local_package.to_string(), iter->package.private_namespace};
|
||||
}
|
||||
return iter->package;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "Diagnostics.h"
|
||||
#include "Resource.h"
|
||||
#include "ResourceValues.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "util/Util.h"
|
||||
#include "xml/XmlUtil.h"
|
||||
|
||||
@@ -100,13 +101,13 @@ class Element : public BaseNode<Element> {
|
||||
std::string name;
|
||||
std::vector<Attribute> attributes;
|
||||
|
||||
Attribute* FindAttribute(const StringPiece& ns, const StringPiece& name);
|
||||
xml::Element* FindChild(const StringPiece& ns, const StringPiece& name);
|
||||
xml::Element* FindChildWithAttribute(const StringPiece& ns,
|
||||
const StringPiece& name,
|
||||
const StringPiece& attr_ns,
|
||||
const StringPiece& attr_name,
|
||||
const StringPiece& attr_value);
|
||||
Attribute* FindAttribute(const android::StringPiece& ns, const android::StringPiece& name);
|
||||
xml::Element* FindChild(const android::StringPiece& ns, const android::StringPiece& name);
|
||||
xml::Element* FindChildWithAttribute(const android::StringPiece& ns,
|
||||
const android::StringPiece& name,
|
||||
const android::StringPiece& attr_ns,
|
||||
const android::StringPiece& attr_name,
|
||||
const android::StringPiece& attr_value);
|
||||
std::vector<xml::Element*> GetChildElements();
|
||||
std::unique_ptr<Node> Clone() override;
|
||||
};
|
||||
@@ -190,8 +191,7 @@ class PackageAwareVisitor : public Visitor, public IPackageDeclStack {
|
||||
|
||||
void Visit(Namespace* ns) override;
|
||||
Maybe<ExtractedPackage> TransformPackageAlias(
|
||||
const StringPiece& alias,
|
||||
const StringPiece& local_package) const override;
|
||||
const android::StringPiece& alias, const android::StringPiece& local_package) const override;
|
||||
|
||||
private:
|
||||
struct PackageDecl {
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "xml/XmlPullParser.h"
|
||||
#include "xml/XmlUtil.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
namespace xml {
|
||||
|
||||
@@ -136,15 +138,14 @@ const std::string& XmlPullParser::namespace_uri() const {
|
||||
Maybe<ExtractedPackage> XmlPullParser::TransformPackageAlias(
|
||||
const StringPiece& alias, const StringPiece& local_package) const {
|
||||
if (alias.empty()) {
|
||||
return ExtractedPackage{local_package.ToString(), false /* private */};
|
||||
return ExtractedPackage{local_package.to_string(), false /* private */};
|
||||
}
|
||||
|
||||
const auto end_iter = package_aliases_.rend();
|
||||
for (auto iter = package_aliases_.rbegin(); iter != end_iter; ++iter) {
|
||||
if (alias == iter->prefix) {
|
||||
if (iter->package.package.empty()) {
|
||||
return ExtractedPackage{local_package.ToString(),
|
||||
iter->package.private_namespace};
|
||||
return ExtractedPackage{local_package.to_string(), iter->package.private_namespace};
|
||||
}
|
||||
return iter->package;
|
||||
}
|
||||
@@ -188,19 +189,18 @@ size_t XmlPullParser::attribute_count() const {
|
||||
/**
|
||||
* Extracts the namespace and name of an expanded element or attribute name.
|
||||
*/
|
||||
static void SplitName(const char* name, std::string& out_ns,
|
||||
std::string& out_name) {
|
||||
static void SplitName(const char* name, std::string* out_ns, std::string* out_name) {
|
||||
const char* p = name;
|
||||
while (*p != 0 && *p != kXmlNamespaceSep) {
|
||||
p++;
|
||||
}
|
||||
|
||||
if (*p == 0) {
|
||||
out_ns = std::string();
|
||||
out_name = name;
|
||||
out_ns->clear();
|
||||
out_name->assign(name);
|
||||
} else {
|
||||
out_ns = StringPiece(name, (p - name)).ToString();
|
||||
out_name = p + 1;
|
||||
out_ns->assign(name, (p - name));
|
||||
out_name->assign(p + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,11 +224,11 @@ void XMLCALL XmlPullParser::StartElementHandler(void* user_data,
|
||||
EventData data = {Event::kStartElement,
|
||||
XML_GetCurrentLineNumber(parser->parser_),
|
||||
parser->depth_++};
|
||||
SplitName(name, data.data1, data.data2);
|
||||
SplitName(name, &data.data1, &data.data2);
|
||||
|
||||
while (*attrs) {
|
||||
Attribute attribute;
|
||||
SplitName(*attrs++, attribute.namespace_uri, attribute.name);
|
||||
SplitName(*attrs++, &attribute.namespace_uri, &attribute.name);
|
||||
attribute.value = *attrs++;
|
||||
|
||||
// Insert in sorted order.
|
||||
@@ -245,9 +245,8 @@ void XMLCALL XmlPullParser::CharacterDataHandler(void* user_data, const char* s,
|
||||
int len) {
|
||||
XmlPullParser* parser = reinterpret_cast<XmlPullParser*>(user_data);
|
||||
|
||||
parser->event_queue_.push(
|
||||
EventData{Event::kText, XML_GetCurrentLineNumber(parser->parser_),
|
||||
parser->depth_, StringPiece(s, len).ToString()});
|
||||
parser->event_queue_.push(EventData{Event::kText, XML_GetCurrentLineNumber(parser->parser_),
|
||||
parser->depth_, std::string(s, len)});
|
||||
}
|
||||
|
||||
void XMLCALL XmlPullParser::EndElementHandler(void* user_data,
|
||||
@@ -257,7 +256,7 @@ void XMLCALL XmlPullParser::EndElementHandler(void* user_data,
|
||||
EventData data = {Event::kEndElement,
|
||||
XML_GetCurrentLineNumber(parser->parser_),
|
||||
--(parser->depth_)};
|
||||
SplitName(name, data.data1, data.data2);
|
||||
SplitName(name, &data.data1, &data.data2);
|
||||
|
||||
// Move the data into the queue (no copy).
|
||||
parser->event_queue_.push(std::move(data));
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
#include <vector>
|
||||
|
||||
#include "android-base/macros.h"
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "Resource.h"
|
||||
#include "process/IResourceTableConsumer.h"
|
||||
#include "util/Maybe.h"
|
||||
#include "util/StringPiece.h"
|
||||
#include "xml/XmlUtil.h"
|
||||
|
||||
namespace aapt {
|
||||
@@ -119,8 +119,7 @@ class XmlPullParser : public IPackageDeclStack {
|
||||
* 'package' will be set to 'defaultPackage'.
|
||||
*/
|
||||
Maybe<ExtractedPackage> TransformPackageAlias(
|
||||
const StringPiece& alias,
|
||||
const StringPiece& local_package) const override;
|
||||
const android::StringPiece& alias, const android::StringPiece& local_package) const override;
|
||||
|
||||
//
|
||||
// Remaining methods are for retrieving information about attributes
|
||||
@@ -146,8 +145,7 @@ class XmlPullParser : public IPackageDeclStack {
|
||||
const_iterator begin_attributes() const;
|
||||
const_iterator end_attributes() const;
|
||||
size_t attribute_count() const;
|
||||
const_iterator FindAttribute(StringPiece namespace_uri,
|
||||
StringPiece name) const;
|
||||
const_iterator FindAttribute(android::StringPiece namespace_uri, android::StringPiece name) const;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(XmlPullParser);
|
||||
@@ -190,16 +188,16 @@ class XmlPullParser : public IPackageDeclStack {
|
||||
/**
|
||||
* Finds the attribute in the current element within the global namespace.
|
||||
*/
|
||||
Maybe<StringPiece> FindAttribute(const XmlPullParser* parser,
|
||||
const StringPiece& name);
|
||||
Maybe<android::StringPiece> FindAttribute(const XmlPullParser* parser,
|
||||
const android::StringPiece& name);
|
||||
|
||||
/**
|
||||
* Finds the attribute in the current element within the global namespace. The
|
||||
* attribute's value
|
||||
* must not be the empty string.
|
||||
*/
|
||||
Maybe<StringPiece> FindNonEmptyAttribute(const XmlPullParser* parser,
|
||||
const StringPiece& name);
|
||||
Maybe<android::StringPiece> FindNonEmptyAttribute(const XmlPullParser* parser,
|
||||
const android::StringPiece& name);
|
||||
|
||||
//
|
||||
// Implementation
|
||||
@@ -299,13 +297,13 @@ inline bool XmlPullParser::Attribute::operator!=(const Attribute& rhs) const {
|
||||
}
|
||||
|
||||
inline XmlPullParser::const_iterator XmlPullParser::FindAttribute(
|
||||
StringPiece namespace_uri, StringPiece name) const {
|
||||
android::StringPiece namespace_uri, android::StringPiece name) const {
|
||||
const auto end_iter = end_attributes();
|
||||
const auto iter = std::lower_bound(
|
||||
begin_attributes(), end_iter,
|
||||
std::pair<StringPiece, StringPiece>(namespace_uri, name),
|
||||
std::pair<android::StringPiece, android::StringPiece>(namespace_uri, name),
|
||||
[](const Attribute& attr,
|
||||
const std::pair<StringPiece, StringPiece>& rhs) -> bool {
|
||||
const std::pair<android::StringPiece, android::StringPiece>& rhs) -> bool {
|
||||
int cmp = attr.namespace_uri.compare(
|
||||
0, attr.namespace_uri.size(), rhs.first.data(), rhs.first.size());
|
||||
if (cmp < 0) return true;
|
||||
|
||||
@@ -18,8 +18,11 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
#include "test/Test.h"
|
||||
#include "util/StringPiece.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "util/Maybe.h"
|
||||
#include "util/Util.h"
|
||||
|
||||
using android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
namespace xml {
|
||||
|
||||
@@ -42,7 +44,7 @@ Maybe<ExtractedPackage> ExtractPackageFromNamespace(
|
||||
if (package.empty()) {
|
||||
return {};
|
||||
}
|
||||
return ExtractedPackage{package.ToString(), false /* is_private */};
|
||||
return ExtractedPackage{package.to_string(), false /* is_private */};
|
||||
|
||||
} else if (util::StartsWith(namespace_uri, kSchemaPrivatePrefix)) {
|
||||
StringPiece schema_prefix = kSchemaPrivatePrefix;
|
||||
@@ -52,7 +54,7 @@ Maybe<ExtractedPackage> ExtractPackageFromNamespace(
|
||||
if (package.empty()) {
|
||||
return {};
|
||||
}
|
||||
return ExtractedPackage{package.ToString(), true /* is_private */};
|
||||
return ExtractedPackage{package.to_string(), true /* is_private */};
|
||||
|
||||
} else if (namespace_uri == kSchemaAuto) {
|
||||
return ExtractedPackage{std::string(), true /* is_private */};
|
||||
|
||||
@@ -74,7 +74,7 @@ Maybe<ExtractedPackage> ExtractPackageFromNamespace(
|
||||
*
|
||||
* http://schemas.android.com/apk/prv/res/<package>
|
||||
*/
|
||||
std::string BuildPackageNamespace(const StringPiece& package,
|
||||
std::string BuildPackageNamespace(const android::StringPiece& package,
|
||||
bool private_reference = false);
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ struct IPackageDeclStack {
|
||||
* package declaration.
|
||||
*/
|
||||
virtual Maybe<ExtractedPackage> TransformPackageAlias(
|
||||
const StringPiece& alias, const StringPiece& local_package) const = 0;
|
||||
const android::StringPiece& alias, const android::StringPiece& local_package) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -100,8 +100,7 @@ struct IPackageDeclStack {
|
||||
* the namespace of the package declaration was private.
|
||||
*/
|
||||
void TransformReferenceFromNamespace(IPackageDeclStack* decl_stack,
|
||||
const StringPiece& local_package,
|
||||
Reference* in_ref);
|
||||
const android::StringPiece& local_package, Reference* in_ref);
|
||||
|
||||
} // namespace xml
|
||||
} // namespace aapt
|
||||
|
||||
Reference in New Issue
Block a user