(function (_, kotlin_kotlin) {
  'use strict';
  //region block: imports
  var toCharArray = kotlin_kotlin.$_$.pg;
  var booleanArray = kotlin_kotlin.$_$.eb;
  var _Char___init__impl__6a9atx = kotlin_kotlin.$_$.u2;
  var Char__toInt_impl_vasixd = kotlin_kotlin.$_$.b3;
  var Char__plus_impl_qi7pgj = kotlin_kotlin.$_$.z2;
  var Unit_instance = kotlin_kotlin.$_$.m5;
  var charSequenceLength = kotlin_kotlin.$_$.jb;
  var StringBuilder_init_$Create$ = kotlin_kotlin.$_$.e1;
  var charSequenceGet = kotlin_kotlin.$_$.ib;
  var decodeToString = kotlin_kotlin.$_$.te;
  var toString = kotlin_kotlin.$_$.c3;
  var toString_0 = kotlin_kotlin.$_$.bd;
  var IllegalArgumentException_init_$Create$ = kotlin_kotlin.$_$.u1;
  var toInt = kotlin_kotlin.$_$.vg;
  var toByte = kotlin_kotlin.$_$.yc;
  var IllegalArgumentException_init_$Create$_0 = kotlin_kotlin.$_$.w1;
  var NumberFormatException = kotlin_kotlin.$_$.di;
  var protoOf = kotlin_kotlin.$_$.wc;
  var VOID = kotlin_kotlin.$_$.f;
  var objectMeta = kotlin_kotlin.$_$.vc;
  var setMetadataFor = kotlin_kotlin.$_$.xc;
  //endregion
  //region block: pre-declaration
  setMetadataFor(UrlEncoderUtil, 'UrlEncoderUtil', objectMeta);
  //endregion
  function UrlEncoderUtil() {
    UrlEncoderUtil_instance = this;
    this.pmd_1 = toCharArray('0123456789ABCDEF');
    var tmp = this;
    // Inline function 'kotlin.apply' call
    var this_0 = booleanArray(123);
    // Inline function 'kotlin.contracts.contract' call
    // Inline function 'net.thauvin.erik.urlencoder.UrlEncoderUtil.unreservedChars.<anonymous>' call
    // Inline function 'kotlin.code' call
    var this_1 = _Char___init__impl__6a9atx(45);
    this_0[Char__toInt_impl_vasixd(this_1)] = true;
    // Inline function 'kotlin.code' call
    var this_2 = _Char___init__impl__6a9atx(46);
    this_0[Char__toInt_impl_vasixd(this_2)] = true;
    // Inline function 'kotlin.code' call
    var this_3 = _Char___init__impl__6a9atx(95);
    this_0[Char__toInt_impl_vasixd(this_3)] = true;
    var inductionVariable = _Char___init__impl__6a9atx(48);
    if (inductionVariable <= _Char___init__impl__6a9atx(57))
      do {
        var c = inductionVariable;
        inductionVariable = Char__plus_impl_qi7pgj(inductionVariable, 1);
        // Inline function 'kotlin.code' call
        this_0[Char__toInt_impl_vasixd(c)] = true;
      }
       while (inductionVariable <= _Char___init__impl__6a9atx(57));
    var inductionVariable_0 = _Char___init__impl__6a9atx(65);
    if (inductionVariable_0 <= _Char___init__impl__6a9atx(90))
      do {
        var c_0 = inductionVariable_0;
        inductionVariable_0 = Char__plus_impl_qi7pgj(inductionVariable_0, 1);
        // Inline function 'kotlin.code' call
        this_0[Char__toInt_impl_vasixd(c_0)] = true;
      }
       while (inductionVariable_0 <= _Char___init__impl__6a9atx(90));
    var inductionVariable_1 = _Char___init__impl__6a9atx(97);
    if (inductionVariable_1 <= _Char___init__impl__6a9atx(122))
      do {
        var c_1 = inductionVariable_1;
        inductionVariable_1 = Char__plus_impl_qi7pgj(inductionVariable_1, 1);
        // Inline function 'kotlin.code' call
        this_0[Char__toInt_impl_vasixd(c_1)] = true;
      }
       while (inductionVariable_1 <= _Char___init__impl__6a9atx(122));
    tmp.qmd_1 = this_0;
  }
  protoOf(UrlEncoderUtil).rmd = function (source, plusToSpace) {
    // Inline function 'kotlin.text.isEmpty' call
    if (charSequenceLength(source) === 0) {
      return source;
    }
    var length = source.length;
    var out = StringBuilder_init_$Create$(length);
    var bytesBuffer = null;
    var bytesPos = 0;
    var i = 0;
    var started = false;
    while (i < length) {
      var ch = charSequenceGet(source, i);
      if (ch === _Char___init__impl__6a9atx(37)) {
        if (!started) {
          out.s8(source, 0, i);
          started = true;
        }
        if (bytesBuffer == null) {
          bytesBuffer = new Int8Array((length - i | 0) / 3 | 0);
        }
        i = i + 1 | 0;
        // Inline function 'kotlin.require' call
        // Inline function 'kotlin.contracts.contract' call
        if (!(length >= (i + 2 | 0))) {
          // Inline function 'net.thauvin.erik.urlencoder.UrlEncoderUtil.decode.<anonymous>' call
          var message = 'Incomplete trailing escape (' + toString(ch) + ') pattern';
          throw IllegalArgumentException_init_$Create$(toString_0(message));
        }
        try {
          // Inline function 'kotlin.text.substring' call
          var startIndex = i;
          var endIndex = i + 2 | 0;
          // Inline function 'kotlin.js.asDynamic' call
          var tmp$ret$3 = source.substring(startIndex, endIndex);
          var v = toInt(tmp$ret$3, 16);
          // Inline function 'kotlin.require' call
          // Inline function 'kotlin.contracts.contract' call
          if (!(0 <= v ? v <= 255 : false)) {
            // Inline function 'net.thauvin.erik.urlencoder.UrlEncoderUtil.decode.<anonymous>' call
            var message_0 = 'Illegal escape value';
            throw IllegalArgumentException_init_$Create$(toString_0(message_0));
          }
          var tmp = bytesBuffer;
          var tmp1 = bytesPos;
          bytesPos = tmp1 + 1 | 0;
          tmp[tmp1] = toByte(v);
          i = i + 2 | 0;
        } catch ($p) {
          if ($p instanceof NumberFormatException) {
            var e = $p;
            throw IllegalArgumentException_init_$Create$_0('Illegal characters in escape sequence: ' + e + '.message', e);
          } else {
            throw $p;
          }
        }
      } else {
        if (!(bytesBuffer == null)) {
          out.y5(decodeToString(bytesBuffer, 0, bytesPos));
          started = true;
          bytesBuffer = null;
          bytesPos = 0;
        }
        if (plusToSpace ? ch === _Char___init__impl__6a9atx(43) : false) {
          if (!started) {
            out.s8(source, 0, i);
            started = true;
          }
          out.y5(' ');
        } else if (started) {
          out.z5(ch);
        }
        i = i + 1 | 0;
      }
    }
    if (!(bytesBuffer == null)) {
      out.y5(decodeToString(bytesBuffer, 0, bytesPos));
    }
    return !started ? source : out.toString();
  };
  protoOf(UrlEncoderUtil).smd = function (source, plusToSpace, $super) {
    plusToSpace = plusToSpace === VOID ? false : plusToSpace;
    return $super === VOID ? this.rmd(source, plusToSpace) : $super.rmd.call(this, source, plusToSpace);
  };
  var UrlEncoderUtil_instance;
  function UrlEncoderUtil_getInstance() {
    if (UrlEncoderUtil_instance == null)
      new UrlEncoderUtil();
    return UrlEncoderUtil_instance;
  }
  //region block: exports
  _.$_$ = _.$_$ || {};
  _.$_$.a = UrlEncoderUtil_getInstance;
  //endregion
  return _;
}(module.exports, require('./kotlin-kotlin-stdlib.js')));

//# sourceMappingURL=urlencoder-urlencoder-lib.js.map
