/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter UniSharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

const Utils = require("./../../../unisharp/Utils");

const UnitextItem = require("./../../UnitextItem");
const UnitextNewline = require("./../../UnitextNewline");
const UnitextTablecell = require("./../../UnitextTablecell");
const UnitextPlaintext = require("./../../UnitextPlaintext");
const UnitextComment = require("./../../UnitextComment");
const UnitextContainer = require("./../../UnitextContainer");
const UnitextList = require("./../../UnitextList");
const UnitextListitem = require("./../../UnitextListitem");
const UnitextHyperlink = require("./../../UnitextHyperlink");
const UnitextDocblock = require("./../../UnitextDocblock");
const UnitextFootnote = require("./../../UnitextFootnote");
const UnitextContainerType = require("./../../UnitextContainerType");
const UnitextTable = require("./../../UnitextTable");

class UnitextImplantateHelper {
    
    static clear(content, id, typeName, cntTyp, own, cou) {
        let tab = Utils.as(content, UnitextTable);
        if (tab !== null) {
            for (let r = 0; r < tab.rowsCount; r++) {
                for (let c = 0; c < tab.colsCount; c++) {
                    let cel = tab.getCell(r, c);
                    if (cel !== null && cel.content !== null) 
                        cel.content = UnitextImplantateHelper.clear(cel.content, id, typeName, cntTyp, null, cou);
                }
            }
            return tab;
        }
        let li = Utils.as(content, UnitextList);
        if (li !== null) {
            for (const l of li.items) {
                if (l.prefix !== null) 
                    l.prefix = UnitextImplantateHelper.clear(l.prefix, id, typeName, cntTyp, null, cou);
                if (l.content !== null) 
                    l.content = UnitextImplantateHelper.clear(l.content, id, typeName, cntTyp, null, cou);
                if (l.sublist !== null) 
                    UnitextImplantateHelper.clear(l.sublist, id, typeName, cntTyp, null, cou);
            }
            return li;
        }
        let foot = Utils.as(content, UnitextFootnote);
        if (foot !== null) {
            if (foot.content !== null) 
                foot.content = UnitextImplantateHelper.clear(foot.content, id, typeName, cntTyp, null, cou);
            return foot;
        }
        let hyp = Utils.as(content, UnitextHyperlink);
        if (hyp !== null) {
            if (hyp.content !== null) 
                hyp.content = UnitextImplantateHelper.clear(hyp.content, id, typeName, cntTyp, null, cou);
            return hyp;
        }
        let dbl = Utils.as(content, UnitextDocblock);
        if (dbl !== null) {
            if (dbl.head !== null) 
                dbl.head = Utils.as(UnitextImplantateHelper.clear(dbl.head, id, typeName, cntTyp, null, cou), UnitextContainer);
            if (dbl.body !== null) 
                dbl.body = UnitextImplantateHelper.clear(dbl.body, id, typeName, cntTyp, null, cou);
            if (dbl.tail !== null) 
                dbl.tail = Utils.as(UnitextImplantateHelper.clear(dbl.tail, id, typeName, cntTyp, null, cou), UnitextContainer);
            if (dbl.appendix !== null) 
                dbl.appendix = Utils.as(UnitextImplantateHelper.clear(dbl.appendix, id, typeName, cntTyp, null, cou), UnitextContainer);
            return dbl;
        }
        let cnt = Utils.as(content, UnitextContainer);
        if (cnt === null) 
            return content;
        for (let i = 0; i < cnt.children.length; i++) {
            let cc = UnitextImplantateHelper.clear(cnt.children[i], id, typeName, cntTyp, cnt, cou);
            if (cc === null) {
            }
            if (cc === cnt.children[i] && (cc instanceof UnitextContainer) && cc.children.length === 0) {
                if (typeName !== null) {
                }
                else if (id !== null) {
                    if (cc.id !== id) 
                        continue;
                }
                cnt.children.splice(i, 1);
                i--;
            }
            else 
                cnt.children[i] = cc;
        }
        if (id !== null) {
            if (cnt.id !== id) 
                return content;
        }
        if (cnt.children.length === 0) 
            return content;
        if (cnt.children.length === 1) {
            cnt.children[0].parent = cnt.parent;
            return cnt.children[0];
        }
        if (own === null) 
            return content;
        let ii = own.getChildIndexOf(cnt);
        if (ii < 0) 
            return content;
        own.children.splice(ii, 1);
        own.children.splice(ii, 0, ...cnt.children);
        for (const ch of own.children) {
            ch.parent = own;
        }
        cou.value++;
        return own.children[ii];
    }
    
