]>
git.saurik.com Git - android/aapt.git/blob - StringPool.h
2 // Copyright 2006 The Android Open Source Project
4 // Build resource files from raw assets.
11 #include "AaptAssets.h"
13 #include <utils/ResourceTypes.h>
14 #include <utils/String16.h>
15 #include <utils/TextOutput.h>
17 #include <sys/types.h>
25 using namespace android
;
27 #define PRINT_STRING_METRICS 0
29 void strcpy16_htod(uint16_t* dst
, const uint16_t* src
);
31 void printStringPool(const ResStringPool
* pool
);
34 * The StringPool class is used as an intermediate representation for
35 * generating the string pool resource data structure that can be parsed with
36 * ResStringPool in include/utils/ResourceTypes.h.
42 entry() : offset(0) { }
43 entry(const String16
& _value
) : value(_value
), offset(0) { }
44 entry(const entry
& o
) : value(o
.value
), offset(o
.offset
), indices(o
.indices
) { }
48 Vector
<size_t> indices
;
51 struct entry_style_span
{
53 ResStringPool_span span
;
57 entry_style() : offset(0) { }
59 entry_style(const entry_style
& o
) : offset(o
.offset
), spans(o
.spans
) { }
62 Vector
<entry_style_span
> spans
;
66 * If 'sorted' is true, then the final strings in the resource data
67 * structure will be generated in sorted order. This allow for fast
68 * lookup with ResStringPool::indexOfString() (O(log n)), at the expense
69 * of support for styled string entries (which requires the same string
70 * be included multiple times in the pool).
72 explicit StringPool(bool sorted
= false);
75 * Add a new string to the pool. If mergeDuplicates is true, thenif
76 * the string already exists the existing entry for it will be used;
77 * otherwise, or if the value doesn't already exist, a new entry is
80 * Returns the index in the entry array of the new string entry. Note that
81 * if this string pool is sorted, the returned index will not be valid
82 * when the pool is finally written.
84 ssize_t
add(const String16
& value
, bool mergeDuplicates
= false);
86 ssize_t
add(const String16
& value
, const Vector
<entry_style_span
>& spans
);
88 ssize_t
add(const String16
& ident
, const String16
& value
,
89 bool mergeDuplicates
= false);
91 status_t
addStyleSpan(size_t idx
, const String16
& name
,
92 uint32_t start
, uint32_t end
);
93 status_t
addStyleSpans(size_t idx
, const Vector
<entry_style_span
>& spans
);
94 status_t
addStyleSpan(size_t idx
, const entry_style_span
& span
);
98 const entry
& entryAt(size_t idx
) const;
100 size_t countIdentifiers() const;
102 sp
<AaptFile
> createStringBlock();
104 status_t
writeStringBlock(const sp
<AaptFile
>& pool
);
107 * Find out an offset in the pool for a particular string. If the string
108 * pool is sorted, this can not be called until after createStringBlock()
109 * or writeStringBlock() has been called
110 * (which determines the offsets). In the case of a string that appears
111 * multiple times in the pool, the first offset will be returned. Returns
112 * -1 if the string does not exist.
114 ssize_t
offsetForString(const String16
& val
) const;
117 * Find all of the offsets in the pool for a particular string. If the
118 * string pool is sorted, this can not be called until after
119 * createStringBlock() or writeStringBlock() has been called
120 * (which determines the offsets). Returns NULL if the string does not exist.
122 const Vector
<size_t>* offsetsForString(const String16
& val
) const;
126 // Raw array of unique strings, in some arbitrary order.
127 Vector
<entry
> mEntries
;
128 // Array of indices into mEntries, in the order they were
129 // added to the pool. This can be different than mEntries
130 // if the same string was added multiple times (it will appear
131 // once in mEntries, with multiple occurrences in this array).
132 Vector
<size_t> mEntryArray
;
133 // Optional style span information associated with each index of
135 Vector
<entry_style
> mEntryStyleArray
;
136 // Mapping from indices in mEntryArray to indices in mValues.
137 Vector
<size_t> mEntryArrayToValues
;
138 // Unique set of all the strings added to the pool, mapped to
139 // the first index of mEntryArray where the value was added.
140 DefaultKeyedVector
<String16
, ssize_t
> mValues
;
141 // Unique set of all (optional) identifiers of strings in the
142 // pool, mapping to indices in mEntries.
143 DefaultKeyedVector
<String16
, ssize_t
> mIdents
;