ICU format support for pseudolocalizes.
Custom parser can handle nested ICU messages even if they
are split into multiple fragments. Code reworked to encapsulate
all pseudolocalization logic in Pseudolocalizer and PseudoMethods
classes. To minimize a changelist size, some static functions
remained. Fake BiDi pseudolocalization method is reimplemented
to handle word boundaries correctly. Unit tests added.
Change-Id: I9fb4baf4e3123df5dd6d182cca02bb7b0489ca71
diff --git a/tools/aapt/pseudolocalize.h b/tools/aapt/pseudolocalize.h
index e6ab18e..71b974b 100644
--- a/tools/aapt/pseudolocalize.h
+++ b/tools/aapt/pseudolocalize.h
@@ -1,18 +1,58 @@
#ifndef HOST_PSEUDOLOCALIZE_H
#define HOST_PSEUDOLOCALIZE_H
+#include <base/macros.h>
#include "StringPool.h"
-#include <string>
+class PseudoMethodImpl {
+ public:
+ virtual ~PseudoMethodImpl() {}
+ virtual String16 start() { return String16(); }
+ virtual String16 end() { return String16(); }
+ virtual String16 text(const String16& text) = 0;
+ virtual String16 placeholder(const String16& text) = 0;
+};
-String16 pseudolocalize_string(const String16& source);
-// Surrounds every word in the sentance with specific characters that makes
-// the word directionality RTL.
-String16 pseudobidi_string(const String16& source);
-// Generates expansion string based on the specified lenght.
-// Generated string could not be shorter that length, but it could be slightly
-// longer.
-String16 pseudo_generate_expansion(const unsigned int length);
+class PseudoMethodNone : public PseudoMethodImpl {
+ public:
+ PseudoMethodNone() {}
+ String16 text(const String16& text) { return text; }
+ String16 placeholder(const String16& text) { return text; }
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PseudoMethodNone);
+};
+
+class PseudoMethodBidi : public PseudoMethodImpl {
+ public:
+ String16 text(const String16& text);
+ String16 placeholder(const String16& text);
+};
+
+class PseudoMethodAccent : public PseudoMethodImpl {
+ public:
+ PseudoMethodAccent() : mDepth(0), mWordCount(0), mLength(0) {}
+ String16 start();
+ String16 end();
+ String16 text(const String16& text);
+ String16 placeholder(const String16& text);
+ private:
+ size_t mDepth;
+ size_t mWordCount;
+ size_t mLength;
+};
+
+class Pseudolocalizer {
+ public:
+ Pseudolocalizer(PseudolocalizationMethod m);
+ ~Pseudolocalizer() { if (mImpl) delete mImpl; }
+ void setMethod(PseudolocalizationMethod m);
+ String16 start() { return mImpl->start(); }
+ String16 end() { return mImpl->end(); }
+ String16 text(const String16& text);
+ private:
+ PseudoMethodImpl *mImpl;
+ size_t mLastDepth;
+};
#endif // HOST_PSEUDOLOCALIZE_H