/*
 * SDK Pullenti Lingvo, 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#.NET project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

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

/**
 * Информация о символах токена
 * 
 * Символьная информация
 */
class CharsInfo {
    
    constructor() {
        this.value = 0;
    }
    
    getValue(i) {
        return (((((this.value) >> i)) & 1)) !== 0;
    }
    
    setValue(i, val) {
        if (val) 
            this.value |= (1 << i);
        else 
            this.value &= (~(1 << i));
    }
    
    get isAllUpper() {
        return this.getValue(0);
    }
    set isAllUpper(_value) {
        this.setValue(0, _value);
        return _value;
    }
    
    get isAllLower() {
        return this.getValue(1);
    }
    set isAllLower(_value) {
        this.setValue(1, _value);
        return _value;
    }
    
    get isCapitalUpper() {
        return this.getValue(2);
    }
    set isCapitalUpper(_value) {
        this.setValue(2, _value);
        return _value;
    }
    
    get isLastLower() {
        return this.getValue(3);
    }
    set isLastLower(_value) {
        this.setValue(3, _value);
        return _value;
    }
    
    get isLetter() {
        return this.getValue(4);
    }
    set isLetter(_value) {
        this.setValue(4, _value);
        return _value;
    }
    
    get isLatinLetter() {
        return this.getValue(5);
    }
    set isLatinLetter(_value) {
        this.setValue(5, _value);
        return _value;
    }
    
    get isCyrillicLetter() {
        return this.getValue(6);
    }
    set isCyrillicLetter(_value) {
        this.setValue(6, _value);
        return _value;
    }
    
    toString() {
        if (!this.isLetter) 
            return "Nonletter";
        let tmpStr = new StringBuilder();
        if (this.isAllUpper) 
            tmpStr.append("AllUpper");
        else if (this.isAllLower) 
            tmpStr.append("AllLower");
        else if (this.isCapitalUpper) 
            tmpStr.append("CapitalUpper");
        else if (this.isLastLower) 
            tmpStr.append("LastLower");
        else 
            tmpStr.append("Nonstandard");
        if (this.isLatinLetter) 
            tmpStr.append(" Latin");
        else if (this.isCyrillicLetter) 
            tmpStr.append(" Cyrillic");
        else if (this.isLetter) 
            tmpStr.append(" Letter");
        return tmpStr.toString();
    }
    
    /**
     * Сравнение на совпадение значений всех полей
     * @param obj сравниваемый объект
     * @return 
     */
    equals(obj) {
        if (!(obj instanceof CharsInfo)) 
            return false;
        return this.value === obj.value;
    }
    
    convertWord(word) {
        if (Utils.isNullOrEmpty(word)) 
            return word;
        if (this.isAllLower) 
            return word.toLowerCase();
        if (this.isAllUpper) 
            return word.toUpperCase();
        if (this.isCapitalUpper && word.length > 0) {
            let tmp = new StringBuilder(word);
            for (let i = 0; i < tmp.length; i++) {
                if (i === 0) 
                    tmp.setCharAt(0, tmp.charAt(0).toUpperCase());
                else if (tmp.charAt(i - 1) === '-' || tmp.charAt(i - 1) === ' ') 
                    tmp.setCharAt(0, tmp.charAt(0).toUpperCase());
                else 
                    tmp.setCharAt(i, tmp.charAt(i).toLowerCase());
            }
            return tmp.toString();
        }
        return word;
    }
    
    static _new3217(_arg1) {
        let res = new CharsInfo();
        res.isCapitalUpper = _arg1;
        return res;
    }
    
    static _new3386(_arg1) {
        let res = new CharsInfo();
        res.isCyrillicLetter = _arg1;
        return res;
    }
    
    static _new3392(_arg1, _arg2) {
        let res = new CharsInfo();
        res.isCyrillicLetter = _arg1;
        res.isCapitalUpper = _arg2;
        return res;
    }
    
    static _new3397(_arg1, _arg2, _arg3, _arg4) {
        let res = new CharsInfo();
        res.isCapitalUpper = _arg1;
        res.isCyrillicLetter = _arg2;
        res.isLatinLetter = _arg3;
        res.isLetter = _arg4;
        return res;
    }
    
    static _new3405(_arg1) {
        let res = new CharsInfo();
        res.value = _arg1;
        return res;
    }
    
    static _new3426(_arg1) {
        let res = new CharsInfo();
        res.isLatinLetter = _arg1;
        return res;
    }
}


module.exports = CharsInfo