| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#ifndef STRING_POOL_H |
| 8 |
#define STRING_POOL_H |
| 9 |
|
| 10 |
#include "Main.h" |
| 11 |
#include "AaptAssets.h" |
| 12 |
|
| 13 |
#include <androidfw/ResourceTypes.h> |
| 14 |
#include <utils/String16.h> |
| 15 |
|
| 16 |
#include <sys/types.h> |
| 17 |
#include <sys/stat.h> |
| 18 |
#include <fcntl.h> |
| 19 |
#include <ctype.h> |
| 20 |
#include <errno.h> |
| 21 |
|
| 22 |
using namespace android; |
| 23 |
|
| 24 |
#define PRINT_STRING_METRICS 0 |
| 25 |
|
| 26 |
#if __cplusplus >= 201103L |
| 27 |
void strcpy16_htod(char16_t* dst, const char16_t* src); |
| 28 |
#endif |
| 29 |
void strcpy16_htod(uint16_t* dst, const char16_t* src); |
| 30 |
|
| 31 |
void printStringPool(const ResStringPool* pool); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class StringPool |
| 39 |
{ |
| 40 |
public: |
| 41 |
struct entry { |
| 42 |
entry() : offset(0) { } |
| 43 |
explicit entry(const String16& _value) : value(_value), offset(0), hasStyles(false) { } |
| 44 |
entry(const entry& o) : value(o.value), offset(o.offset), |
| 45 |
hasStyles(o.hasStyles), indices(o.indices), |
| 46 |
configTypeName(o.configTypeName), configs(o.configs) { } |
| 47 |
|
| 48 |
String16 value; |
| 49 |
size_t offset; |
| 50 |
bool hasStyles; |
| 51 |
Vector<size_t> indices; |
| 52 |
String8 configTypeName; |
| 53 |
Vector<ResTable_config> configs; |
| 54 |
|
| 55 |
String8 makeConfigsString() const; |
| 56 |
|
| 57 |
int compare(const entry& o) const; |
| 58 |
|
| 59 |
inline bool operator<(const entry& o) const { return compare(o) < 0; } |
| 60 |
inline bool operator<=(const entry& o) const { return compare(o) <= 0; } |
| 61 |
inline bool operator==(const entry& o) const { return compare(o) == 0; } |
| 62 |
inline bool operator!=(const entry& o) const { return compare(o) != 0; } |
| 63 |
inline bool operator>=(const entry& o) const { return compare(o) >= 0; } |
| 64 |
inline bool operator>(const entry& o) const { return compare(o) > 0; } |
| 65 |
}; |
| 66 |
|
| 67 |
struct entry_style_span { |
| 68 |
String16 name; |
| 69 |
ResStringPool_span span; |
| 70 |
}; |
| 71 |
|
| 72 |
struct entry_style { |
| 73 |
entry_style() : offset(0) { } |
| 74 |
|
| 75 |
entry_style(const entry_style& o) : offset(o.offset), spans(o.spans) { } |
| 76 |
|
| 77 |
size_t offset; |
| 78 |
Vector<entry_style_span> spans; |
| 79 |
}; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
explicit StringPool(bool utf8 = false); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ssize_t add(const String16& value, bool mergeDuplicates = false, |
| 96 |
const String8* configTypeName = NULL, const ResTable_config* config = NULL); |
| 97 |
|
| 98 |
ssize_t add(const String16& value, const Vector<entry_style_span>& spans, |
| 99 |
const String8* configTypeName = NULL, const ResTable_config* config = NULL); |
| 100 |
|
| 101 |
status_t addStyleSpan(size_t idx, const String16& name, |
| 102 |
uint32_t start, uint32_t end); |
| 103 |
status_t addStyleSpans(size_t idx, const Vector<entry_style_span>& spans); |
| 104 |
status_t addStyleSpan(size_t idx, const entry_style_span& span); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
void sortByConfig(); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
size_t mapOriginalPosToNewPos(size_t originalPos) const { |
| 115 |
return mOriginalPosToNewPos.itemAt(originalPos); |
| 116 |
} |
| 117 |
|
| 118 |
sp<AaptFile> createStringBlock(); |
| 119 |
|
| 120 |
status_t writeStringBlock(const sp<AaptFile>& pool); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
ssize_t offsetForString(const String16& val) const; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
const Vector<size_t>* offsetsForString(const String16& val) const; |
| 139 |
|
| 140 |
private: |
| 141 |
class ConfigSorter |
| 142 |
{ |
| 143 |
public: |
| 144 |
explicit ConfigSorter(const StringPool&); |
| 145 |
bool operator()(size_t l, size_t r); |
| 146 |
private: |
| 147 |
const StringPool& pool; |
| 148 |
}; |
| 149 |
|
| 150 |
const bool mUTF8; |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
Vector<entry> mEntries; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
Vector<size_t> mEntryArray; |
| 166 |
|
| 167 |
|
| 168 |
Vector<entry_style> mEntryStyleArray; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
DefaultKeyedVector<String16, ssize_t> mValues; |
| 176 |
|
| 177 |
|
| 178 |
Vector<size_t> mOriginalPosToNewPos; |
| 179 |
}; |
| 180 |
|
| 181 |
#endif |
| 182 |
|