CompositionUnderlineVectorBuilder::CompositionUnderlineVectorBuilder( const WebVector<WebCompositionUnderline>& underlines) { size_t size = underlines.size(); reserveCapacity(size); for (size_t i = 0; i < size; ++i) append(CompositionUnderlineBuilder(underlines[i])); }
void DataStore::setEntry(const fzStoreEntry& entry) { fzStoreEntry *current = entryForHash(entry.hash); removeEntry(current); reserveCapacity(m_num+1); p_store[m_num] = entry; ++m_num; m_dirty = true; }
void DataStore::readFromMemory() { FZ_ASSERT(p_path, "Path cannot be NULL."); if(m_dirty) return; fzBuffer buffer = IO::loadFile(p_path); if(!buffer.isEmpty()) { xml_document<> doc; doc.parse<parse_fastest | parse_validate_closing_tags>(buffer.getPointer()); xml_node<> *node = doc.first_node(); if(strncmp(node->name(), XML_SIZE_TAG, node->name_size()) != 0) FZ_RAISE("DataStore: XML is corrupted."); // RESERVE CAPACITY reserveCapacity(atoi(node->value())+1); // ITERATE XML m_num = 0; node = node->next_sibling(); for(; node; node = node->next_sibling()) { if(strncmp(node->name(), XML_ENTRY_TAG, node->name_size()) != 0) { FZLOGERROR("DataStore: XML entry is corrupted."); continue; } fzStoreEntry &entry = p_store[m_num]; // KEY xml_attribute<> *attribute = node->first_attribute(XML_KEY_ATTRIBUTE); if(attribute == NULL) { FZLOGERROR("DataStore: Key attribute is missing."); continue; } entry.key = fzStrcpy(attribute->value(), attribute->value_size()); entry.hash = fzHash(attribute->value(), attribute->value_size()); // ENTRY TYPE attribute = node->last_attribute(XML_TYPE_ATTRIBUTE); if(attribute == NULL) { FZLOGERROR("DataStore: Type attribute is missing."); continue; } int type = atoi(attribute->value()); // DATA const char *data = node->value(); if(data) { switch (type) { case kFZData_string: case kFZData_data: { fzBuffer decoded = Data::B64Decode(data, node->value_size()); entry.data = decoded; break; } case kFZData_integer: entry.integerValue = atoi(data); break; case kFZData_float: entry.floatValue = atof(data); break; default: FZ_RAISE("DataStore: Entry type is invalid."); break; } } entry.type = static_cast<unsigned char>(type); ++m_num; } buffer.free(); FZ_ASSERT(m_num <= m_capacity, "Memory overflow."); } }