summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str-enc-utf32.def
blob: c1c2c5ca59554dff9ae3d21e158a6ac1c01f60fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
%%
%% 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-2017 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'.