bool pt_PieceTable::_insertObject(pf_Frag * pf, PT_BlockOffset fragOffset, PTObjectType pto, PT_AttrPropIndex indexAP, pf_Frag_Object * & pfo) { pfo = NULL; if (!_createObject(pto,indexAP,&pfo)) return false; pfo->setXID(getXID()); if (fragOffset == 0) { // we are at the beginning of a fragment, insert the // new object immediately prior to it. m_fragments.insertFrag(pf->getPrev(),pfo); } else if (fragOffset == pf->getLength()) { // we are at the end of a fragment, insert the new // object immediately after it. m_fragments.insertFrag(pf,pfo); } else { // if the insert is in the middle of the (text) fragment, we // split the current fragment and insert the object between // them. UT_return_val_if_fail (pf->getType() == pf_Frag::PFT_Text, false); pf_Frag_Text * pft = static_cast<pf_Frag_Text *>(pf); UT_uint32 lenTail = pft->getLength() - fragOffset; PT_BufIndex biTail = m_varset.getBufIndex(pft->getBufIndex(),fragOffset); pf_Frag_Text * pftTail = new pf_Frag_Text(this,biTail,lenTail,pft->getIndexAP(),pft->getField()); if (!pftTail) goto MemoryError; pft->changeLength(fragOffset); m_fragments.insertFrag(pft,pfo); m_fragments.insertFrag(pfo,pftTail); } return true; MemoryError: if (pfo) delete pfo; return false; }
bool pt_PieceTable::_makeObject(PTObjectType pto, const gchar ** attributes, pf_Frag_Object * &pfo) { // create a new object fragment at the current end of the document. // this function can only be called while loading the document. UT_return_val_if_fail (m_pts==PTS_Loading, false); // Only a strux can be appended to an empty document UT_return_val_if_fail (NULL != m_fragments.getFirst(), false); // first, store the attributes and properties and get an index to them. PT_AttrPropIndex indexAP; if (!m_varset.storeAP(attributes,&indexAP)) return false; if (!_createObject(pto,indexAP,&pfo)) return false; return true; }