    static _splitTexts(content, begin, end, own, lev) {
        if (content === null) 
            return null;
        if (lev > 30) 
            return content;
        if (end < content.beginChar) 
            return content;
        if (begin > content.endChar) 
            return content;
        if (begin <= content.beginChar && end >= content.endChar) 
            return content;
        let tab = Utils.as(content, UnitextTable);
        if (tab !== null) {
            let cel = tab._findCellByPos(begin);
            if (cel !== null && cel.content !== null) 
                cel.content = UnitextImplantateHelper._splitTexts(cel.content, begin, end, null, lev + 1);
            return tab;
        }
        let li = Utils.as(content, UnitextList);
        if (li !== null) {
            for (const l of li.items) {
                if (l.prefix !== null) 
                    l.prefix = UnitextImplantateHelper._splitTexts(l.prefix, begin, end, null, lev + 1);
                if (l.content !== null) 
                    l.content = UnitextImplantateHelper._splitTexts(l.content, begin, end, null, lev + 1);
                if (l.sublist !== null) 
                    UnitextImplantateHelper._splitTexts(l.sublist, begin, end, null, lev + 1);
            }
            return li;
        }
        let foot = Utils.as(content, UnitextFootnote);
        if (foot !== null) {
            if (foot.content !== null) 
                foot.content = UnitextImplantateHelper._splitTexts(foot.content, begin, end, null, lev + 1);
            return foot;
        }
        let hyp = Utils.as(content, UnitextHyperlink);
        if (hyp !== null) {
            if (hyp.content !== null) 
                hyp.content = UnitextImplantateHelper._splitTexts(hyp.content, begin, end, null, lev + 1);
            return hyp;
        }
        let dbl = Utils.as(content, UnitextDocblock);
        if (dbl !== null) {
            if (dbl.head !== null) {
                let hh = Utils.as(UnitextImplantateHelper._splitTexts(dbl.head, begin, end, null, lev + 1), UnitextContainer);
                if (hh.children.includes(dbl)) {
                }
                dbl.head = hh;
            }
            if (dbl.body !== null) 
                dbl.body = UnitextImplantateHelper._splitTexts(dbl.body, begin, end, null, lev + 1);
            if (dbl.tail !== null) 
                dbl.tail = Utils.as(UnitextImplantateHelper._splitTexts(dbl.tail, begin, end, null, lev + 1), UnitextContainer);
            if (dbl.appendix !== null) 
                dbl.appendix = UnitextImplantateHelper._splitTexts(dbl.appendix, begin, end, null, lev + 1);
            return dbl;
        }
        let cnt = Utils.as(content, UnitextContainer);
        if (cnt !== null) {
            for (let i = 0; i < cnt.children.length; i++) {
                let ch = cnt.children[i];
                if ((ch.endChar < begin) || ch.endChar === 0) 
                    continue;
                if (ch.beginChar > end) {
                    if (end === (begin - 1) && ch.beginChar <= begin) {
                    }
                    else 
                        break;
                }
                let cc = UnitextImplantateHelper._splitTexts(ch, begin, end, cnt, lev + 1);
                if (cc === null) {
                }
                else 
                    cc.parent = cnt;
                cnt.children[i] = cc;
            }
            return content;
        }
        let txt = Utils.as(content, UnitextPlaintext);
        if (txt !== null) {
            if (begin === txt.beginChar && end === txt.endChar) 
                return txt;
            let creat = false;
            if (own === null) {
                own = UnitextContainer._new401(txt.parent, txt.beginChar, txt.endChar, ("cnt0_" + txt.beginChar + "_" + txt.endChar));
                own.children.push(txt);
                creat = true;
            }
            let ii = own.getChildIndexOf(content);
            if (ii < 0) 
                return content;
            let jj = ii;
            own.children.splice(ii, 1);
            if (begin > txt.beginChar) {
                let b = txt.removeStart(begin - txt.beginChar);
                if (b !== null) {
                    own.children.splice(jj, 0, b);
                    jj++;
                }
            }
            if (end < txt.endChar) {
                let e = txt.removeEnd(txt.endChar - end);
                if (e !== null) 
                    own.children.splice(jj, 0, e);
            }
            own.children.splice(jj, 0, txt);
            txt.parent = own;
            if (creat) 
                return own;
            else 
                return own.children[ii];
        }
        return content;
    }
    
