Move StringPool to libandroidfw
Test: verified affected tests pass
Bug: 232940948
Change-Id: I22089893d7e5013f759c39ce190bec07fa6435db
diff --git a/tools/aapt2/compile/IdAssigner.cpp b/tools/aapt2/compile/IdAssigner.cpp
index 29f9a08..b3f98a9 100644
--- a/tools/aapt2/compile/IdAssigner.cpp
+++ b/tools/aapt2/compile/IdAssigner.cpp
@@ -107,10 +107,10 @@
// Returns whether the id was reserved successfully.
// Reserving identifiers must be completed before `NextId` is called for the first time.
bool ReserveId(const ResourceName& name, ResourceId id, const Visibility& visibility,
- IDiagnostics* diag);
+ android::IDiagnostics* diag);
// Retrieves the next available resource id that has not been reserved.
- std::optional<ResourceId> NextId(const ResourceName& name, IDiagnostics* diag);
+ std::optional<ResourceId> NextId(const ResourceName& name, android::IDiagnostics* diag);
private:
std::string package_name_;
@@ -267,11 +267,11 @@
}
bool IdAssignerContext::ReserveId(const ResourceName& name, ResourceId id,
- const Visibility& visibility, IDiagnostics* diag) {
+ const Visibility& visibility, android::IDiagnostics* diag) {
if (package_id_ != id.package_id()) {
- diag->Error(DiagMessage() << "can't assign ID " << id << " to resource " << name
- << " because package already has ID " << std::hex
- << (int)id.package_id());
+ diag->Error(android::DiagMessage()
+ << "can't assign ID " << id << " to resource " << name
+ << " because package already has ID " << std::hex << (int)id.package_id());
return false;
}
@@ -282,8 +282,8 @@
// another type.
auto assign_result = type_id_finder_.ReserveId(key, id.type_id());
if (!assign_result.has_value()) {
- diag->Error(DiagMessage() << "can't assign ID " << id << " to resource " << name
- << " because type " << assign_result.error());
+ diag->Error(android::DiagMessage() << "can't assign ID " << id << " to resource " << name
+ << " because type " << assign_result.error());
return false;
}
type = types_.emplace(key, TypeGroup(package_id_, id.type_id())).first;
@@ -293,24 +293,25 @@
// Ensure that non-staged resources can only exist in one type ID.
auto non_staged_type = non_staged_type_ids_.emplace(name.type.type, id.type_id());
if (!non_staged_type.second && non_staged_type.first->second != id.type_id()) {
- diag->Error(DiagMessage() << "can't assign ID " << id << " to resource " << name
- << " because type already has ID " << std::hex
- << (int)id.type_id());
+ diag->Error(android::DiagMessage()
+ << "can't assign ID " << id << " to resource " << name
+ << " because type already has ID " << std::hex << (int)id.type_id());
return false;
}
}
auto assign_result = type->second.ReserveId(name, id);
if (!assign_result.has_value()) {
- diag->Error(DiagMessage() << "can't assign ID " << id << " to resource " << name << " because "
- << assign_result.error());
+ diag->Error(android::DiagMessage() << "can't assign ID " << id << " to resource " << name
+ << " because " << assign_result.error());
return false;
}
return true;
}
-std::optional<ResourceId> IdAssignerContext::NextId(const ResourceName& name, IDiagnostics* diag) {
+std::optional<ResourceId> IdAssignerContext::NextId(const ResourceName& name,
+ android::IDiagnostics* diag) {
// The package name is not known during the compile stage.
// Resources without a package name are considered a part of the app being linked.
CHECK(name.package.empty() || name.package == package_name_);
@@ -331,8 +332,8 @@
auto assign_result = type->second.NextId();
if (!assign_result.has_value()) {
- diag->Error(DiagMessage() << "can't assign resource ID to resource " << name << " because "
- << assign_result.error());
+ diag->Error(android::DiagMessage() << "can't assign resource ID to resource " << name
+ << " because " << assign_result.error());
return {};
}
return assign_result.value();
diff --git a/tools/aapt2/compile/InlineXmlFormatParser.cpp b/tools/aapt2/compile/InlineXmlFormatParser.cpp
index de1c3bb..444f821 100644
--- a/tools/aapt2/compile/InlineXmlFormatParser.cpp
+++ b/tools/aapt2/compile/InlineXmlFormatParser.cpp
@@ -47,19 +47,19 @@
return;
}
- const Source src = xml_resource_->file.source.WithLine(el->line_number);
+ const android::Source src = xml_resource_->file.source.WithLine(el->line_number);
xml::Attribute* attr = el->FindAttribute({}, "name");
if (!attr) {
- context_->GetDiagnostics()->Error(DiagMessage(src) << "missing 'name' attribute");
+ context_->GetDiagnostics()->Error(android::DiagMessage(src) << "missing 'name' attribute");
error_ = true;
return;
}
std::optional<Reference> ref = ResourceUtils::ParseXmlAttributeName(attr->value);
if (!ref) {
- context_->GetDiagnostics()->Error(DiagMessage(src) << "invalid XML attribute '" << attr->value
- << "'");
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
+ << "invalid XML attribute '" << attr->value << "'");
error_ = true;
return;
}
@@ -67,7 +67,7 @@
const ResourceName& name = ref.value().name.value();
std::optional<xml::ExtractedPackage> maybe_pkg = TransformPackageAlias(name.package);
if (!maybe_pkg) {
- context_->GetDiagnostics()->Error(DiagMessage(src)
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
<< "invalid namespace prefix '" << name.package << "'");
error_ = true;
return;
@@ -136,15 +136,15 @@
// Extracted elements must be the only child of <aapt:attr>.
// Make sure there is one root node in the children (ignore empty text).
for (std::unique_ptr<xml::Node>& child : decl.el->children) {
- const Source child_source = doc->file.source.WithLine(child->line_number);
+ const android::Source child_source = doc->file.source.WithLine(child->line_number);
if (xml::Text* t = xml::NodeCast<xml::Text>(child.get())) {
if (!util::TrimWhitespace(t->text).empty()) {
- context->GetDiagnostics()->Error(DiagMessage(child_source)
+ context->GetDiagnostics()->Error(android::DiagMessage(child_source)
<< "can't extract text into its own resource");
return false;
}
} else if (new_doc->root) {
- context->GetDiagnostics()->Error(DiagMessage(child_source)
+ context->GetDiagnostics()->Error(android::DiagMessage(child_source)
<< "inline XML resources must have a single root");
return false;
} else {
@@ -160,7 +160,7 @@
// Get the parent element of <aapt:attr>
xml::Element* parent_el = decl.el->parent;
if (!parent_el) {
- context->GetDiagnostics()->Error(DiagMessage(new_doc->file.source)
+ context->GetDiagnostics()->Error(android::DiagMessage(new_doc->file.source)
<< "no suitable parent for inheriting attribute");
return false;
}
diff --git a/tools/aapt2/compile/Png.cpp b/tools/aapt2/compile/Png.cpp
index d396d81..76db815 100644
--- a/tools/aapt2/compile/Png.cpp
+++ b/tools/aapt2/compile/Png.cpp
@@ -24,11 +24,10 @@
#include <string>
#include <vector>
+#include "androidfw/BigBuffer.h"
#include "androidfw/ResourceTypes.h"
-
-#include "Source.h"
+#include "androidfw/Source.h"
#include "trace/TraceBuffer.h"
-#include "util/BigBuffer.h"
#include "util/Util.h"
namespace aapt {
@@ -91,7 +90,7 @@
static void writeDataToStream(png_structp writePtr, png_bytep data,
png_size_t length) {
- BigBuffer* outBuffer = reinterpret_cast<BigBuffer*>(png_get_io_ptr(writePtr));
+ android::BigBuffer* outBuffer = reinterpret_cast<android::BigBuffer*>(png_get_io_ptr(writePtr));
png_bytep buf = outBuffer->NextBlock<png_byte>(length);
memcpy(buf, data, length);
}
@@ -99,15 +98,15 @@
static void flushDataToStream(png_structp /*writePtr*/) {}
static void logWarning(png_structp readPtr, png_const_charp warningMessage) {
- IDiagnostics* diag =
- reinterpret_cast<IDiagnostics*>(png_get_error_ptr(readPtr));
- diag->Warn(DiagMessage() << warningMessage);
+ android::IDiagnostics* diag =
+ reinterpret_cast<android::IDiagnostics*>(png_get_error_ptr(readPtr));
+ diag->Warn(android::DiagMessage() << warningMessage);
}
-static bool readPng(IDiagnostics* diag, png_structp readPtr, png_infop infoPtr,
+static bool readPng(android::IDiagnostics* diag, png_structp readPtr, png_infop infoPtr,
PngInfo* outInfo) {
if (setjmp(png_jmpbuf(readPtr))) {
- diag->Error(DiagMessage() << "failed reading png");
+ diag->Error(android::DiagMessage() << "failed reading png");
return false;
}
@@ -245,10 +244,9 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
-static void analyze_image(IDiagnostics* diag, const PngInfo& imageInfo,
- int grayscaleTolerance, png_colorp rgbPalette,
- png_bytep alphaPalette, int* paletteEntries,
- bool* hasTransparency, int* colorType,
+static void analyze_image(android::IDiagnostics* diag, const PngInfo& imageInfo,
+ int grayscaleTolerance, png_colorp rgbPalette, png_bytep alphaPalette,
+ int* paletteEntries, bool* hasTransparency, int* colorType,
png_bytepp outRows) {
int w = imageInfo.width;
int h = imageInfo.height;
@@ -383,8 +381,8 @@
*colorType = PNG_COLOR_TYPE_PALETTE;
} else {
if (maxGrayDeviation <= grayscaleTolerance) {
- diag->Note(DiagMessage() << "forcing image to gray (max deviation = "
- << maxGrayDeviation << ")");
+ diag->Note(android::DiagMessage()
+ << "forcing image to gray (max deviation = " << maxGrayDeviation << ")");
*colorType = isOpaque ? PNG_COLOR_TYPE_GRAY : PNG_COLOR_TYPE_GRAY_ALPHA;
} else {
*colorType = isOpaque ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGB_ALPHA;
@@ -431,10 +429,10 @@
}
}
-static bool writePng(IDiagnostics* diag, png_structp writePtr,
- png_infop infoPtr, PngInfo* info, int grayScaleTolerance) {
+static bool writePng(android::IDiagnostics* diag, png_structp writePtr, png_infop infoPtr,
+ PngInfo* info, int grayScaleTolerance) {
if (setjmp(png_jmpbuf(writePtr))) {
- diag->Error(DiagMessage() << "failed to write png");
+ diag->Error(android::DiagMessage() << "failed to write png");
return false;
}
@@ -463,8 +461,8 @@
png_set_compression_level(writePtr, Z_BEST_COMPRESSION);
if (kDebug) {
- diag->Note(DiagMessage() << "writing image: w = " << info->width
- << ", h = " << info->height);
+ diag->Note(android::DiagMessage()
+ << "writing image: w = " << info->width << ", h = " << info->height);
}
png_color rgbPalette[256];
@@ -486,24 +484,21 @@
if (kDebug) {
switch (colorType) {
case PNG_COLOR_TYPE_PALETTE:
- diag->Note(DiagMessage() << "has " << paletteEntries << " colors"
- << (hasTransparency ? " (with alpha)" : "")
- << ", using PNG_COLOR_TYPE_PALLETTE");
+ diag->Note(android::DiagMessage() << "has " << paletteEntries << " colors"
+ << (hasTransparency ? " (with alpha)" : "")
+ << ", using PNG_COLOR_TYPE_PALLETTE");
break;
case PNG_COLOR_TYPE_GRAY:
- diag->Note(DiagMessage()
- << "is opaque gray, using PNG_COLOR_TYPE_GRAY");
+ diag->Note(android::DiagMessage() << "is opaque gray, using PNG_COLOR_TYPE_GRAY");
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
- diag->Note(DiagMessage()
- << "is gray + alpha, using PNG_COLOR_TYPE_GRAY_ALPHA");
+ diag->Note(android::DiagMessage() << "is gray + alpha, using PNG_COLOR_TYPE_GRAY_ALPHA");
break;
case PNG_COLOR_TYPE_RGB:
- diag->Note(DiagMessage() << "is opaque RGB, using PNG_COLOR_TYPE_RGB");
+ diag->Note(android::DiagMessage() << "is opaque RGB, using PNG_COLOR_TYPE_RGB");
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
- diag->Note(DiagMessage()
- << "is RGB + alpha, using PNG_COLOR_TYPE_RGB_ALPHA");
+ diag->Note(android::DiagMessage() << "is RGB + alpha, using PNG_COLOR_TYPE_RGB_ALPHA");
break;
}
}
@@ -537,7 +532,7 @@
// base 9 patch data
if (kDebug) {
- diag->Note(DiagMessage() << "adding 9-patch info..");
+ diag->Note(android::DiagMessage() << "adding 9-patch info..");
}
memcpy((char*)unknowns[pIndex].name, "npTc", 5);
unknowns[pIndex].data = (png_byte*)info->serialize9Patch();
@@ -614,11 +609,10 @@
&interlaceType, &compressionType, nullptr);
if (kDebug) {
- diag->Note(DiagMessage() << "image written: w = " << width
- << ", h = " << height << ", d = " << bitDepth
- << ", colors = " << colorType
- << ", inter = " << interlaceType
- << ", comp = " << compressionType);
+ diag->Note(android::DiagMessage()
+ << "image written: w = " << width << ", h = " << height << ", d = " << bitDepth
+ << ", colors = " << colorType << ", inter = " << interlaceType
+ << ", comp = " << compressionType);
}
return true;
}
@@ -1232,20 +1226,20 @@
return true;
}
-bool Png::process(const Source& source, std::istream* input,
- BigBuffer* outBuffer, const PngOptions& options) {
+bool Png::process(const android::Source& source, std::istream* input, android::BigBuffer* outBuffer,
+ const PngOptions& options) {
TRACE_CALL();
png_byte signature[kPngSignatureSize];
// Read the PNG signature first.
if (!input->read(reinterpret_cast<char*>(signature), kPngSignatureSize)) {
- mDiag->Error(DiagMessage() << strerror(errno));
+ mDiag->Error(android::DiagMessage() << strerror(errno));
return false;
}
// If the PNG signature doesn't match, bail early.
if (png_sig_cmp(signature, 0, kPngSignatureSize) != 0) {
- mDiag->Error(DiagMessage() << "not a valid png file");
+ mDiag->Error(android::DiagMessage() << "not a valid png file");
return false;
}
@@ -1258,13 +1252,13 @@
readPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, nullptr, nullptr);
if (!readPtr) {
- mDiag->Error(DiagMessage() << "failed to allocate read ptr");
+ mDiag->Error(android::DiagMessage() << "failed to allocate read ptr");
goto bail;
}
infoPtr = png_create_info_struct(readPtr);
if (!infoPtr) {
- mDiag->Error(DiagMessage() << "failed to allocate info ptr");
+ mDiag->Error(android::DiagMessage() << "failed to allocate info ptr");
goto bail;
}
@@ -1281,7 +1275,7 @@
if (util::EndsWith(source.path, ".9.png")) {
std::string errorMsg;
if (!do9Patch(&pngInfo, &errorMsg)) {
- mDiag->Error(DiagMessage() << errorMsg);
+ mDiag->Error(android::DiagMessage() << errorMsg);
goto bail;
}
}
@@ -1289,13 +1283,13 @@
writePtr =
png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, nullptr, nullptr);
if (!writePtr) {
- mDiag->Error(DiagMessage() << "failed to allocate write ptr");
+ mDiag->Error(android::DiagMessage() << "failed to allocate write ptr");
goto bail;
}
writeInfoPtr = png_create_info_struct(writePtr);
if (!writeInfoPtr) {
- mDiag->Error(DiagMessage() << "failed to allocate write info ptr");
+ mDiag->Error(android::DiagMessage() << "failed to allocate write info ptr");
goto bail;
}
diff --git a/tools/aapt2/compile/Png.h b/tools/aapt2/compile/Png.h
index 7ca1f0e..7f8d923 100644
--- a/tools/aapt2/compile/Png.h
+++ b/tools/aapt2/compile/Png.h
@@ -21,13 +21,12 @@
#include <string>
#include "android-base/macros.h"
-
-#include "Diagnostics.h"
-#include "Source.h"
+#include "androidfw/BigBuffer.h"
+#include "androidfw/IDiagnostics.h"
+#include "androidfw/Source.h"
#include "compile/Image.h"
#include "io/Io.h"
#include "process/IResourceTableConsumer.h"
-#include "util/BigBuffer.h"
namespace aapt {
@@ -43,15 +42,16 @@
*/
class Png {
public:
- explicit Png(IDiagnostics* diag) : mDiag(diag) {}
+ explicit Png(android::IDiagnostics* diag) : mDiag(diag) {
+ }
- bool process(const Source& source, std::istream* input, BigBuffer* outBuffer,
+ bool process(const android::Source& source, std::istream* input, android::BigBuffer* outBuffer,
const PngOptions& options);
private:
DISALLOW_COPY_AND_ASSIGN(Png);
- IDiagnostics* mDiag;
+ android::IDiagnostics* mDiag;
};
/**
@@ -90,7 +90,8 @@
/**
* Reads a PNG from the InputStream into memory as an RGBA Image.
*/
-std::unique_ptr<Image> ReadPng(IAaptContext* context, const Source& source, io::InputStream* in);
+std::unique_ptr<Image> ReadPng(IAaptContext* context, const android::Source& source,
+ io::InputStream* in);
/**
* Writes the RGBA Image, with optional 9-patch meta-data, into the OutputStream
diff --git a/tools/aapt2/compile/PngCrunch.cpp b/tools/aapt2/compile/PngCrunch.cpp
index 1f4ea44d..4ef87ba 100644
--- a/tools/aapt2/compile/PngCrunch.cpp
+++ b/tools/aapt2/compile/PngCrunch.cpp
@@ -67,14 +67,14 @@
// Custom warning logging method that uses IDiagnostics.
static void LogWarning(png_structp png_ptr, png_const_charp warning_msg) {
- IDiagnostics* diag = (IDiagnostics*)png_get_error_ptr(png_ptr);
- diag->Warn(DiagMessage() << warning_msg);
+ android::IDiagnostics* diag = (android::IDiagnostics*)png_get_error_ptr(png_ptr);
+ diag->Warn(android::DiagMessage() << warning_msg);
}
// Custom error logging method that uses IDiagnostics.
static void LogError(png_structp png_ptr, png_const_charp error_msg) {
- IDiagnostics* diag = (IDiagnostics*)png_get_error_ptr(png_ptr);
- diag->Error(DiagMessage() << error_msg);
+ android::IDiagnostics* diag = (android::IDiagnostics*)png_get_error_ptr(png_ptr);
+ diag->Error(android::DiagMessage() << error_msg);
// Causes libpng to longjmp to the spot where setjmp was set. This is how libpng does
// error handling. If this custom error handler method were to return, libpng would, by
@@ -143,10 +143,11 @@
}
}
-std::unique_ptr<Image> ReadPng(IAaptContext* context, const Source& source, io::InputStream* in) {
+std::unique_ptr<Image> ReadPng(IAaptContext* context, const android::Source& source,
+ io::InputStream* in) {
TRACE_CALL();
// Create a diagnostics that has the source information encoded.
- SourcePathDiagnostics source_diag(source, context->GetDiagnostics());
+ android::SourcePathDiagnostics source_diag(source, context->GetDiagnostics());
// Read the first 8 bytes of the file looking for the PNG signature.
// Bail early if it does not match.
@@ -154,15 +155,16 @@
size_t buffer_size;
if (!in->Next((const void**)&signature, &buffer_size)) {
if (in->HadError()) {
- source_diag.Error(DiagMessage() << "failed to read PNG signature: " << in->GetError());
+ source_diag.Error(android::DiagMessage()
+ << "failed to read PNG signature: " << in->GetError());
} else {
- source_diag.Error(DiagMessage() << "not enough data for PNG signature");
+ source_diag.Error(android::DiagMessage() << "not enough data for PNG signature");
}
return {};
}
if (buffer_size < kPngSignatureSize || png_sig_cmp(signature, 0, kPngSignatureSize) != 0) {
- source_diag.Error(DiagMessage() << "file signature does not match PNG signature");
+ source_diag.Error(android::DiagMessage() << "file signature does not match PNG signature");
return {};
}
@@ -174,14 +176,14 @@
// version of libpng.
png_structp read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (read_ptr == nullptr) {
- source_diag.Error(DiagMessage() << "failed to create libpng read png_struct");
+ source_diag.Error(android::DiagMessage() << "failed to create libpng read png_struct");
return {};
}
// Create and initialize the memory for image header and data.
png_infop info_ptr = png_create_info_struct(read_ptr);
if (info_ptr == nullptr) {
- source_diag.Error(DiagMessage() << "failed to create libpng read png_info");
+ source_diag.Error(android::DiagMessage() << "failed to create libpng read png_info");
png_destroy_read_struct(&read_ptr, nullptr, nullptr);
return {};
}
@@ -254,7 +256,7 @@
// something
// that can always be represented by 9-patch.
if (width > std::numeric_limits<int32_t>::max() || height > std::numeric_limits<int32_t>::max()) {
- source_diag.Error(DiagMessage()
+ source_diag.Error(android::DiagMessage()
<< "PNG image dimensions are too large: " << width << "x" << height);
return {};
}
@@ -490,14 +492,16 @@
// version of libpng.
png_structp write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (write_ptr == nullptr) {
- context->GetDiagnostics()->Error(DiagMessage() << "failed to create libpng write png_struct");
+ context->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed to create libpng write png_struct");
return false;
}
// Allocate memory to store image header data.
png_infop write_info_ptr = png_create_info_struct(write_ptr);
if (write_info_ptr == nullptr) {
- context->GetDiagnostics()->Error(DiagMessage() << "failed to create libpng write png_info");
+ context->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed to create libpng write png_info");
png_destroy_write_struct(&write_ptr, nullptr);
return false;
}
@@ -575,7 +579,7 @@
}
if (context->IsVerbose()) {
- DiagMessage msg;
+ android::DiagMessage msg;
msg << " paletteSize=" << color_palette.size()
<< " alphaPaletteSize=" << alpha_palette.size()
<< " maxGrayDeviation=" << max_gray_deviation
@@ -590,7 +594,7 @@
nine_patch != nullptr, color_palette.size(), alpha_palette.size());
if (context->IsVerbose()) {
- DiagMessage msg;
+ android::DiagMessage msg;
msg << "encoding PNG ";
if (nine_patch) {
msg << "(with 9-patch) as ";
diff --git a/tools/aapt2/compile/PseudolocaleGenerator.cpp b/tools/aapt2/compile/PseudolocaleGenerator.cpp
index 2461438..09a8560 100644
--- a/tools/aapt2/compile/PseudolocaleGenerator.cpp
+++ b/tools/aapt2/compile/PseudolocaleGenerator.cpp
@@ -21,6 +21,7 @@
#include "ResourceTable.h"
#include "ResourceValues.h"
#include "ValueVisitor.h"
+#include "androidfw/Util.h"
#include "compile/Pseudolocalizer.h"
#include "util/Util.h"
@@ -53,7 +54,7 @@
return false;
}
-inline static UnifiedSpan SpanToUnifiedSpan(const StringPool::Span& span) {
+inline static UnifiedSpan SpanToUnifiedSpan(const android::StringPool::Span& span) {
return UnifiedSpan{*span.name, span.first_char, span.last_char};
}
@@ -111,7 +112,7 @@
std::unique_ptr<StyledString> PseudolocalizeStyledString(StyledString* string,
Pseudolocalizer::Method method,
- StringPool* pool) {
+ android::StringPool* pool) {
Pseudolocalizer localizer(method);
// Collect the spans and untranslatable sections into one set of spans, sorted by first_char.
@@ -121,7 +122,7 @@
// All Span indices are UTF-16 based, according to the resources.arsc format expected by the
// runtime. So we will do all our processing in UTF-16, then convert back.
- const std::u16string text16 = util::Utf8ToUtf16(string->value->value);
+ const std::u16string text16 = android::util::Utf8ToUtf16(string->value->value);
// Convenient wrapper around the text that allows us to work with StringPieces.
const StringPiece16 text(text16);
@@ -154,7 +155,7 @@
cursor += substr.size();
// Pseudolocalize the substring.
- std::string new_substr = util::Utf16ToUtf8(substr);
+ std::string new_substr = android::util::Utf16ToUtf8(substr);
if (translatable) {
new_substr = localizer.Text(new_substr);
}
@@ -181,7 +182,7 @@
cursor += substr.size();
// Pseudolocalize the substring.
- std::string new_substr = util::Utf16ToUtf8(substr);
+ std::string new_substr = android::util::Utf16ToUtf8(substr);
if (translatable) {
new_substr = localizer.Text(new_substr);
}
@@ -199,16 +200,18 @@
}
// Finish the pseudolocalization at the end of the string.
- new_string += localizer.Text(util::Utf16ToUtf8(text.substr(cursor, text.size() - cursor)));
+ new_string +=
+ localizer.Text(android::util::Utf16ToUtf8(text.substr(cursor, text.size() - cursor)));
new_string += localizer.End();
- StyleString localized;
+ android::StyleString localized;
localized.str = std::move(new_string);
// Convert the UnifiedSpans into regular Spans, skipping the UntranslatableSections.
for (UnifiedSpan& span : merged_spans) {
if (span.tag) {
- localized.spans.push_back(Span{std::move(span.tag.value()), span.first_char, span.last_char});
+ localized.spans.push_back(
+ android::Span{std::move(span.tag.value()), span.first_char, span.last_char});
}
}
return util::make_unique<StyledString>(pool->MakeRef(localized));
@@ -222,8 +225,9 @@
std::unique_ptr<Value> value;
std::unique_ptr<Item> item;
- Visitor(StringPool* pool, Pseudolocalizer::Method method)
- : pool_(pool), method_(method), localizer_(method) {}
+ Visitor(android::StringPool* pool, Pseudolocalizer::Method method)
+ : pool_(pool), method_(method), localizer_(method) {
+ }
void Visit(Plural* plural) override {
CloningValueTransformer cloner(pool_);
@@ -284,7 +288,7 @@
private:
DISALLOW_COPY_AND_ASSIGN(Visitor);
- StringPool* pool_;
+ android::StringPool* pool_;
Pseudolocalizer::Method method_;
Pseudolocalizer localizer_;
};
@@ -313,8 +317,8 @@
}
void PseudolocalizeIfNeeded(const Pseudolocalizer::Method method,
- ResourceConfigValue* original_value,
- StringPool* pool, ResourceEntry* entry) {
+ ResourceConfigValue* original_value, android::StringPool* pool,
+ ResourceEntry* entry) {
Visitor visitor(pool, method);
original_value->value->Accept(&visitor);
diff --git a/tools/aapt2/compile/PseudolocaleGenerator.h b/tools/aapt2/compile/PseudolocaleGenerator.h
index ace3786..44e6e3e 100644
--- a/tools/aapt2/compile/PseudolocaleGenerator.h
+++ b/tools/aapt2/compile/PseudolocaleGenerator.h
@@ -17,14 +17,15 @@
#ifndef AAPT_COMPILE_PSEUDOLOCALEGENERATOR_H
#define AAPT_COMPILE_PSEUDOLOCALEGENERATOR_H
-#include "StringPool.h"
+#include "androidfw/StringPool.h"
#include "compile/Pseudolocalizer.h"
#include "process/IResourceTableConsumer.h"
namespace aapt {
-std::unique_ptr<StyledString> PseudolocalizeStyledString(
- StyledString* string, Pseudolocalizer::Method method, StringPool* pool);
+std::unique_ptr<StyledString> PseudolocalizeStyledString(StyledString* string,
+ Pseudolocalizer::Method method,
+ android::StringPool* pool);
struct PseudolocaleGenerator : public IResourceTableConsumer {
bool Consume(IAaptContext* context, ResourceTable* table) override;
diff --git a/tools/aapt2/compile/PseudolocaleGenerator_test.cpp b/tools/aapt2/compile/PseudolocaleGenerator_test.cpp
index 432d7bf..2f90cbf 100644
--- a/tools/aapt2/compile/PseudolocaleGenerator_test.cpp
+++ b/tools/aapt2/compile/PseudolocaleGenerator_test.cpp
@@ -24,10 +24,11 @@
namespace aapt {
TEST(PseudolocaleGeneratorTest, PseudolocalizeStyledString) {
- StringPool pool;
- StyleString original_style;
+ android::StringPool pool;
+ android::StyleString original_style;
original_style.str = "Hello world!";
- original_style.spans = {Span{"i", 1, 10}, Span{"b", 2, 3}, Span{"b", 6, 7}};
+ original_style.spans = {android::Span{"i", 1, 10}, android::Span{"b", 2, 3},
+ android::Span{"b", 6, 7}};
std::unique_ptr<StyledString> new_string = PseudolocalizeStyledString(
util::make_unique<StyledString>(pool.MakeRef(original_style)).get(),
@@ -48,7 +49,7 @@
EXPECT_EQ(std::u16string(u"Hello ").size(), new_string->value->spans[2].first_char);
EXPECT_EQ(std::u16string(u"Hello w").size(), new_string->value->spans[2].last_char);
- original_style.spans.insert(original_style.spans.begin(), Span{"em", 0, 11u});
+ original_style.spans.insert(original_style.spans.begin(), android::Span{"em", 0, 11u});
new_string = PseudolocalizeStyledString(
util::make_unique<StyledString>(pool.MakeRef(original_style)).get(),
@@ -71,10 +72,10 @@
}
TEST(PseudolocaleGeneratorTest, PseudolocalizeAdjacentNestedTags) {
- StringPool pool;
- StyleString original_style;
+ android::StringPool pool;
+ android::StyleString original_style;
original_style.str = "bold";
- original_style.spans = {Span{"b", 0, 3}, Span{"i", 0, 3}};
+ original_style.spans = {android::Span{"b", 0, 3}, android::Span{"i", 0, 3}};
std::unique_ptr<StyledString> new_string = PseudolocalizeStyledString(
util::make_unique<StyledString>(pool.MakeRef(original_style)).get(),
@@ -93,10 +94,10 @@
}
TEST(PseudolocaleGeneratorTest, PseudolocalizeAdjacentTagsUnsorted) {
- StringPool pool;
- StyleString original_style;
+ android::StringPool pool;
+ android::StyleString original_style;
original_style.str = "bold";
- original_style.spans = {Span{"i", 2, 3}, Span{"b", 0, 1}};
+ original_style.spans = {android::Span{"i", 2, 3}, android::Span{"b", 0, 1}};
std::unique_ptr<StyledString> new_string = PseudolocalizeStyledString(
util::make_unique<StyledString>(pool.MakeRef(original_style)).get(),
@@ -115,11 +116,11 @@
}
TEST(PseudolocaleGeneratorTest, PseudolocalizeNestedAndAdjacentTags) {
- StringPool pool;
- StyleString original_style;
+ android::StringPool pool;
+ android::StyleString original_style;
original_style.str = "This sentence is not what you think it is at all.";
- original_style.spans = {Span{"b", 16u, 19u}, Span{"em", 29u, 47u}, Span{"i", 38u, 40u},
- Span{"b", 44u, 47u}};
+ original_style.spans = {android::Span{"b", 16u, 19u}, android::Span{"em", 29u, 47u},
+ android::Span{"i", 38u, 40u}, android::Span{"b", 44u, 47u}};
std::unique_ptr<StyledString> new_string = PseudolocalizeStyledString(
util::make_unique<StyledString>(pool.MakeRef(original_style)).get(),
@@ -154,10 +155,10 @@
}
TEST(PseudolocaleGeneratorTest, PseudolocalizePartsOfString) {
- StringPool pool;
- StyleString original_style;
+ android::StringPool pool;
+ android::StyleString original_style;
original_style.str = "This should NOT be pseudolocalized.";
- original_style.spans = {Span{"em", 4u, 14u}, Span{"i", 18u, 33u}};
+ original_style.spans = {android::Span{"em", 4u, 14u}, android::Span{"i", 18u, 33u}};
std::unique_ptr<StyledString> original_string =
util::make_unique<StyledString>(pool.MakeRef(original_style));
original_string->untranslatable_sections = {UntranslatableSection{11u, 15u}};
@@ -263,9 +264,10 @@
std::unique_ptr<ResourceTable> table = util::make_unique<ResourceTable>();
{
- StyleString original_style;
+ android::StyleString original_style;
original_style.str = "Hello world!";
- original_style.spans = {Span{"i", 1, 10}, Span{"b", 2, 3}, Span{"b", 6, 7}};
+ original_style.spans = {android::Span{"i", 1, 10}, android::Span{"b", 2, 3},
+ android::Span{"b", 6, 7}};
auto styled_string =
util::make_unique<StyledString>(table->string_pool.MakeRef(original_style));
diff --git a/tools/aapt2/compile/Pseudolocalizer.h b/tools/aapt2/compile/Pseudolocalizer.h
index 6cf003b..4dedc70 100644
--- a/tools/aapt2/compile/Pseudolocalizer.h
+++ b/tools/aapt2/compile/Pseudolocalizer.h
@@ -19,11 +19,10 @@
#include <memory>
+#include "ResourceValues.h"
#include "android-base/macros.h"
#include "androidfw/StringPiece.h"
-
-#include "ResourceValues.h"
-#include "StringPool.h"
+#include "androidfw/StringPool.h"
namespace aapt {
diff --git a/tools/aapt2/compile/XmlIdCollector.cpp b/tools/aapt2/compile/XmlIdCollector.cpp
index bb72159..68cb36a 100644
--- a/tools/aapt2/compile/XmlIdCollector.cpp
+++ b/tools/aapt2/compile/XmlIdCollector.cpp
@@ -38,8 +38,9 @@
using xml::Visitor::Visit;
explicit IdCollector(std::vector<SourcedResourceName>* out_symbols,
- SourcePathDiagnostics* source_diag) : out_symbols_(out_symbols),
- source_diag_(source_diag) {}
+ android::SourcePathDiagnostics* source_diag)
+ : out_symbols_(out_symbols), source_diag_(source_diag) {
+ }
void Visit(xml::Element* element) override {
for (xml::Attribute& attr : element->attributes) {
@@ -48,8 +49,8 @@
if (ResourceUtils::ParseReference(attr.value, &name, &create, nullptr)) {
if (create && name.type.type == ResourceType::kId) {
if (!text::IsValidResourceEntryName(name.entry)) {
- source_diag_->Error(DiagMessage(element->line_number)
- << "id '" << name << "' has an invalid entry name");
+ source_diag_->Error(android::DiagMessage(element->line_number)
+ << "id '" << name << "' has an invalid entry name");
} else {
auto iter = std::lower_bound(out_symbols_->begin(),
out_symbols_->end(), name, cmp_name);
@@ -67,7 +68,7 @@
private:
std::vector<SourcedResourceName>* out_symbols_;
- SourcePathDiagnostics* source_diag_;
+ android::SourcePathDiagnostics* source_diag_;
};
} // namespace
@@ -75,7 +76,7 @@
bool XmlIdCollector::Consume(IAaptContext* context, xml::XmlResource* xmlRes) {
TRACE_CALL();
xmlRes->file.exported_symbols.clear();
- SourcePathDiagnostics source_diag(xmlRes->file.source, context->GetDiagnostics());
+ android::SourcePathDiagnostics source_diag(xmlRes->file.source, context->GetDiagnostics());
IdCollector collector(&xmlRes->file.exported_symbols, &source_diag);
xmlRes->root->Accept(&collector);
return !source_diag.HadError();