/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { CodePageEncoding } from "./CodePageEncoding";
import { Dictionary$2 } from "igniteui-angular-core";
import { String_$type, Array_$type, fromEnum, markType } from "igniteui-angular-core";
import { ArgumentNullException } from "igniteui-angular-core";
import { ArgumentOutOfRangeException } from "igniteui-angular-core";
import { StringBuilder } from "igniteui-angular-core";
import { nullableNotEquals, unwrapNullable } from "igniteui-angular-core";
import { stringToCharArray } from "igniteui-angular-core";
/**
 * @hidden
 */
var CodePageDoubleByte = /** @class */ (function (_super) {
    tslib_1.__extends(CodePageDoubleByte, _super);
    function CodePageDoubleByte(a, b) {
        var e_1, _a;
        var _this = _super.call(this) || this;
        _this._ag = 0;
        _this._ae = null;
        _this._af = null;
        _this._ag = a;
        _this._ae = b;
        if (b == null) {
            return _this;
        }
        if (_this._af != null) {
            return _this;
        }
        _this._af = new Dictionary$2(String_$type, Array_$type, 0);
        try {
            for (var _b = tslib_1.__values(fromEnum(b.keys)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                var d = b.item(c);
                for (var e = 0; e < d.length; e++) {
                    var f = d[e];
                    if (nullableNotEquals(f, null) && !_this._af.containsKey(f.value)) {
                        _this._af.addItem(f.value, [c, e]);
                    }
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_1) throw e_1.error; }
        }
        return _this;
    }
    CodePageDoubleByte.prototype.get__codePage = function () {
        return this._ag;
    };
    Object.defineProperty(CodePageDoubleByte.prototype, "_codePage", {
        get: function () {
            return this.get__codePage();
        },
        enumerable: true,
        configurable: true
    });
    CodePageDoubleByte.prototype.getChars = function (a, b, c, d, e) {
        if ((a == null) || (d == null)) {
            throw new ArgumentNullException(0, (a == null) ? "bytes are Null" : "chars are Null");
        }
        if ((b < 0) || (c < 0)) {
            throw new ArgumentOutOfRangeException(1, (b < 0) ? "byteIndex is out of Range" : "byteCount is out of Range");
        }
        if ((a.length - b) < c) {
            throw new ArgumentOutOfRangeException(1, "bytes");
        }
        if ((e < 0) || (e > d.length)) {
            throw new ArgumentOutOfRangeException(1, "charIndex");
        }
        if (a.length == 0) {
            return 0;
        }
        if (d.length == 0) {
            return 0;
        }
        var f = 0;
        var g = 0;
        var h = this.getString1(a, b, c);
        var i = stringToCharArray(h);
        for (var k = 0; k < i.length; k++) {
            var j = i[k];
            if (e <= j.charCodeAt(0)) {
                if (g < d.length) {
                    d[g] = j;
                    g++;
                }
                f++;
            }
        }
        return f;
    };
    CodePageDoubleByte.prototype.getMaxByteCount = function (a) {
        return a * 2;
    };
    CodePageDoubleByte.prototype.getMaxCharCount = function (a) {
        return a;
    };
    CodePageDoubleByte.prototype.getByteCount = function (a, b, c) {
        return c;
    };
    CodePageDoubleByte.prototype.getBytes2 = function (a, b, c, d, e) {
        var f = this._af;
        var _loop_1 = function (g) {
            var h;
            if (((function () { var i = f.tryGetValue(a[b], h); h = i.p1; return i.ret; })()) == false && ((function () { var i = f.tryGetValue('?', h); h = i.p1; return i.ret; })()) == false) {
                return "continue";
            }
            if (h[0] == 0) {
                d[e++] = h[1];
            }
            else {
                d[e++] = h[0];
                d[e++] = h[1];
            }
        };
        for (var g = b + c; b < g; b++) {
            _loop_1(g);
        }
        return c;
    };
    CodePageDoubleByte.prototype.getCharCount1 = function (a, b, c) {
        return c;
    };
    CodePageDoubleByte.prototype.getString1 = function (a, b, c) {
        var d = new StringBuilder(0);
        for (var e = b; e < b + c;) {
            if (this._ae.containsKey(a[e])) {
                var f = this._ae.item(a[e]);
                d.k(unwrapNullable(f[a[e + 1]]));
                e += 2;
            }
            else {
                var g = this._ae.item(0);
                d.k(unwrapNullable(g[a[e]]));
                e++;
            }
        }
        return d.toString();
    };
    CodePageDoubleByte.$t = markType(CodePageDoubleByte, 'CodePageDoubleByte', CodePageEncoding.$);
    return CodePageDoubleByte;
}(CodePageEncoding));
export { CodePageDoubleByte };
//# sourceMappingURL=CodePageDoubleByte.js.map