(function (_, kotlin_kotlin) {
  'use strict';
  //region block: imports
  var _Char___init__impl__6a9atx = kotlin_kotlin.$_$.o3;
  var protoOf = kotlin_kotlin.$_$.bg;
  var Char__toInt_impl_vasixd = kotlin_kotlin.$_$.v3;
  var numberToChar = kotlin_kotlin.$_$.vf;
  var Companion_getInstance = kotlin_kotlin.$_$.b6;
  var objectMeta = kotlin_kotlin.$_$.ag;
  var setMetadataFor = kotlin_kotlin.$_$.cg;
  var Char__compareTo_impl_ypi4mb = kotlin_kotlin.$_$.q3;
  var get_indices = kotlin_kotlin.$_$.aj;
  var IndexOutOfBoundsException_init_$Create$ = kotlin_kotlin.$_$.q2;
  var charSequenceLength = kotlin_kotlin.$_$.ke;
  var charSequenceGet = kotlin_kotlin.$_$.je;
  var getOrNull = kotlin_kotlin.$_$.wi;
  var isLowSurrogate = kotlin_kotlin.$_$.fj;
  var Char = kotlin_kotlin.$_$.tl;
  var isHighSurrogate = kotlin_kotlin.$_$.dj;
  var toCharArray = kotlin_kotlin.$_$.qk;
  var booleanArray = kotlin_kotlin.$_$.fe;
  var Char__plus_impl_qi7pgj = kotlin_kotlin.$_$.t3;
  var StringBuilder_init_$Create$ = kotlin_kotlin.$_$.m1;
  var decodeToString = kotlin_kotlin.$_$.pi;
  var toString = kotlin_kotlin.$_$.w3;
  var toString_0 = kotlin_kotlin.$_$.gg;
  var IllegalArgumentException_init_$Create$ = kotlin_kotlin.$_$.g2;
  var toInt = kotlin_kotlin.$_$.wk;
  var toByte = kotlin_kotlin.$_$.dg;
  var IllegalArgumentException_init_$Create$_0 = kotlin_kotlin.$_$.i2;
  var NumberFormatException = kotlin_kotlin.$_$.jm;
  var VOID = kotlin_kotlin.$_$.g;
  var charArrayOf = kotlin_kotlin.$_$.he;
  var concatToString = kotlin_kotlin.$_$.ki;
  var encodeToByteArray = kotlin_kotlin.$_$.ri;
  var contains = kotlin_kotlin.$_$.ni;
  //endregion
  //region block: pre-declaration
  setMetadataFor(Character, 'Character', objectMeta);
  setMetadataFor(UrlEncoderUtil, 'UrlEncoderUtil', objectMeta);
  //endregion
  function _get_MAX_CODE_POINT__52cea6($this) {
    return $this.MAX_CODE_POINT_1;
  }
  function _get_MIN_SUPPLEMENTARY_CODE_POINT__i2yy0g($this) {
    return $this.MIN_SUPPLEMENTARY_CODE_POINT_1;
  }
  function _get_SURROGATE_DECODE_OFFSET__fff46s($this) {
    return $this.SURROGATE_DECODE_OFFSET_1;
  }
  function _get_HIGH_SURROGATE_ENCODE_OFFSET__ivfnmb($this) {
    return $this.HIGH_SURROGATE_ENCODE_OFFSET_1;
  }
  function Character() {
    Character_instance = this;
    this.MAX_CODE_POINT_1 = 1114111;
    this.MIN_SUPPLEMENTARY_CODE_POINT_1 = 65536;
    this.SURROGATE_DECODE_OFFSET_1 = -56613888;
    this.HIGH_SURROGATE_ENCODE_OFFSET_1 = _Char___init__impl__6a9atx(55232);
  }
  protoOf(Character).isSupplementaryCodePoint_gwjh52_k$ = function (codePoint) {
    return 65536 <= codePoint ? codePoint <= 1114111 : false;
  };
  protoOf(Character).toCodePoint_4ug988_k$ = function (highSurrogate, lowSurrogate) {
    // Inline function 'kotlin.code' call
    var tmp = Char__toInt_impl_vasixd(highSurrogate) << 10;
    // Inline function 'kotlin.code' call
    return (tmp + Char__toInt_impl_vasixd(lowSurrogate) | 0) + -56613888 | 0;
  };
  protoOf(Character).isBmpCodePoint_nwwl8w_k$ = function (codePoint) {
    return (codePoint >>> 16 | 0) === 0;
  };
  protoOf(Character).highSurrogateOf_rqtz3h_k$ = function (codePoint) {
    var tmp = codePoint >>> 10 | 0;
    // Inline function 'kotlin.code' call
    var this_0 = _Char___init__impl__6a9atx(55232);
    var tmp$ret$0 = Char__toInt_impl_vasixd(this_0);
    return numberToChar(tmp + tmp$ret$0 | 0);
  };
  protoOf(Character).lowSurrogateOf_mvzkm7_k$ = function (codePoint) {
    var tmp = codePoint & 1023;
    // Inline function 'kotlin.code' call
    var this_0 = Companion_getInstance().get_MIN_LOW_SURROGATE_mwv6vb_k$();
    var tmp$ret$0 = Char__toInt_impl_vasixd(this_0);
    return numberToChar(tmp + tmp$ret$0 | 0);
  };
  var Character_instance;
  function Character_getInstance() {
    if (Character_instance == null)
      new Character();
    return Character_instance;
  }
  function _get_hexDigits__71exdc($this) {
    return $this.hexDigits_1;
  }
  function _get_unreservedChars__q1bk6t($this) {
    return $this.unreservedChars_1;
  }
  function isUnreserved(_this__u8e3s4, $this) {
    var tmp;
    if (Char__compareTo_impl_ypi4mb(_this__u8e3s4, _Char___init__impl__6a9atx(122)) <= 0) {
      // Inline function 'kotlin.code' call
      var tmp$ret$0 = Char__toInt_impl_vasixd(_this__u8e3s4);
      tmp = $this.unreservedChars_1[tmp$ret$0];
    } else {
      tmp = false;
    }
    return tmp;
  }
  function appendEncodedDigit(_this__u8e3s4, $this, digit) {
    _this__u8e3s4.append_am5a4z_k$($this.hexDigits_1[digit & 15]);
  }
  function appendEncodedByte(_this__u8e3s4, $this, ch) {
    _this__u8e3s4.append_22ad7x_k$('%');
    appendEncodedDigit(_this__u8e3s4, $this, ch >> 4);
    appendEncodedDigit(_this__u8e3s4, $this, ch);
  }
  function codePointAt(_this__u8e3s4, $this, index) {
    if (!(0 <= index ? index <= (charSequenceLength(_this__u8e3s4) - 1 | 0) : false))
      throw IndexOutOfBoundsException_init_$Create$('index ' + index + ' was not in range ' + get_indices(_this__u8e3s4));
    var firstChar = charSequenceGet(_this__u8e3s4, index);
    if (isHighSurrogate(firstChar)) {
      var nextChar = getOrNull(_this__u8e3s4, index + 1 | 0);
      var tmp;
      var tmp_0 = nextChar;
      if ((tmp_0 == null ? null : new Char(tmp_0)) == null) {
        tmp = null;
      } else {
        tmp = isLowSurrogate(nextChar);
      }
      if (tmp === true) {
        return Character_getInstance().toCodePoint_4ug988_k$(firstChar, nextChar);
      }
    }
    // Inline function 'kotlin.code' call
    return Char__toInt_impl_vasixd(firstChar);
  }
  function UrlEncoderUtil() {
    UrlEncoderUtil_instance = this;
    this.hexDigits_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.unreservedChars_1 = this_0;
  }
  protoOf(UrlEncoderUtil).decode_w29spz_k$ = 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.append_xdc1zw_k$(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.append_22ad7x_k$(decodeToString(bytesBuffer, 0, bytesPos));
          started = true;
          bytesBuffer = null;
          bytesPos = 0;
        }
        if (plusToSpace ? ch === _Char___init__impl__6a9atx(43) : false) {
          if (!started) {
            out.append_xdc1zw_k$(source, 0, i);
            started = true;
          }
          out.append_22ad7x_k$(' ');
        } else if (started) {
          out.append_am5a4z_k$(ch);
        }
        i = i + 1 | 0;
      }
    }
    if (!(bytesBuffer == null)) {
      out.append_22ad7x_k$(decodeToString(bytesBuffer, 0, bytesPos));
    }
    return !started ? source : out.toString();
  };
  protoOf(UrlEncoderUtil).decode$default_ih4uzr_k$ = function (source, plusToSpace, $super) {
    plusToSpace = plusToSpace === VOID ? false : plusToSpace;
    return $super === VOID ? this.decode_w29spz_k$(source, plusToSpace) : $super.decode_w29spz_k$.call(this, source, plusToSpace);
  };
  protoOf(UrlEncoderUtil).encode_ma6hv5_k$ = function (source, allow, spaceToPlus) {
    // Inline function 'kotlin.text.isEmpty' call
    if (charSequenceLength(source) === 0) {
      return source;
    }
    var out = null;
    var i = 0;
    while (i < source.length) {
      var ch = charSequenceGet(source, i);
      if (isUnreserved(ch, this) ? true : contains(allow, ch)) {
        var tmp0_safe_receiver = out;
        if (tmp0_safe_receiver == null)
          null;
        else
          tmp0_safe_receiver.append_am5a4z_k$(ch);
        i = i + 1 | 0;
      } else {
        if (out == null) {
          out = StringBuilder_init_$Create$(source.length);
          out.append_xdc1zw_k$(source, 0, i);
        }
        var cp = codePointAt(source, this, i);
        if (cp < 128) {
          if (spaceToPlus ? ch === _Char___init__impl__6a9atx(32) : false) {
            out.append_am5a4z_k$(_Char___init__impl__6a9atx(43));
          } else {
            appendEncodedByte(out, this, cp);
          }
          i = i + 1 | 0;
        } else if (Character_getInstance().isBmpCodePoint_nwwl8w_k$(cp)) {
          var indexedObject = encodeToByteArray(toString(ch));
          var inductionVariable = 0;
          var last = indexedObject.length;
          while (inductionVariable < last) {
            var b = indexedObject[inductionVariable];
            inductionVariable = inductionVariable + 1 | 0;
            appendEncodedByte(out, this, b);
          }
          i = i + 1 | 0;
        } else if (Character_getInstance().isSupplementaryCodePoint_gwjh52_k$(cp)) {
          var high = Character_getInstance().highSurrogateOf_rqtz3h_k$(cp);
          var low = Character_getInstance().lowSurrogateOf_mvzkm7_k$(cp);
          // Inline function 'kotlin.charArrayOf' call
          var tmp$ret$1 = charArrayOf([high, low]);
          var indexedObject_0 = encodeToByteArray(concatToString(tmp$ret$1));
          var inductionVariable_0 = 0;
          var last_0 = indexedObject_0.length;
          while (inductionVariable_0 < last_0) {
            var b_0 = indexedObject_0[inductionVariable_0];
            inductionVariable_0 = inductionVariable_0 + 1 | 0;
            appendEncodedByte(out, this, b_0);
          }
          i = i + 2 | 0;
        }
      }
    }
    var tmp6_safe_receiver = out;
    var tmp7_elvis_lhs = tmp6_safe_receiver == null ? null : tmp6_safe_receiver.toString();
    return tmp7_elvis_lhs == null ? source : tmp7_elvis_lhs;
  };
  protoOf(UrlEncoderUtil).encode$default_3ym6jo_k$ = function (source, allow, spaceToPlus, $super) {
    allow = allow === VOID ? '' : allow;
    spaceToPlus = spaceToPlus === VOID ? false : spaceToPlus;
    return $super === VOID ? this.encode_ma6hv5_k$(source, allow, spaceToPlus) : $super.encode_ma6hv5_k$.call(this, source, allow, spaceToPlus);
  };
  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
