MCPcopy Create free account
hub / github.com/CyanogenMod/android_frameworks_base / writeStringBlock

Method writeStringBlock

tools/aapt/StringPool.cpp:363–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361}
362
363status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
364{
365 // Allow appending. Sorry this is a little wacky.
366 if (pool->getSize() > 0) {
367 sp<AaptFile> block = createStringBlock();
368 if (block == NULL) {
369 return UNKNOWN_ERROR;
370 }
371 ssize_t res = pool->writeData(block->getData(), block->getSize());
372 return (res >= 0) ? (status_t)NO_ERROR : res;
373 }
374
375 // First we need to add all style span names to the string pool.
376 // We do this now (instead of when the span is added) so that these
377 // will appear at the end of the pool, not disrupting the order
378 // our client placed their own strings in it.
379
380 const size_t STYLES = mEntryStyleArray.size();
381 size_t i;
382
383 for (i=0; i<STYLES; i++) {
384 entry_style& style = mEntryStyleArray.editItemAt(i);
385 const size_t N = style.spans.size();
386 for (size_t i=0; i<N; i++) {
387 entry_style_span& span = style.spans.editItemAt(i);
388 ssize_t idx = add(span.name, true);
389 if (idx < 0) {
390 fprintf(stderr, "Error adding span for style tag '%s'\n",
391 String8(span.name).string());
392 return idx;
393 }
394 span.span.name.index = (uint32_t)idx;
395 }
396 }
397
398 const size_t ENTRIES = mEntryArray.size();
399
400 // Now build the pool of unique strings.
401
402 const size_t STRINGS = mEntries.size();
403 const size_t preSize = sizeof(ResStringPool_header)
404 + (sizeof(uint32_t)*ENTRIES)
405 + (sizeof(uint32_t)*STYLES);
406 if (pool->editData(preSize) == NULL) {
407 fprintf(stderr, "ERROR: Out of memory for string pool\n");
408 return NO_MEMORY;
409 }
410
411 const size_t charSize = mUTF8 ? sizeof(uint8_t) : sizeof(char16_t);
412
413 size_t strPos = 0;
414 for (i=0; i<STRINGS; i++) {
415 entry& ent = mEntries.editItemAt(i);
416 const size_t strSize = (ent.value.size());
417 const size_t lenSize = strSize > (size_t)(1<<((charSize*8)-1))-1 ?
418 charSize*2 : charSize;
419
420 String8 encStr;

Callers 1

flattenMethod · 0.80

Calls 8

strcpy16_htodFunction · 0.85
writeDataMethod · 0.80
stringMethod · 0.80
editDataMethod · 0.80
padDataMethod · 0.80
getSizeMethod · 0.65
sizeMethod · 0.65
getDataMethod · 0.45

Tested by

no test coverage detected