]>
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      * If 'utf8' is true, strings will be encoded with UTF-8 instead of 
  73      * left in Java's native UTF-16. 
  75     explicit StringPool(bool sorted 
= false, bool utf8 
= false); 
  78      * Add a new string to the pool.  If mergeDuplicates is true, thenif 
  79      * the string already exists the existing entry for it will be used; 
  80      * otherwise, or if the value doesn't already exist, a new entry is 
  83      * Returns the index in the entry array of the new string entry.  Note that 
  84      * if this string pool is sorted, the returned index will not be valid 
  85      * when the pool is finally written. 
  87     ssize_t 
add(const String16
& value
, bool mergeDuplicates 
= false); 
  89     ssize_t 
add(const String16
& value
, const Vector
<entry_style_span
>& spans
); 
  91     ssize_t 
add(const String16
& ident
, const String16
& value
, 
  92                 bool mergeDuplicates 
= false); 
  94     status_t 
addStyleSpan(size_t idx
, const String16
& name
, 
  95                           uint32_t start
, uint32_t end
); 
  96     status_t 
addStyleSpans(size_t idx
, const Vector
<entry_style_span
>& spans
); 
  97     status_t 
addStyleSpan(size_t idx
, const entry_style_span
& span
); 
 101     const entry
& entryAt(size_t idx
) const; 
 103     size_t countIdentifiers() const; 
 105     sp
<AaptFile
> createStringBlock(); 
 107     status_t 
writeStringBlock(const sp
<AaptFile
>& pool
); 
 110      * Find out an offset in the pool for a particular string.  If the string 
 111      * pool is sorted, this can not be called until after createStringBlock() 
 112      * or writeStringBlock() has been called 
 113      * (which determines the offsets).  In the case of a string that appears 
 114      * multiple times in the pool, the first offset will be returned.  Returns 
 115      * -1 if the string does not exist. 
 117     ssize_t 
offsetForString(const String16
& val
) const; 
 120      * Find all of the offsets in the pool for a particular string.  If the 
 121      * string pool is sorted, this can not be called until after 
 122      * createStringBlock() or writeStringBlock() has been called 
 123      * (which determines the offsets).  Returns NULL if the string does not exist. 
 125     const Vector
<size_t>* offsetsForString(const String16
& val
) const; 
 130     // Raw array of unique strings, in some arbitrary order. 
 131     Vector
<entry
>                           mEntries
; 
 132     // Array of indices into mEntries, in the order they were 
 133     // added to the pool.  This can be different than mEntries 
 134     // if the same string was added multiple times (it will appear 
 135     // once in mEntries, with multiple occurrences in this array). 
 136     Vector
<size_t>                          mEntryArray
; 
 137     // Optional style span information associated with each index of 
 139     Vector
<entry_style
>                     mEntryStyleArray
; 
 140     // Mapping from indices in mEntryArray to indices in mValues. 
 141     Vector
<size_t>                          mEntryArrayToValues
; 
 142     // Unique set of all the strings added to the pool, mapped to 
 143     // the first index of mEntryArray where the value was added. 
 144     DefaultKeyedVector
<String16
, ssize_t
>   mValues
; 
 145     // Unique set of all (optional) identifiers of strings in the 
 146     // pool, mapping to indices in mEntries. 
 147     DefaultKeyedVector
<String16
, ssize_t
>   mIdents
;