    static implantate(content, impl, text, own = null) {
        if (content === null || content === impl) 
            return content;
        if (impl.endChar < content.beginChar) 
            return content;
        if (impl.beginChar > content.endChar) 
            return content;
        if (impl.parent !== null) 
            return content;
        if ((impl.beginChar === content.beginChar && impl.endChar === content.endChar && own === null) && !(content instanceof UnitextContainer)) {
            impl.parent = content.parent;
            impl.children.push(content);
            content.parent = impl;
            return impl;
        }
        if (impl.beginChar === 0 && impl.endChar === 0 && (content instanceof UnitextContainer)) {
            let cnt1 = Utils.as(content, UnitextContainer);
            let i = 0;
            for (i = 0; i < cnt1.children.length; i++) {
                if (cnt1.children[i].endChar > 0) 
                    break;
            }
            impl.parent = cnt1;
            cnt1.children.splice(i, 0, impl);
            return impl;
        }
        content = UnitextImplantateHelper._splitTexts(content, impl.beginChar, impl.endChar, own, 0);
        if (content === null) 
            return null;
        if (content === impl) 
            return content;
        if (impl.beginChar <= content.getPlaintextNsPos(text) && content.getPlaintextNsPos1(text) <= impl.endChar) {
            if ((content instanceof UnitextDocblock) && Utils.compareStrings((content.typname != null ? content.typname : ""), "Footnote", true) === 0) {
                let db = Utils.as(content, UnitextDocblock);
                if (db.body !== null) {
                    db.body = UnitextImplantateHelper.implantate(db.body, impl, text, null);
                    return db.body;
                }
            }
            if (((impl.typ === UnitextContainerType.NUMBER || impl.typ === UnitextContainerType.NAME)) && (content instanceof UnitextContainer) && content.typ === UnitextContainerType.HEAD) {
                for (const ch of content.children) {
                    ch.parent = impl;
                    impl.children.push(ch);
                }
                impl.parent = content.parent;
            }
            else {
                let cnt1 = Utils.as(content, UnitextContainer);
                if (cnt1 !== null) {
                    for (let i = 0; i < cnt1.children.length; i++) {
                        let ch = cnt1.children[i];
                        if (ch.endChar === 0) 
                            continue;
                        if (ch.beginChar <= impl.beginChar && impl.endChar <= ch.endChar) {
                            let ch1 = UnitextImplantateHelper.implantate(ch, impl, text, null);
                            if (ch1 === null) 
                                return null;
                            cnt1.children[i] = ch1;
                            ch1.parent = cnt1;
                            return content;
                        }
                    }
                }
                impl.children.push(content);
                impl.parent = content.parent;
                content.parent = impl;
            }
            if (impl.endChar > content.endChar || (impl.beginChar < content.beginChar)) {
                impl.beginChar = content.beginChar;
                impl.endChar = content.endChar;
            }
            if (own !== null) {
                let ii = own.getChildIndexOf(content);
                if (ii >= 0) {
                    own.children[ii] = impl;
                    impl.parent = own;
                }
                else 
                    return content;
            }
            return impl;
        }
        let tab = Utils.as(content, UnitextTable);
        if (tab !== null) {
            let cel = tab._findCellByPos(impl.beginChar);
            if (cel !== null) {
                if (cel.content !== null) 
                    cel.content = UnitextImplantateHelper.implantate(cel.content, impl, text, null);
                else {
                    cel.content = impl;
                    impl.parent = cel;
                }
            }
            return tab;
        }
        let li = Utils.as(content, UnitextList);
        if (li !== null) {
            for (const l of li.items) {
                if (l.beginChar <= impl.beginChar && impl.beginChar <= l.endChar) {
                    if (l.prefix !== null && impl.parent === null) 
                        l.prefix = UnitextImplantateHelper.implantate(l.prefix, impl, text, null);
                    if (l.content !== null && impl.parent === null) 
                        l.content = UnitextImplantateHelper.implantate(l.content, impl, text, null);
                    if (l.sublist !== null && impl.parent === null) 
                        UnitextImplantateHelper.implantate(l.sublist, impl, text, null);
                }
            }
            return li;
        }
        let foot = Utils.as(content, UnitextFootnote);
        if (foot !== null) {
            if (foot.content !== null) 
                foot.content = UnitextImplantateHelper.implantate(foot.content, impl, text, null);
            return foot;
        }
        let hyp = Utils.as(content, UnitextHyperlink);
        if (hyp !== null) {
            if (hyp.content !== null) 
                hyp.content = UnitextImplantateHelper.implantate(hyp.content, impl, text, null);
            return hyp;
        }
        let dbl = Utils.as(content, UnitextDocblock);
        if (dbl !== null) {
            if (dbl.head !== null) {
                let hh = Utils.as(UnitextImplantateHelper.implantate(dbl.head, impl, text, null), UnitextContainer);
                if (hh.children.includes(dbl)) {
                }
                dbl.head = hh;
            }
            if (dbl.body !== null && impl.parent === null) 
                dbl.body = UnitextImplantateHelper.implantate(dbl.body, impl, text, null);
            if (dbl.tail !== null && impl.parent === null) 
                dbl.tail = Utils.as(UnitextImplantateHelper.implantate(dbl.tail, impl, text, null), UnitextContainer);
            if (dbl.appendix !== null && impl.parent === null) 
                dbl.appendix = UnitextImplantateHelper.implantate(dbl.appendix, impl, text, null);
            return dbl;
        }
        let cnt = Utils.as(content, UnitextContainer);
        if (cnt !== null) {
            for (let i = 0; i < cnt.children.length; i++) {
                if (i === 49) {
                }
                let ch = cnt.children[i];
                if (ch.endChar === 0) 
                    continue;
                if (impl.endChar < ch.beginChar) {
                    if (impl.endChar === (impl.beginChar - 1) && impl.beginChar === ch.beginChar) {
                    }
                    else 
                        continue;
                }
                if (impl.beginChar > ch.endChar) 
                    continue;
                if (((ch instanceof UnitextFootnote) || (ch instanceof UnitextTable) || (ch instanceof UnitextList)) || (ch instanceof UnitextDocblock)) {
                    UnitextImplantateHelper.implantate(ch, impl, text, cnt);
                    if (impl.parent !== null) 
                        break;
                    continue;
                }
                if (((ch instanceof UnitextHyperlink) && ch.beginChar !== impl.beginChar) || ch.endChar > impl.endChar) {
                    UnitextImplantateHelper.implantate(ch, impl, text, cnt);
                    if (impl.parent !== null) 
                        break;
                    continue;
                }
                if (ch instanceof UnitextComment) 
                    continue;
                if (ch.beginChar > ch.endChar) 
                    continue;
                let i1 = impl.getPlaintextNsPos(text);
                let i2 = ch.getPlaintextNsPos(text);
                let e1 = impl.getPlaintextNsPos1(text);
                let e2 = ch.getPlaintextNsPos1(text);
                if (i1 > i2 || ((i1 === i2 && (e1 < e2)))) {
                    if (ch instanceof UnitextContainer) {
                        let cc = UnitextImplantateHelper.implantate(ch, impl, text, null);
                        if (cc === null) {
                        }
                        cnt.children[i] = cc;
                    }
                    continue;
                }
                let j = 0;
                for (j = i; j < cnt.children.length; j++) {
                    ch = cnt.children[j];
                    if (impl.endChar < ch.beginChar) {
                        if (impl.endChar === (impl.beginChar - 1) && impl.beginChar === ch.beginChar) {
                            cnt.children.splice(j, 0, impl);
                            impl.parent = cnt;
                            return content;
                        }
                        break;
                    }
                    if (ch === impl) 
                        return content;
                    impl.children.push(ch);
                    ch.parent = impl;
                }
                if (j > i) {
                    cnt.children[i] = impl;
                    impl.parent = cnt;
                    if (j > (i + 1)) 
                        cnt.children.splice(i + 1, j - i - 1);
                    impl.endChar = impl.children[impl.children.length - 1].endChar;
                    impl.beginChar = impl.children[0].beginChar;
                }
                break;
            }
            return content;
        }
        impl.children.push(content);
        impl.parent = content.parent;
        content.parent = impl;
        if (own !== null) {
            let ii = own.getChildIndexOf(content);
            if (ii >= 0) {
                own.children[ii] = impl;
                impl.parent = own;
            }
            else 
                return content;
        }
        return impl;
    }
    
