%%
%% This is file `l3str-convert.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3str-convert.dtx  (with options: `package')
%% 
%% Copyright (C) 2011-2019 The LaTeX3 Project
%% 
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version.  The latest
%% version of this license is in the file:
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% This file is part of the "l3experimental bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%% 
%% File: l3str-convert.dtx Copyright (C) 2013-2019 The LaTeX3 Project
\RequirePackage{expl3}
\ProvidesExplPackage{l3str-convert}{2019-03-05}{}
  {L3 Experimental string encoding conversions}
\cs_if_exist:NF \use_ii_i:nn
  { \cs_new:Npn \use_ii_i:nn #1#2 { #2 #1 } }
\cs_new_protected:Npn \__str_tmp:w { }
\tl_new:N \l__str_internal_tl
\int_new:N \l__str_internal_int
\tl_new:N \g__str_result_tl
\int_const:Nn \c__str_replacement_char_int { "FFFD }
\int_const:Nn \c__str_max_byte_int { 255 }
\prop_new:N \g__str_alias_prop
\prop_gput:Nnn \g__str_alias_prop { latin1 } { iso88591 }
\prop_gput:Nnn \g__str_alias_prop { latin2 } { iso88592 }
\prop_gput:Nnn \g__str_alias_prop { latin3 } { iso88593 }
\prop_gput:Nnn \g__str_alias_prop { latin4 } { iso88594 }
\prop_gput:Nnn \g__str_alias_prop { latin5 } { iso88599 }
\prop_gput:Nnn \g__str_alias_prop { latin6 } { iso885910 }
\prop_gput:Nnn \g__str_alias_prop { latin7 } { iso885913 }
\prop_gput:Nnn \g__str_alias_prop { latin8 } { iso885914 }
\prop_gput:Nnn \g__str_alias_prop { latin9 } { iso885915 }
\prop_gput:Nnn \g__str_alias_prop { latin10 } { iso885916 }
\prop_gput:Nnn \g__str_alias_prop { utf16le } { utf16 }
\prop_gput:Nnn \g__str_alias_prop { utf16be } { utf16 }
\prop_gput:Nnn \g__str_alias_prop { utf32le } { utf32 }
\prop_gput:Nnn \g__str_alias_prop { utf32be } { utf32 }
\prop_gput:Nnn \g__str_alias_prop { hexadecimal } { hex }
\bool_new:N \g__str_error_bool
\flag_new:n { str_byte }
\flag_new:n { str_error }
\prg_new_conditional:Npnn \__str_if_contains_char:NN #1#2 { T , TF }
  {
    \exp_after:wN \__str_if_contains_char_aux:NN \exp_after:wN #2
      #1 { \prg_break:n { ? \fi: } }
    \prg_break_point:
    \prg_return_false:
  }
\prg_new_conditional:Npnn \__str_if_contains_char:nN #1#2 { TF }
  {
    \__str_if_contains_char_aux:NN #2 #1 { \prg_break:n { ? \fi: } }
    \prg_break_point:
    \prg_return_false:
  }
\cs_new:Npn \__str_if_contains_char_aux:NN #1#2
  {
    \if_charcode:w #1 #2
      \exp_after:wN \__str_if_contains_char_true:
    \fi:
    \__str_if_contains_char_aux:NN #1
  }
\cs_new:Npn \__str_if_contains_char_true:
  { \prg_break:n { \prg_return_true: \use_none:n } }
\prg_new_conditional:Npnn \__str_octal_use:N #1 { TF }
  {
    \if_int_compare:w 1 < '1 \token_to_str:N #1 \exp_stop_f:
      #1 \prg_return_true:
    \else:
      \prg_return_false:
    \fi:
  }
\prg_new_conditional:Npnn \__str_hexadecimal_use:N #1 { TF }
  {
    \if_int_compare:w 1 < "1 \token_to_str:N #1 \exp_stop_f:
      #1 \prg_return_true:
    \else:
      \if_case:w \int_eval:n { \exp_after:wN ` \token_to_str:N #1 - `a }
           A
      \or: B
      \or: C
      \or: D
      \or: E
      \or: F
      \else:
        \prg_return_false:
        \exp_after:wN \use_none:n
      \fi:
      \prg_return_true:
    \fi:
  }
\group_begin:
  \tl_set:Nx \l__str_internal_tl { \tl_to_str:n { 0123456789ABCDEF } }
   \tl_map_inline:Nn \l__str_internal_tl
     {
        \tl_map_inline:Nn \l__str_internal_tl
          {
            \tl_const:cx { c__str_byte_ \int_eval:n {"#1##1} _tl }
               { \char_generate:nn { "#1##1 } { 12 } #1 ##1 }
          }
     }
\group_end:
\tl_const:cn { c__str_byte_-1_tl } { { } \use_none:n { } }
\cs_new:Npn \__str_output_byte:n #1
  { \__str_output_byte:w #1 \__str_output_end: }
\cs_new:Npn \__str_output_byte:w
  {
    \exp_after:wN \exp_after:wN
    \exp_after:wN \use_i:nnn
    \cs:w c__str_byte_ \int_eval:w
  }
\cs_new:Npn \__str_output_hexadecimal:n #1
  {
    \exp_after:wN \exp_after:wN
    \exp_after:wN \use_none:n
    \cs:w c__str_byte_ \int_eval:n {#1} _tl \cs_end:
  }
\cs_new:Npn \__str_output_end:
  { \scan_stop: _tl \cs_end: }
\cs_new:Npn \__str_output_byte_pair_be:n #1
  {
    \exp_args:Nf \__str_output_byte_pair:nnN
      { \int_div_truncate:nn { #1 } { "100 } } {#1} \use:nn
  }
\cs_new:Npn \__str_output_byte_pair_le:n #1
  {
    \exp_args:Nf \__str_output_byte_pair:nnN
      { \int_div_truncate:nn { #1 } { "100 } } {#1} \use_ii_i:nn
  }
\cs_new:Npn \__str_output_byte_pair:nnN #1#2#3
  {
    #3
      { \__str_output_byte:n { #1 } }
      { \__str_output_byte:n { #2 - #1 * "100 } }
  }
\cs_new_protected:Npn \__str_convert_gmap:N #1
  {
    \tl_gset:Nx \g__str_result_tl
      {
        \exp_after:wN \__str_convert_gmap_loop:NN
        \exp_after:wN #1
          \g__str_result_tl { ? \prg_break: }
        \prg_break_point:
      }
  }
\cs_new:Npn \__str_convert_gmap_loop:NN #1#2
  {
    \use_none:n #2
    #1#2
    \__str_convert_gmap_loop:NN #1
  }
\cs_new_protected:Npn \__str_convert_gmap_internal:N #1
  {
    \tl_gset:Nx \g__str_result_tl
      {
        \exp_after:wN \__str_convert_gmap_internal_loop:Nww
        \exp_after:wN #1
          \g__str_result_tl \s__tl \q_stop \prg_break: \s__tl
        \prg_break_point:
      }
  }
\cs_new:Npn \__str_convert_gmap_internal_loop:Nww #1 #2 \s__tl #3 \s__tl
  {
    \use_none_delimit_by_q_stop:w #3 \q_stop
    #1 {#3}
    \__str_convert_gmap_internal_loop:Nww #1
  }
\cs_new_protected:Npn \__str_if_flag_error:nnx #1
  {
    \flag_if_raised:nTF {#1}
      { \__kernel_msg_error:nnx { str } }
      { \use_none:nn }
  }
\cs_new_protected:Npn \__str_if_flag_no_error:nnx #1#2#3
  { \flag_if_raised:nT {#1} { \bool_gset_true:N \g__str_error_bool } }
\cs_new:Npn \__str_if_flag_times:nT #1#2
  { \flag_if_raised:nT {#1} { #2~(x \flag_height:n {#1} ) } }
\cs_new_protected:Npn \str_set_convert:Nnnn
  { \__str_convert:nNNnnn { } \tl_set_eq:NN }
\cs_new_protected:Npn \str_gset_convert:Nnnn
  { \__str_convert:nNNnnn { } \tl_gset_eq:NN }
\prg_new_protected_conditional:Npnn
    \str_set_convert:Nnnn #1#2#3#4 { T , F , TF }
  {
    \bool_gset_false:N \g__str_error_bool
    \__str_convert:nNNnnn
      { \cs_set_eq:NN \__str_if_flag_error:nnx \__str_if_flag_no_error:nnx }
      \tl_set_eq:NN #1 {#2} {#3} {#4}
    \bool_if:NTF \g__str_error_bool \prg_return_false: \prg_return_true:
  }
\prg_new_protected_conditional:Npnn
    \str_gset_convert:Nnnn #1#2#3#4 { T , F , TF }
  {
    \bool_gset_false:N \g__str_error_bool
    \__str_convert:nNNnnn
      { \cs_set_eq:NN \__str_if_flag_error:nnx \__str_if_flag_no_error:nnx }
      \tl_gset_eq:NN #1 {#2} {#3} {#4}
    \bool_if:NTF \g__str_error_bool \prg_return_false: \prg_return_true:
  }
\cs_new_protected:Npn \__str_convert:nNNnnn #1#2#3#4#5#6
  {
    \group_begin:
      #1
      \tl_gset:Nx \g__str_result_tl { \__kernel_str_to_other_fast:n {#4} }
      \exp_after:wN \__str_convert:wwwnn
        \tl_to_str:n {#5} /// \q_stop
        { decode } { unescape }
        \prg_do_nothing:
        \__str_convert_decode_:
      \exp_after:wN \__str_convert:wwwnn
        \tl_to_str:n {#6} /// \q_stop
        { encode } { escape }
        \use_ii_i:nn
        \__str_convert_encode_:
    \group_end:
    #2 #3 \g__str_result_tl
  }
\cs_new_protected:Npn \__str_convert:wwwnn
    #1 / #2 // #3 \q_stop #4#5
  {
    \__str_convert:nnn {enc} {#4} {#1}
    \__str_convert:nnn {esc} {#5} {#2}
    \exp_args:Ncc \__str_convert:NNnNN
      { __str_convert_#4_#1: } { __str_convert_#5_#2: } {#2}
  }
\cs_new_protected:Npn \__str_convert:NNnNN #1#2#3#4#5
  {
    \if_meaning:w #1 #5
      \tl_if_empty:nF {#3}
        { \__kernel_msg_error:nnx { str } { native-escaping } {#3} }
      #1
    \else:
      #4 #2 #1
    \fi:
  }
\cs_new_protected:Npn \__str_convert:nnn #1#2#3
  {
    \cs_if_exist:cF { __str_convert_#2_#3: }
      {
        \exp_args:Nx \__str_convert:nnnn
          { \__str_convert_lowercase_alphanum:n {#3} }
          {#1} {#2} {#3}
      }
  }
\cs_new_protected:Npn \__str_convert:nnnn #1#2#3#4
  {
    \cs_if_exist:cF { __str_convert_#3_#1: }
      {
        \prop_get:NnNF \g__str_alias_prop {#1} \l__str_internal_tl
          { \tl_set:Nn \l__str_internal_tl {#1} }
        \cs_if_exist:cF { __str_convert_#3_ \l__str_internal_tl : }
          {
            \file_if_exist:nTF { l3str-#2- \l__str_internal_tl .def }
              {
                \group_begin:
                  \__str_load_catcodes:
                  \file_input:n { l3str-#2- \l__str_internal_tl .def }
                \group_end:
              }
              {
                \tl_clear:N \l__str_internal_tl
                \__kernel_msg_error:nnxx { str } { unknown-#2 } {#4} {#1}
              }
          }
        \cs_if_exist:cF { __str_convert_#3_#1: }
          {
            \cs_gset_eq:cc { __str_convert_#3_#1: }
              { __str_convert_#3_ \l__str_internal_tl : }
          }
      }
    \cs_gset_eq:cc { __str_convert_#3_#4: } { __str_convert_#3_#1: }
  }
\cs_new:Npn \__str_convert_lowercase_alphanum:n #1
  {
    \exp_after:wN \__str_convert_lowercase_alphanum_loop:N
      \tl_to_str:n {#1} { ? \prg_break: }
    \prg_break_point:
  }
\cs_new:Npn \__str_convert_lowercase_alphanum_loop:N #1
  {
    \use_none:n #1
    \if_int_compare:w `#1 > `Z \exp_stop_f:
      \if_int_compare:w `#1 > `z \exp_stop_f: \else:
        \if_int_compare:w `#1 < `a \exp_stop_f: \else:
          #1
        \fi:
      \fi:
    \else:
      \if_int_compare:w `#1 < `A \exp_stop_f:
        \if_int_compare:w 1 < 1#1 \exp_stop_f:
          #1
        \fi:
      \else:
        \__str_output_byte:n { `#1 + `a - `A }
      \fi:
    \fi:
    \__str_convert_lowercase_alphanum_loop:N
  }
\cs_new_protected:Npn \__str_load_catcodes:
  {
    \char_set_catcode_escape:N \\
    \char_set_catcode_group_begin:N \{
    \char_set_catcode_group_end:N \}
    \char_set_catcode_math_toggle:N \$
    \char_set_catcode_alignment:N \&
    \char_set_catcode_parameter:N \#
    \char_set_catcode_math_superscript:N \^
    \char_set_catcode_ignore:N \ %
    \char_set_catcode_space:N \~
    \tl_map_function:nN { abcdefghijklmnopqrstuvwxyz_:ABCDEFILNPSTUX }
      \char_set_catcode_letter:N
    \tl_map_function:nN { 0123456789"'?*+-.(),`!/<>[];= }
      \char_set_catcode_other:N
    \char_set_catcode_comment:N \%
    \int_set:Nn \tex_endlinechar:D {32}
  }
\bool_lazy_any:nTF
  {
    \sys_if_engine_luatex_p:
    \sys_if_engine_xetex_p:
  }
  {
    \cs_new:Npn \__str_filter_bytes:n #1
      {
        \__str_filter_bytes_aux:N #1
          { ? \prg_break: }
        \prg_break_point:
      }
    \cs_new:Npn \__str_filter_bytes_aux:N #1
      {
        \use_none:n #1
        \if_int_compare:w `#1 < 256 \exp_stop_f:
          #1
        \else:
          \flag_raise:n { str_byte }
        \fi:
        \__str_filter_bytes_aux:N
      }
  }
  { \cs_new_eq:NN \__str_filter_bytes:n \use:n }
\bool_lazy_any:nTF
  {
    \sys_if_engine_luatex_p:
    \sys_if_engine_xetex_p:
  }
  {
    \cs_new_protected:Npn \__str_convert_unescape_:
      {
        \flag_clear:n { str_byte }
        \tl_gset:Nx \g__str_result_tl
          { \exp_args:No \__str_filter_bytes:n \g__str_result_tl }
        \__str_if_flag_error:nnx { str_byte } { non-byte } { bytes }
      }
  }
  { \cs_new_protected:Npn \__str_convert_unescape_: { } }
\cs_new_eq:NN \__str_convert_unescape_bytes: \__str_convert_unescape_:
\cs_new_protected:Npn \__str_convert_escape_: { }
\cs_new_eq:NN \__str_convert_escape_bytes: \__str_convert_escape_:
\cs_new_protected:Npn \__str_convert_decode_:
  { \__str_convert_gmap:N \__str_decode_native_char:N }
\cs_new:Npn \__str_decode_native_char:N #1
  { #1 \s__tl \int_value:w `#1 \s__tl }
\bool_lazy_any:nTF
  {
    \sys_if_engine_luatex_p:
    \sys_if_engine_xetex_p:
  }
  {
    \cs_new_protected:Npn \__str_convert_encode_:
      { \__str_convert_gmap_internal:N \__str_encode_native_char:n }
    \cs_new:Npn \__str_encode_native_char:n #1
      { \char_generate:nn {#1} {12} }
  }
  {
    \cs_new_protected:Npn \__str_convert_encode_:
      {
        \flag_clear:n { str_error }
        \__str_convert_gmap_internal:N \__str_encode_native_char:n
        \__str_if_flag_error:nnx { str_error }
          { native-overflow } { }
      }
    \cs_new:Npn \__str_encode_native_char:n #1
      {
        \if_int_compare:w #1 > \c__str_max_byte_int
          \flag_raise:n { str_error }
          ?
        \else:
          \char_generate:nn {#1} {12}
        \fi:
      }
    \__kernel_msg_new:nnnn { str } { native-overflow }
      { Character~code~too~large~for~this~engine. }
      {
        This~engine~only~support~8-bit~characters:~
        valid~character~codes~are~in~the~range~[0,255].~
        To~manipulate~arbitrary~Unicode,~use~LuaTeX~or~XeTeX.
      }
  }
\cs_new_protected:Npn \__str_convert_decode_clist:
  {
    \clist_gset:No \g__str_result_tl \g__str_result_tl
    \tl_gset:Nx \g__str_result_tl
      {
        \exp_args:No \clist_map_function:nN
          \g__str_result_tl \__str_decode_clist_char:n
      }
  }
\cs_new:Npn \__str_decode_clist_char:n #1
  { #1 \s__tl \int_eval:n {#1} \s__tl }
\cs_new_protected:Npn \__str_convert_encode_clist:
  {
    \__str_convert_gmap_internal:N \__str_encode_clist_char:n
    \tl_gset:Nx \g__str_result_tl { \tl_tail:N \g__str_result_tl }
  }
\cs_new:Npn \__str_encode_clist_char:n #1 { , #1 }
\cs_new_protected:Npn \__str_declare_eight_bit_encoding:nnn #1#2#3
  {
    \tl_set:Nn \l__str_internal_tl {#1}
    \cs_new_protected:cpn { __str_convert_decode_#1: }
      { \__str_convert_decode_eight_bit:n {#1} }
    \cs_new_protected:cpn { __str_convert_encode_#1: }
      { \__str_convert_encode_eight_bit:n {#1} }
    \tl_const:cn { c__str_encoding_#1_tl } {#2}
    \tl_const:cn { c__str_encoding_#1_missing_tl } {#3}
  }
\cs_new_protected:Npn \__str_convert_decode_eight_bit:n #1
  {
    \group_begin:
      \int_zero:N \l__str_internal_int
      \exp_last_unbraced:Nx \__str_decode_eight_bit_load:nn
        { \tl_use:c { c__str_encoding_#1_tl } }
        { \q_stop \prg_break: } { }
      \prg_break_point:
      \exp_last_unbraced:Nx \__str_decode_eight_bit_load_missing:n
        { \tl_use:c { c__str_encoding_#1_missing_tl } }
        { \q_stop \prg_break: }
      \prg_break_point:
      \flag_clear:n { str_error }
      \__str_convert_gmap:N \__str_decode_eight_bit_char:N
      \__str_if_flag_error:nnx { str_error } { decode-8-bit } {#1}
    \group_end:
  }
\cs_new_protected:Npn \__str_decode_eight_bit_load:nn #1#2
  {
    \use_none_delimit_by_q_stop:w #1 \q_stop
    \tex_dimen:D "#1 = \l__str_internal_int sp \scan_stop:
    \tex_skip:D \l__str_internal_int = "#1 sp \scan_stop:
    \tex_toks:D \l__str_internal_int \exp_after:wN { \int_value:w "#2 }
    \int_incr:N \l__str_internal_int
    \__str_decode_eight_bit_load:nn
  }
\cs_new_protected:Npn \__str_decode_eight_bit_load_missing:n #1
  {
    \use_none_delimit_by_q_stop:w #1 \q_stop
    \tex_dimen:D "#1 = \l__str_internal_int sp \scan_stop:
    \tex_skip:D \l__str_internal_int = "#1 sp \scan_stop:
    \tex_toks:D \l__str_internal_int \exp_after:wN
      { \int_use:N \c__str_replacement_char_int }
    \int_incr:N \l__str_internal_int
    \__str_decode_eight_bit_load_missing:n
  }
\cs_new:Npn \__str_decode_eight_bit_char:N #1
  {
    #1 \s__tl
    \if_int_compare:w \tex_dimen:D `#1 < \l__str_internal_int
      \if_int_compare:w \tex_skip:D \tex_dimen:D `#1 = `#1 \exp_stop_f:
        \tex_the:D \tex_toks:D \tex_dimen:D
      \fi:
    \fi:
    \int_value:w `#1 \s__tl
  }
\cs_new_protected:Npn \__str_convert_encode_eight_bit:n #1
  {
    \group_begin:
      \int_zero:N \l__str_internal_int
      \exp_last_unbraced:Nx \__str_encode_eight_bit_load:nn
        { \tl_use:c { c__str_encoding_#1_tl } }
        { \q_stop \prg_break: } { }
      \prg_break_point:
      \flag_clear:n { str_error }
      \__str_convert_gmap_internal:N \__str_encode_eight_bit_char:n
      \__str_if_flag_error:nnx { str_error } { encode-8-bit } {#1}
    \group_end:
  }
\cs_new_protected:Npn \__str_encode_eight_bit_load:nn #1#2
  {
    \use_none_delimit_by_q_stop:w #1 \q_stop
    \tex_dimen:D "#2 = \l__str_internal_int sp \scan_stop:
    \tex_skip:D \l__str_internal_int = "#2 sp \scan_stop:
    \exp_args:NNf \tex_toks:D \l__str_internal_int
      { \__str_output_byte:n { "#1 } }
    \int_incr:N \l__str_internal_int
    \__str_encode_eight_bit_load:nn
  }
\cs_new:Npn \__str_encode_eight_bit_char:n #1
  {
    \if_int_compare:w #1 > \c_max_register_int
      \flag_raise:n { str_error }
    \else:
      \if_int_compare:w \tex_dimen:D #1 < \l__str_internal_int
        \if_int_compare:w \tex_skip:D \tex_dimen:D #1 = #1 \exp_stop_f:
          \tex_the:D \tex_toks:D \tex_dimen:D #1 \exp_stop_f:
          \exp_after:wN \exp_after:wN \exp_after:wN \use_none:nn
        \fi:
      \fi:
      \__str_encode_eight_bit_char_aux:n {#1}
    \fi:
  }
\cs_new:Npn \__str_encode_eight_bit_char_aux:n #1
  {
    \if_int_compare:w #1 > \c__str_max_byte_int
      \flag_raise:n { str_error }
    \else:
      \__str_output_byte:n {#1}
    \fi:
  }
\__kernel_msg_new:nnn { str } { unknown-esc }
  { Escaping~scheme~'#1'~(filtered:~'#2')~unknown. }
\__kernel_msg_new:nnn { str } { unknown-enc }
  { Encoding~scheme~'#1'~(filtered:~'#2')~unknown. }
\__kernel_msg_new:nnnn { str } { native-escaping }
  { The~'native'~encoding~scheme~does~not~support~any~escaping. }
  {
    Since~native~strings~do~not~consist~in~bytes,~
    none~of~the~escaping~methods~make~sense.~
    The~specified~escaping,~'#1',~will be ignored.
  }
\__kernel_msg_new:nnn { str } { file-not-found }
  { File~'l3str-#1.def'~not~found. }
\bool_lazy_any:nT
  {
    \sys_if_engine_luatex_p:
    \sys_if_engine_xetex_p:
  }
  {
    \__kernel_msg_new:nnnn { str } { non-byte }
      { String~invalid~in~escaping~'#1':~it~may~only~contain~bytes. }
      {
        Some~characters~in~the~string~you~asked~to~convert~are~not~
        8-bit~characters.~Perhaps~the~string~is~a~'native'~Unicode~string?~
        If~it~is,~try~using\\
        \\
        \iow_indent:n
          {
            \iow_char:N\\str_set_convert:Nnnn \\
            \ \ <str~var>~\{~<string>~\}~\{~native~\}~\{~<target~encoding>~\}
          }
      }
  }
\__kernel_msg_new:nnnn { str } { decode-8-bit }
  { Invalid~string~in~encoding~'#1'. }
  {
    LaTeX~came~across~a~byte~which~is~not~defined~to~represent~
    any~character~in~the~encoding~'#1'.
  }
\__kernel_msg_new:nnnn { str } { encode-8-bit }
  { Unicode~string~cannot~be~converted~to~encoding~'#1'. }
  {
    The~encoding~'#1'~only~contains~a~subset~of~all~Unicode~characters.~
    LaTeX~was~asked~to~convert~a~string~to~that~encoding,~but~that~
    string~contains~a~character~that~'#1'~does~not~support.
  }
%% 
%%
%% End of file `l3str-convert.sty'.
