cbb1e676b5
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
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#ifndef HOST_PSEUDOLOCALIZE_H
|
|
#define HOST_PSEUDOLOCALIZE_H
|
|
|
|
#include <base/macros.h>
|
|
#include "StringPool.h"
|
|
|
|
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;
|
|
};
|
|
|
|
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
|
|
|