    static _isTableChar(ch) {
        return (ch.charCodeAt(0)) === 7 || (ch.charCodeAt(0)) === 0x1E || (ch.charCodeAt(0)) === 0x1F;
    }
    
    static implantateBlock(content, beginHead, beginBody, beginTail, beginAppendix, end, text, own, res) {
        if (content === null) 
            return null;
        if (end < content.beginChar) 
            return content;
        if (beginHead > content.endChar) 
            return content;
        if ((beginHead < beginBody) && (beginBody < end)) 
            content = UnitextImplantateHelper._splitTexts(content, beginHead, beginBody - 1, own, 0);
        let tab = Utils.as(content, UnitextTable);
        if (tab !== null) {
            let bh = beginHead;
            for (; bh < text.length; bh++) {
                if (!UnitextImplantateHelper._isTableChar(text[bh])) 
                    break;
            }
            let bb = beginBody;
            if (bb < bh) 
                bb = bh;
            for (let r = 0; r < tab.rowsCount; r++) {
                for (let c = 0; c < tab.colsCount; c++) {
                    let cel = tab.getCell(r, c);
                    if (cel === null || cel.content === null) 
                        continue;
                    if (cel.colEnd > c) 
                        c = cel.colEnd;
                    if (cel.beginChar <= bh && bh <= cel.endChar && cel.rowBegin === cel.rowEnd) {
                        if ((bh < bb) && cel.endChar > bh && bb > cel.endChar) {
                            let res0 = UnitextDocblock._new402(bh, cel.endChar);
                            res0.head = UnitextContainer._new94(UnitextContainerType.HEAD);
                            res0.head.children.push(cel.content);
                            res0.head.beginChar = bh;
                            res0.head.endChar = cel.endChar;
                            cel.content = res0;
                            if (res.value === null) 
                                res.value = res0;
                            return tab;
                        }
                        cel.content = UnitextImplantateHelper.implantateBlock(cel.content, beginHead, beginBody, beginTail, beginAppendix, end, text, null, res);
                    }
                    else if (cel.beginChar <= bb && bb <= cel.endChar) {
                        if ((bh < bb) && cel.endChar > bh && bb > cel.endChar) {
                            let res0 = UnitextDocblock._new402(bh, cel.endChar);
                            res0.body = UnitextContainer._new94(UnitextContainerType.HEAD);
                            res0.body.children.push(cel.content);
                            res0.body.beginChar = bb;
                            res0.body.endChar = cel.endChar;
                            cel.content = res0;
                            if (res.value === null) 
                                res.value = res0;
                            return tab;
                        }
                        cel.content = UnitextImplantateHelper.implantateBlock(cel.content, beginHead, beginBody, beginTail, beginAppendix, end, text, null, res);
                    }
                }
            }
            return tab;
        }
        let li = Utils.as(content, UnitextList);
        if (li !== null) {
            for (const l of li.items) {
                if (l.beginChar <= beginHead && beginHead <= l.endChar) {
                    if (l.content !== null) 
                        l.content = UnitextImplantateHelper.implantateBlock(l.content, beginHead, beginBody, beginTail, beginAppendix, end, text, null, res);
                    if (l.sublist !== null) 
                        UnitextImplantateHelper.implantateBlock(l.sublist, beginHead, beginBody, beginTail, beginAppendix, end, text, null, res);
                }
            }
            return li;
        }
        let cnt = Utils.as(content, UnitextContainer);
        if (cnt !== null) {
            for (let i = 0; i < cnt.children.length; i++) {
                let ch = cnt.children[i];
                if (ch.isWhitespaces) 
                    continue;
                if (end < ch.beginChar) 
                    break;
                if ((ch instanceof UnitextTable) || (ch instanceof UnitextList) || (ch instanceof UnitextDocblock)) {
                }
                if (beginHead > ch.getPlaintextNsPos(text)) {
                    if ((beginHead < ch.endChar) && (ch instanceof UnitextTable)) {
                        UnitextImplantateHelper.implantateBlock(ch, beginHead, beginBody, beginTail, beginAppendix, end, text, null, res);
                        return content;
                    }
                    continue;
                }
                if (ch !== cnt.children[i]) {
                }
                ch = cnt.children[i];
                if (ch instanceof UnitextDocblock) 
                    continue;
                if ((ch instanceof UnitextList) && (beginHead < beginBody) && ch.getPlaintextNsPos(text) === beginHead) {
                    let list = Utils.as(ch, UnitextList);
                    let jj = i + 1;
                    for (const it of list.items) {
                        if (it.prefix !== null) {
                            it.prefix.parent = cnt;
                            cnt.children.splice(jj++, 0, it.prefix);
                            let sp = UnitextPlaintext._new57(" ");
                            sp.beginChar = it.prefix.endChar + 1;
                            sp.endChar = sp.beginChar;
                            sp.parent = cnt;
                            cnt.children.splice(jj++, 0, sp);
                        }
                        if (it.content !== null) {
                            it.content.parent = cnt;
                            cnt.children.splice(jj++, 0, it.content);
                        }
                        if (it === list.items[list.items.length - 1] && it.sublist === null) 
                            continue;
                        let nl = new UnitextNewline();
                        nl.beginChar = cnt.children[jj - 1].endChar + 1;
                        nl.endChar = nl.beginChar;
                        nl.parent = cnt;
                        cnt.children.splice(jj++, 0, nl);
                        if (it.sublist !== null) {
                            it.sublist.parent = cnt;
                            cnt.children.splice(jj++, 0, it.sublist);
                        }
                    }
                    cnt.children.splice(i, 1);
                    i--;
                    continue;
                }
                if ((ch instanceof UnitextTable) && ch.beginChar <= beginHead && (end < ch.endChar)) {
                    UnitextImplantateHelper.implantateBlock(ch, beginHead, beginBody, beginTail, beginAppendix, end, text, null, res);
                    return content;
                }
                res.value = UnitextDocblock._new402(beginHead, end);
                let head = UnitextContainer._new94(UnitextContainerType.HEAD);
                let body = new UnitextContainer();
                let tail = UnitextContainer._new94(UnitextContainerType.TAIL);
                let apps = new UnitextContainer();
                let j = 0;
                for (j = i; j < cnt.children.length; j++) {
                    if (beginHead === beginBody) 
                        break;
                    ch = cnt.children[j];
                    if (!ch.isWhitespaces) {
                        let ppp = ch.getPlaintextNsPos1(text);
                        if (beginBody < ppp) 
                            break;
                        if (beginBody === ppp && (beginBody < end)) 
                            break;
                    }
                    head.children.push(ch);
                    ch.parent = head;
                }
                for (; j < cnt.children.length; j++) {
                    if (beginBody === beginTail || beginBody === beginAppendix) 
                        break;
                    ch = cnt.children[j];
                    if (!ch.isWhitespaces) {
                        if (beginTail < ch.getPlaintextNsPos1(text)) 
                            break;
                    }
                    body.children.push(ch);
                    ch.parent = body;
                }
                for (; j < cnt.children.length; j++) {
                    if (beginTail === end) 
                        break;
                    ch = cnt.children[j];
                    if (!ch.isWhitespaces) {
                        if (beginAppendix < ch.getPlaintextNsPos1(text)) 
                            break;
                    }
                    tail.children.push(ch);
                    ch.parent = tail;
                }
                for (; j < cnt.children.length; j++) {
                    if (beginAppendix === end) 
                        break;
                    ch = cnt.children[j];
                    if (!ch.isWhitespaces) {
                        if (end < ch.getPlaintextNsPos1(text)) 
                            break;
                    }
                    apps.children.push(ch);
                    ch.parent = apps;
                }
                if (j > i) {
                    cnt.children[i] = res.value;
                    res.value.parent = cnt;
                    if (j > (i + 1)) 
                        cnt.children.splice(i + 1, j - i - 1);
                    if (head.children.length > 0) {
                        res.value.head = head;
                        head.parent = res.value;
                        head.beginChar = beginHead;
                        head.endChar = head.children[head.children.length - 1].endChar;
                    }
                    if (body.children.length > 0) {
                        res.value.body = body;
                        body.parent = res.value;
                        body.beginChar = beginBody;
                        if (body.children[0].beginChar < body.beginChar) 
                            body.beginChar = body.children[0].beginChar;
                        body.endChar = body.children[body.children.length - 1].endChar;
                    }
                    if (tail.children.length > 0) {
                        res.value.tail = tail;
                        tail.parent = res.value;
                        tail.beginChar = beginTail;
                        if (tail.children[0].beginChar < tail.beginChar) 
                            tail.beginChar = tail.children[0].beginChar;
                        tail.endChar = tail.children[tail.children.length - 1].endChar;
                    }
                    if (apps.children.length > 0) {
                        res.value.appendix = apps;
                        apps.parent = res.value;
                        apps.beginChar = beginAppendix;
                        apps.endChar = apps.children[apps.children.length - 1].endChar;
                    }
                }
                break;
            }
            return content;
        }
        if ((content instanceof UnitextPlaintext) && (((content.parent instanceof UnitextTablecell) || (content.parent instanceof UnitextListitem)))) {
            if ((content.beginChar === beginBody && beginBody === beginHead && end === beginTail) && end === beginAppendix && end === content.endChar) {
                res.value = UnitextDocblock._new402(beginHead, end);
                res.value.body = content;
                return res.value;
            }
        }
        return content;
    }
}


module.exports = UnitextImplantateHelper