/*
 * 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 CorrFootnoteTyps = require("./CorrFootnoteTyps");

class CorrFootnoteTag {
    
    constructor() {
        this.typ = CorrFootnoteTyps.DIGIT;
        this.number = 0;
    }
    
    static tryParse(text, i, forContaiter, robust = false) {
        for (; i.value < text.length; i.value++) {
            if (!Utils.isWhitespace(text[i.value])) 
                break;
        }
        if (i.value >= text.length) 
            return null;
        if (text[i.value] !== '<') {
            if (robust && text[i.value] === '*') {
                let res1 = CorrFootnoteTag._new332(CorrFootnoteTyps.STARS);
                for (; i.value < text.length; i.value++) {
                    if (text[i.value] !== '*') {
                        i.value--;
                        break;
                    }
                    else 
                        res1.number++;
                }
                return res1;
            }
            if (((((i.value + 10) < text.length) && text[i.value] === 'С' && text[i.value + 1] === 'н') && text[i.value + 2] === 'о' && text[i.value + 3] === 'с') && text[i.value + 4] === 'к' && text[i.value + 5] === 'а') {
                let j = 0;
                let num = 0;
                for (j = i.value + 7; j < text.length; j++) {
                    if (text[j] === ':' && num > 0) {
                        let res1 = CorrFootnoteTag._new333(CorrFootnoteTyps.DIGIT, num);
                        i.value = j;
                        return res1;
                    }
                    else if (Utils.isDigit(text[j])) 
                        num = (num * 10) + (((text.charCodeAt(j)) - ('0'.charCodeAt(0))));
                    else 
                        break;
                }
            }
            if (Utils.isDigit(text[i.value]) && forContaiter) {
                let j = 0;
                let num = 0;
                for (j = i.value; j < text.length; j++) {
                    if (Utils.isDigit(text[j])) 
                        num = (num * 10) + (((text.charCodeAt(j)) - ('0'.charCodeAt(0))));
                    else if (text[j] === ')') {
                        let res1 = CorrFootnoteTag._new333(CorrFootnoteTyps.VERYDOUBT, num);
                        i.value = j;
                        return res1;
                    }
                    else 
                        break;
                }
            }
            return null;
        }
        if ((i.value + 2) >= text.length) 
            return null;
        let ii = i.value + 1;
        if (text[ii] !== '*' && !Utils.isDigit(text[ii])) 
            return null;
        let res = CorrFootnoteTag._new332((text[ii] === '*' ? CorrFootnoteTyps.STARS : CorrFootnoteTyps.DIGIT));
        for (; ii < text.length; ii++) {
            if (text[ii] === '*' && res.typ === CorrFootnoteTyps.STARS) 
                res.number++;
            else if (Utils.isDigit(text[ii]) && res.typ === CorrFootnoteTyps.DIGIT) 
                res.number = (res.number * 10) + (((text.charCodeAt(ii)) - ('0'.charCodeAt(0))));
            else if (text[ii] === '>') {
                i.value = ii;
                return res;
            }
            else 
                break;
        }
        return null;
    }
    
    static _new310(_arg1, _arg2) {
        let res = new CorrFootnoteTag();
        res.number = _arg1;
        res.typ = _arg2;
        return res;
    }
    
    static _new332(_arg1) {
        let res = new CorrFootnoteTag();
        res.typ = _arg1;
        return res;
    }
    
    static _new333(_arg1, _arg2) {
        let res = new CorrFootnoteTag();
        res.typ = _arg1;
        res.number = _arg2;
        return res;
    }
}


module.exports = CorrFootnoteTag