%%
%% This is file `l3str-enc-utf32.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3str-convert.dtx  (with options: `utf32')
%% 
%% Copyright (C) 2011-2016 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-2017 The LaTeX3 Project
\group_begin:
  \char_set_catcode_other:N \^^00
  \char_set_catcode_other:N \^^fe
  \char_set_catcode_other:N \^^ff
  \cs_new_protected:cpn { __str_convert_encode_utf32: }
    {
      \__str_convert_gmap_internal:N \__str_encode_utf_xxxii_be:n
      \tl_gput_left:Nx \g__str_result_tl { ^^00 ^^00 ^^fe ^^ff }
    }
  \cs_new_protected:cpn { __str_convert_encode_utf32be: }
    { \__str_convert_gmap_internal:N \__str_encode_utf_xxxii_be:n }
  \cs_new_protected:cpn { __str_convert_encode_utf32le: }
    { \__str_convert_gmap_internal:N \__str_encode_utf_xxxii_le:n }
  \cs_new:Npn \__str_encode_utf_xxxii_be:n #1
    {
      \exp_args:Nf \__str_encode_utf_xxxii_be_aux:nn
        { \int_div_truncate:nn {#1} { "100 } } {#1}
    }
  \cs_new:Npn \__str_encode_utf_xxxii_be_aux:nn #1#2
    {
      ^^00
      \__str_output_byte_pair_be:n {#1}
      \__str_output_byte:n { #2 - #1 * "100 }
    }
  \cs_new:Npn \__str_encode_utf_xxxii_le:n #1
    {
      \exp_args:Nf \__str_encode_utf_xxxii_le_aux:nn
        { \int_div_truncate:nn {#1} { "100 } } {#1}
    }
  \cs_new:Npn \__str_encode_utf_xxxii_le_aux:nn #1#2
    {
      \__str_output_byte:n { #2 - #1 * "100 }
      \__str_output_byte_pair_le:n {#1}
      ^^00
    }
  \flag_clear_new:n { str_overflow }
  \flag_clear_new:n { str_end }
  \__msg_kernel_new:nnnn { str } { utf32-decode }
    {
      Invalid~UTF-32~string: \exp_last_unbraced:Nf \use_none:n
      \__str_if_flag_times:nT { str_overflow } { ,~code~point~too~large }
      \__str_if_flag_times:nT { str_end }      { ,~truncated~string }
      .
    }
    {
      In~the~UTF-32~encoding,~every~Unicode~character~
      (in~the~range~[U+0000,~U+10FFFF])~is~encoded~as~4~bytes.
      \flag_if_raised:nT { str_overflow }
        {
          \\\\
          LaTeX~came~across~a~code~point~larger~than~1114111,~
          the~maximum~code~point~defined~by~Unicode.~
          Perhaps~the~string~was~not~encoded~in~the~UTF-32~encoding?
        }
      \flag_if_raised:nT { str_end }
        {
          \\\\
          The~length~of~the~string~is~not~a~multiple~of~4.~
          Perhaps~the~string~was~truncated?
        }
    }
  \cs_new_protected:cpn { __str_convert_decode_utf32be: }
    { \__str_decode_utf_xxxii:Nw 1 \g__str_result_tl \s__stop }
  \cs_new_protected:cpn { __str_convert_decode_utf32le: }
    { \__str_decode_utf_xxxii:Nw 2 \g__str_result_tl \s__stop }
  \cs_new_protected:cpn { __str_convert_decode_utf32: }
    {
      \exp_after:wN \__str_decode_utf_xxxii_bom:NNNN \g__str_result_tl
        \s__stop \s__stop \s__stop \s__stop \s__stop
    }
  \cs_new_protected:Npn \__str_decode_utf_xxxii_bom:NNNN #1#2#3#4
    {
      \str_if_eq_x:nnTF { #1#2#3#4 } { ^^ff ^^fe ^^00 ^^00 }
        { \__str_decode_utf_xxxii:Nw 2 }
        {
          \str_if_eq_x:nnTF { #1#2#3#4 } { ^^00 ^^00 ^^fe ^^ff }
            { \__str_decode_utf_xxxii:Nw 1 }
            { \__str_decode_utf_xxxii:Nw 1 #1#2#3#4 }
        }
    }
  \cs_new_protected:Npn \__str_decode_utf_xxxii:Nw #1#2 \s__stop
    {
      \flag_clear:n { str_overflow }
      \flag_clear:n { str_end }
      \flag_clear:n { str_error }
      \cs_set:Npn \__str_tmp:w ##1 ##2 { ` ## #1 }
      \tl_gset:Nx \g__str_result_tl
        {
          \exp_after:wN \__str_decode_utf_xxxii_loop:NNNN
            #2 \s__stop \s__stop \s__stop \s__stop
          \__prg_break_point:
        }
      \__str_if_flag_error:nnx { str_error } { utf32-decode } { }
    }
  \cs_new:Npn \__str_decode_utf_xxxii_loop:NNNN #1#2#3#4
    {
      \if_meaning:w \s__stop #4
        \exp_after:wN \__str_decode_utf_xxxii_end:w
      \fi:
      #1#2#3#4 \s__tl
      \if_int_compare:w \__str_tmp:w #1#4 > 0 \exp_stop_f:
        \flag_raise:n { str_overflow }
        \flag_raise:n { str_error }
        \int_use:N \c__str_replacement_char_int
      \else:
        \if_int_compare:w \__str_tmp:w #2#3 > 16 \exp_stop_f:
          \flag_raise:n { str_overflow }
          \flag_raise:n { str_error }
          \int_use:N \c__str_replacement_char_int
        \else:
          \int_eval:n
            { \__str_tmp:w #2#3*"10000 + \__str_tmp:w #3#2*"100 + \__str_tmp:w #4#1 }
        \fi:
      \fi:
      \s__tl
      \__str_decode_utf_xxxii_loop:NNNN
    }
  \cs_new:Npn \__str_decode_utf_xxxii_end:w #1 \s__stop
    {
      \tl_if_empty:nF {#1}
        {
          \flag_raise:n { str_end }
          \flag_raise:n { str_error }
          #1 \s__tl
          \int_use:N \c__str_replacement_char_int \s__tl
        }
      \__prg_break:
    }
\group_end:
%% 
%%
%% End of file `l3str-enc-utf32.def'.
