| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3str-convert.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2013-2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% https://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "l3kernel bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/latex3 |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\documentclass[full,kernel]{l3doc} |
| 27 |
\begin{document} |
| 28 |
\DocInput{\jobname.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% \fi |
| 32 |
% |
| 33 |
% |
| 34 |
% \title{^^A |
| 35 |
% The \pkg{l3str-convert} module\\ String encoding conversions^^A |
| 36 |
% } |
| 37 |
% |
| 38 |
% \author{^^A |
| 39 |
% The \LaTeX{} Project\thanks |
| 40 |
% {^^A |
| 41 |
% E-mail: |
| 42 |
% \href{mailto:[email protected]} |
| 43 |
% {[email protected]}^^A |
| 44 |
% }^^A |
| 45 |
% } |
| 46 |
% |
| 47 |
% \date{Released 2026-05-15} |
| 48 |
% |
| 49 |
% \maketitle |
| 50 |
% |
| 51 |
% \begin{documentation} |
| 52 |
% |
| 53 |
% \section{Encoding and escaping schemes} |
| 54 |
% |
| 55 |
% Traditionally, string encodings only specify how strings of characters |
| 56 |
% should be stored as bytes. However, the resulting lists of bytes are |
| 57 |
% often to be used in contexts where only a restricted subset of bytes |
| 58 |
% are permitted (\emph{e.g.}, \textsc{pdf} string objects, |
| 59 |
% \textsc{url}s). Hence, storing a string of characters is done in two |
| 60 |
% steps. |
| 61 |
% \begin{itemize} |
| 62 |
% \item The code points (\enquote{character codes}) are expressed as |
| 63 |
% bytes following a given \enquote{encoding}. This can be |
| 64 |
% \textsc{utf-16}, \textsc{iso 8859-1}, etc. See |
| 65 |
% Table~\ref{tab:encodings} for a list of supported |
| 66 |
% encodings.\footnote{Encodings and escapings will be added as they |
| 67 |
% are requested.} |
| 68 |
% \item Bytes are translated to \TeX{} tokens through a given |
| 69 |
% \enquote{escaping}. Those are defined for the most part by the |
| 70 |
% \texttt{pdf} file format. See Table~\ref{tab:escapings} for a |
| 71 |
% list of escaping methods supported.\footnotemark[\csname c@footnote\endcsname] |
| 72 |
% \end{itemize} |
| 73 |
% |
| 74 |
% \begin{table}\centering |
| 75 |
% \caption{\label{tab:encodings}Supported encodings. |
| 76 |
% Non-alphanumeric characters are ignored, |
| 77 |
% and capital letters are lower-cased |
| 78 |
% before searching for the encoding in this list.} |
| 79 |
% \begin{tabular}{cc} |
| 80 |
% \toprule |
| 81 |
% \meta{Encoding} & description \\ |
| 82 |
% \midrule |
| 83 |
% \texttt{utf8} & \textsc{utf-8} \\ |
| 84 |
% \texttt{utf16} & \textsc{utf-16}, with byte-order mark \\ |
| 85 |
% \texttt{utf16be} & \textsc{utf-16}, big-endian \\ |
| 86 |
% \texttt{utf16le} & \textsc{utf-16}, little-endian \\ |
| 87 |
% \texttt{utf32} & \textsc{utf-32}, with byte-order mark \\ |
| 88 |
% \texttt{utf32be} & \textsc{utf-32}, big-endian \\ |
| 89 |
% \texttt{utf32le} & \textsc{utf-32}, little-endian \\ |
| 90 |
% \midrule |
| 91 |
% \texttt{iso88591}, \texttt{latin1} & \textsc{iso 8859-1} \\ |
| 92 |
% \texttt{iso88592}, \texttt{latin2} & \textsc{iso 8859-2} \\ |
| 93 |
% \texttt{iso88593}, \texttt{latin3} & \textsc{iso 8859-3} \\ |
| 94 |
% \texttt{iso88594}, \texttt{latin4} & \textsc{iso 8859-4} \\ |
| 95 |
% \texttt{iso88595} & \textsc{iso 8859-5} \\ |
| 96 |
% \texttt{iso88596} & \textsc{iso 8859-6} \\ |
| 97 |
% \texttt{iso88597} & \textsc{iso 8859-7} \\ |
| 98 |
% \texttt{iso88598} & \textsc{iso 8859-8} \\ |
| 99 |
% \texttt{iso88599}, \texttt{latin5} & \textsc{iso 8859-9} \\ |
| 100 |
% \texttt{iso885910}, \texttt{latin6} & \textsc{iso 8859-10} \\ |
| 101 |
% \texttt{iso885911} & \textsc{iso 8859-11} \\ |
| 102 |
% \texttt{iso885913}, \texttt{latin7} & \textsc{iso 8859-13} \\ |
| 103 |
% \texttt{iso885914}, \texttt{latin8} & \textsc{iso 8859-14} \\ |
| 104 |
% \texttt{iso885915}, \texttt{latin9} & \textsc{iso 8859-15} \\ |
| 105 |
% \texttt{iso885916}, \texttt{latin10} & \textsc{iso 8859-16} \\ |
| 106 |
% \midrule |
| 107 |
% \texttt{clist} & comma-list of integers \\ |
| 108 |
% \meta{empty} & native (Unicode) string \\ |
| 109 |
% \texttt{default} & like \texttt{utf8} with 8-bit engines, |
| 110 |
% and like native with unicode-engines \\ |
| 111 |
% \bottomrule |
| 112 |
% \end{tabular} |
| 113 |
% \end{table} |
| 114 |
% |
| 115 |
% \begin{table}\centering |
| 116 |
% \caption{\label{tab:escapings}Supported escapings. |
| 117 |
% Non-alphanumeric characters are ignored, |
| 118 |
% and capital letters are lower-cased |
| 119 |
% before searching for the escaping in this list.} |
| 120 |
% \begin{tabular}{cc} |
| 121 |
% \toprule |
| 122 |
% \meta{Escaping} & description \\ |
| 123 |
% \midrule |
| 124 |
% \texttt{bytes}, or empty |
| 125 |
% & arbitrary bytes \\ |
| 126 |
% \texttt{hex}, \texttt{hexadecimal} |
| 127 |
% & byte $=$ two hexadecimal digits \\ |
| 128 |
% \texttt{name} |
| 129 |
% & see \tn{pdfescapename} \\ |
| 130 |
% \texttt{string} |
| 131 |
% & see \tn{pdfescapestring} \\ |
| 132 |
% \texttt{url} |
| 133 |
% & encoding used in \textsc{url}s \\ |
| 134 |
% \bottomrule |
| 135 |
% \end{tabular} |
| 136 |
% \end{table} |
| 137 |
% |
| 138 |
% \section{Conversion functions} |
| 139 |
% |
| 140 |
% \begin{function}{\str_set_convert:Nnnn, \str_gset_convert:Nnnn} |
| 141 |
% \begin{syntax} |
| 142 |
% \cs{str_set_convert:Nnnn} \meta{str~var} \Arg{string} \Arg{name_1} \Arg{name_2} |
| 143 |
% \end{syntax} |
| 144 |
% This function converts the \meta{string} from the encoding given by |
| 145 |
% \meta{name_1} to the encoding given by \meta{name_2}, and stores the |
| 146 |
% result in the \meta{str~var}. Each \meta{name} can have the form |
| 147 |
% \meta{encoding} or \meta{encoding}\texttt{/}\meta{escaping}, where |
| 148 |
% the possible values of \meta{encoding} and \meta{escaping} are given |
| 149 |
% in Tables~\ref{tab:encodings} and~\ref{tab:escapings}, respectively. |
| 150 |
% The default escaping is to input and output bytes directly. The |
| 151 |
% special case of an empty \meta{name} indicates the use of |
| 152 |
% \enquote{native} strings, 8-bit for \pdfTeX{}, and Unicode strings |
| 153 |
% for the other two engines. |
| 154 |
% |
| 155 |
% For example, |
| 156 |
% \begin{verbatim} |
| 157 |
% \str_set_convert:Nnnn \l_foo_str { Hello! } { } { utf16/hex } |
| 158 |
% \end{verbatim} |
| 159 |
% results in the variable \cs[no-index]{l_foo_str} holding the string |
| 160 |
% \texttt{FEFF00480065006C006C006F0021}. This is obtained by |
| 161 |
% converting each character in the (native) string \texttt{Hello!} to |
| 162 |
% the \textsc{utf-16} encoding, and expressing each byte as a pair of |
| 163 |
% hexadecimal digits. Note the presence of a (big-endian) byte order |
| 164 |
% mark \hexnum{FEFF}, which can be avoided by specifying the encoding |
| 165 |
% \texttt{utf16be/hex}. |
| 166 |
% |
| 167 |
% An error is raised if the \meta{string} is not valid according to |
| 168 |
% the \meta{escaping~1} and \meta{encoding~1}, or if it cannot be |
| 169 |
% reencoded in the \meta{encoding~2} and \meta{escaping~2} (for |
| 170 |
% instance, if a character does not exist in the \meta{encoding~2}). |
| 171 |
% Erroneous input is replaced by the Unicode replacement character |
| 172 |
% \hexnum{FFFD}, and characters which cannot be reencoded are replaced |
| 173 |
% by either the replacement character \hexnum{FFFD} if it exists in |
| 174 |
% the \meta{encoding~2}, or an encoding-specific replacement |
| 175 |
% character, or the question mark character. |
| 176 |
% \end{function} |
| 177 |
% |
| 178 |
% \begin{function}[TF]{\str_set_convert:Nnnn, \str_gset_convert:Nnnn} |
| 179 |
% \begin{syntax} |
| 180 |
% \cs{str_set_convert:NnnnTF} \meta{str~var} \Arg{string} \Arg{name_1} \Arg{name_2} \Arg{true code} \Arg{false code} |
| 181 |
% \end{syntax} |
| 182 |
% As \cs{str_set_convert:Nnnn}, converts the \meta{string} from the |
| 183 |
% encoding given by \meta{name_1} to the encoding given by |
| 184 |
% \meta{name_2}, and assigns the result to \meta{str~var}. Contrarily |
| 185 |
% to \cs{str_set_convert:Nnnn}, the conditional variant does not raise |
| 186 |
% errors in case the \meta{string} is not valid according to the |
| 187 |
% \meta{name_1} encoding, or cannot be expressed in the \meta{name_2} |
| 188 |
% encoding. Instead, the \meta{false code} is performed. |
| 189 |
% \end{function} |
| 190 |
% |
| 191 |
% \subsection{Engine considerations} |
| 192 |
% |
| 193 |
% The treatment of bytes by pdf\TeX{}, \XeTeX{} and Lua\TeX{} is uniform: |
| 194 |
% either input is tokenized as bytes or as codepoints. However, the Japanese |
| 195 |
% engines p\TeX{} and up\TeX{} are more complex. Support for p\TeX{} in |
| 196 |
% \pkg{expl3} is limited to the \textsc{ascii} range only. For up\TeX{}, |
| 197 |
% the \texttt{utf8} conversion is modified to better support the engine |
| 198 |
% behavior. This means that the input is handled as bytes \emph{unless} |
| 199 |
% the input is tokenized by the engine as a Japanese character (one with |
| 200 |
% \tn{kcatcode} above 15): these are left as single tokens. |
| 201 |
% |
| 202 |
% \section{Conversion by expansion (for PDF contexts)} |
| 203 |
% |
| 204 |
% A small number of expandable functions are provided for use in PDF string/name |
| 205 |
% contexts. These \emph{assume UTF-8} and \emph{no escaping} in the input. |
| 206 |
% |
| 207 |
% \begin{function}[EXP]{\str_convert_pdfname:n} |
| 208 |
% \begin{syntax} |
| 209 |
% \cs{str_convert_pdfname:n} \Arg{string} |
| 210 |
% \end{syntax} |
| 211 |
% As \cs{str_set_convert:Nnnn}, converts the \meta{string} on a byte-by-byte |
| 212 |
% basis with non-ASCII codepoints escaped using hashes. |
| 213 |
% \end{function} |
| 214 |
% |
| 215 |
% \section{Possibilities, and things to do} |
| 216 |
% |
| 217 |
% Encoding/escaping-related tasks. |
| 218 |
% \begin{itemize} |
| 219 |
% \item In \XeTeX{}/\LuaTeX{}, would it be better to use the |
| 220 |
% |^^^^....| approach to build a string from a given list of |
| 221 |
% character codes? Namely, within a group, assign |0-9a-f| and all |
| 222 |
% characters we want to category ``other'', then assign~|^| the |
| 223 |
% category superscript, and use \tn{scantokens}. |
| 224 |
% \item Change \cs{str_set_convert:Nnnn} to expand its last two |
| 225 |
% arguments. |
| 226 |
% \item Describe the internal format in the code comments. Refuse code |
| 227 |
% points in $[\hexnum{D800}, \hexnum{DFFF}]$ in the internal |
| 228 |
% representation? |
| 229 |
% \item Add documentation about each encoding and escaping method, and |
| 230 |
% add examples. |
| 231 |
% \item The \texttt{hex} unescaping should raise an error for |
| 232 |
% odd-token count strings. |
| 233 |
% \item Decide what bytes should be escaped in the \texttt{url} |
| 234 |
% escaping. Perhaps the characters |!'()*-./0123456789_| are safe, |
| 235 |
% and all other characters should be escaped? |
| 236 |
% \item Automate generation of 8-bit mapping files. |
| 237 |
% \item Change the framework for 8-bit encodings: for decoding from |
| 238 |
% 8-bit to Unicode, use $256$ integer registers; for encoding, use a |
| 239 |
% tree-box. |
| 240 |
% \item More encodings (see Heiko's \pkg{stringenc}). CESU? |
| 241 |
% \item More escapings: \textsc{ascii85}, shell escapes, lua escapes, |
| 242 |
% etc.? |
| 243 |
% \end{itemize} |
| 244 |
% |
| 245 |
% \end{documentation} |
| 246 |
% |
| 247 |
% \begin{implementation} |
| 248 |
% |
| 249 |
% \section{\pkg{l3str-convert} implementation} |
| 250 |
% |
| 251 |
% \begin{macrocode} |
| 252 |
%<*code> |
| 253 |
% \end{macrocode} |
| 254 |
% |
| 255 |
% \begin{macrocode} |
| 256 |
%<@@=str> |
| 257 |
% \end{macrocode} |
| 258 |
% |
| 259 |
% \subsection{Helpers} |
| 260 |
% |
| 261 |
% \subsubsection{Variables and constants} |
| 262 |
% |
| 263 |
% \begin{macro}{\@@_tmp:w} |
| 264 |
% \begin{variable}{\l_@@_tmp_tl} |
| 265 |
% Internal scratch space for some functions. |
| 266 |
% \begin{macrocode} |
| 267 |
\cs_new_protected:Npn \@@_tmp:w { } |
| 268 |
\tl_new:N \l_@@_tmp_tl |
| 269 |
% \end{macrocode} |
| 270 |
% \end{variable} |
| 271 |
% \end{macro} |
| 272 |
% |
| 273 |
% \begin{variable}{\g_@@_result_tl} |
| 274 |
% The \cs{g_@@_result_tl} variable is used to hold the result of |
| 275 |
% various internal string operations (mostly conversions) which are |
| 276 |
% typically performed in a group. The variable is global so that it |
| 277 |
% remains defined outside the group, to be assigned to a user-provided |
| 278 |
% variable. |
| 279 |
% \begin{macrocode} |
| 280 |
\tl_new:N \g_@@_result_tl |
| 281 |
% \end{macrocode} |
| 282 |
% \end{variable} |
| 283 |
% |
| 284 |
% \begin{variable}{\c_@@_replacement_char_int} |
| 285 |
% When converting, invalid bytes are replaced by the Unicode |
| 286 |
% replacement character \hexnum{FFFD}. |
| 287 |
% \begin{macrocode} |
| 288 |
\int_const:Nn \c_@@_replacement_char_int { "FFFD } |
| 289 |
% \end{macrocode} |
| 290 |
% \end{variable} |
| 291 |
% |
| 292 |
% \begin{variable}{\c_@@_max_byte_int} |
| 293 |
% The maximal byte number. |
| 294 |
% \begin{macrocode} |
| 295 |
\int_const:Nn \c_@@_max_byte_int { 255 } |
| 296 |
% \end{macrocode} |
| 297 |
% \end{variable} |
| 298 |
% |
| 299 |
% \begin{variable}{\s_@@} |
| 300 |
% Internal scan marks. |
| 301 |
% \begin{macrocode} |
| 302 |
\scan_new:N \s_@@ |
| 303 |
% \end{macrocode} |
| 304 |
% \end{variable} |
| 305 |
% |
| 306 |
% \begin{variable}{\q_@@_nil} |
| 307 |
% Internal quarks. |
| 308 |
% \begin{macrocode} |
| 309 |
\quark_new:N \q_@@_nil |
| 310 |
% \end{macrocode} |
| 311 |
% \end{variable} |
| 312 |
% |
| 313 |
% \begin{variable}{\g_@@_alias_prop} |
| 314 |
% To avoid needing one file per encoding/escaping alias, we keep track |
| 315 |
% of those in a property list. |
| 316 |
% \begin{macrocode} |
| 317 |
\prop_new:N \g_@@_alias_prop |
| 318 |
\prop_gput:Nnn \g_@@_alias_prop { latin1 } { iso88591 } |
| 319 |
\prop_gput:Nnn \g_@@_alias_prop { latin2 } { iso88592 } |
| 320 |
\prop_gput:Nnn \g_@@_alias_prop { latin3 } { iso88593 } |
| 321 |
\prop_gput:Nnn \g_@@_alias_prop { latin4 } { iso88594 } |
| 322 |
\prop_gput:Nnn \g_@@_alias_prop { latin5 } { iso88599 } |
| 323 |
\prop_gput:Nnn \g_@@_alias_prop { latin6 } { iso885910 } |
| 324 |
\prop_gput:Nnn \g_@@_alias_prop { latin7 } { iso885913 } |
| 325 |
\prop_gput:Nnn \g_@@_alias_prop { latin8 } { iso885914 } |
| 326 |
\prop_gput:Nnn \g_@@_alias_prop { latin9 } { iso885915 } |
| 327 |
\prop_gput:Nnn \g_@@_alias_prop { latin10 } { iso885916 } |
| 328 |
\prop_gput:Nnn \g_@@_alias_prop { utf16le } { utf16 } |
| 329 |
\prop_gput:Nnn \g_@@_alias_prop { utf16be } { utf16 } |
| 330 |
\prop_gput:Nnn \g_@@_alias_prop { utf32le } { utf32 } |
| 331 |
\prop_gput:Nnn \g_@@_alias_prop { utf32be } { utf32 } |
| 332 |
\prop_gput:Nnn \g_@@_alias_prop { hexadecimal } { hex } |
| 333 |
\bool_lazy_any:nTF |
| 334 |
{ |
| 335 |
\sys_if_engine_luatex_p: |
| 336 |
\sys_if_engine_xetex_p: |
| 337 |
} |
| 338 |
{ |
| 339 |
\prop_gput:Nnn \g_@@_alias_prop { default } { } |
| 340 |
} |
| 341 |
{ |
| 342 |
\prop_gput:Nnn \g_@@_alias_prop { default } { utf8 } |
| 343 |
} |
| 344 |
% \end{macrocode} |
| 345 |
% \end{variable} |
| 346 |
% |
| 347 |
% \begin{variable}{\g_@@_error_bool} |
| 348 |
% In conversion functions with a built-in conditional, errors are not |
| 349 |
% reported directly to the user, but the information is collected in |
| 350 |
% this boolean, used at the end to decide on which branch of the |
| 351 |
% conditional to take. |
| 352 |
% \begin{macrocode} |
| 353 |
\bool_new:N \g_@@_error_bool |
| 354 |
% \end{macrocode} |
| 355 |
% \end{variable} |
| 356 |
% |
| 357 |
% \begin{variable}{\l_@@_byte_flag, \l_@@_error_flag} |
| 358 |
% Conversions from one \meta{encoding}/\meta{escaping} pair to another |
| 359 |
% are done within \texttt{e}-expanding assignments. Errors are |
| 360 |
% signaled by raising the relevant flag. |
| 361 |
% \begin{macrocode} |
| 362 |
\flag_new:N \l_@@_byte_flag |
| 363 |
\flag_new:N \l_@@_error_flag |
| 364 |
% \end{macrocode} |
| 365 |
% \end{variable} |
| 366 |
% |
| 367 |
% \subsection{String conditionals} |
| 368 |
% |
| 369 |
% \begin{macro}[EXP]{\@@_if_contains_char:NnT, \@@_if_contains_char:NnTF} |
| 370 |
% \begin{macro}[EXP]{\@@_if_contains_char:nnTF} |
| 371 |
% \begin{macro}[EXP]{\@@_if_contains_char_aux:nn,\@@_if_contains_char_auxi:nN} |
| 372 |
% \begin{macro}[EXP]{\@@_if_contains_char_true:} |
| 373 |
% \begin{syntax} |
| 374 |
% \cs{@@_if_contains_char:nnTF} \Arg{token list} \meta{char} |
| 375 |
% \end{syntax} |
| 376 |
% Expects the \meta{token list} to be an \meta{other string}: the |
| 377 |
% caller is responsible for ensuring that no (too-)special catcodes |
| 378 |
% remain. |
| 379 |
% Loop over the characters of the string, comparing character codes. |
| 380 |
% The loop is broken if character codes match. Otherwise we return |
| 381 |
% \enquote{false}. |
| 382 |
% \begin{macrocode} |
| 383 |
\prg_new_conditional:Npnn \@@_if_contains_char:Nn #1#2 { T , TF } |
| 384 |
{ |
| 385 |
\exp_after:wN \@@_if_contains_char_aux:nn \exp_after:wN {#1} {#2} |
| 386 |
{ \prg_break:n { ? \fi: } } |
| 387 |
\prg_break_point: |
| 388 |
\prg_return_false: |
| 389 |
} |
| 390 |
\cs_new:Npn \@@_if_contains_char_aux:nn #1#2 |
| 391 |
{ \@@_if_contains_char_auxi:nN {#2} #1 } |
| 392 |
\prg_new_conditional:Npnn \@@_if_contains_char:nn #1#2 { TF } |
| 393 |
{ |
| 394 |
\@@_if_contains_char_auxi:nN {#2} #1 { \prg_break:n { ? \fi: } } |
| 395 |
\prg_break_point: |
| 396 |
\prg_return_false: |
| 397 |
} |
| 398 |
\cs_new:Npn \@@_if_contains_char_auxi:nN #1#2 |
| 399 |
{ |
| 400 |
\if_charcode:w #1 #2 |
| 401 |
\exp_after:wN \@@_if_contains_char_true: |
| 402 |
\fi: |
| 403 |
\@@_if_contains_char_auxi:nN {#1} |
| 404 |
} |
| 405 |
\cs_new:Npn \@@_if_contains_char_true: |
| 406 |
{ \prg_break:n { \prg_return_true: \use_none:n } } |
| 407 |
% \end{macrocode} |
| 408 |
% \end{macro} |
| 409 |
% \end{macro} |
| 410 |
% \end{macro} |
| 411 |
% \end{macro} |
| 412 |
% |
| 413 |
% \begin{macro}[rEXP]{\@@_octal_use:NTF} |
| 414 |
% \begin{syntax} |
| 415 |
% \cs{@@_octal_use:NTF} \meta{token} \Arg{true code} \Arg{false code} |
| 416 |
% \end{syntax} |
| 417 |
% If the \meta{token} is an octal digit, it is left in the input |
| 418 |
% stream, \emph{followed} by the \meta{true code}. Otherwise, the |
| 419 |
% \meta{false code} is left in the input stream. |
| 420 |
% \begin{texnote} |
| 421 |
% This function will fail if the escape character is an octal |
| 422 |
% digit. We are thus careful to set the escape character to a known |
| 423 |
% value before using it. |
| 424 |
% \end{texnote} |
| 425 |
% \TeX{} dutifully detects octal digits for us: if |#1| is an octal |
| 426 |
% digit, then the right-hand side of the comparison is |'1#1|, greater |
| 427 |
% than $1$. Otherwise, the right-hand side stops as |'1|, and the |
| 428 |
% conditional takes the \texttt{false} branch. |
| 429 |
% \begin{macrocode} |
| 430 |
\prg_new_conditional:Npnn \@@_octal_use:N #1 { TF } |
| 431 |
{ |
| 432 |
\if_int_compare:w 1 < '1 \token_to_str:N #1 \exp_stop_f: |
| 433 |
#1 \prg_return_true: |
| 434 |
\else: |
| 435 |
\prg_return_false: |
| 436 |
\fi: |
| 437 |
} |
| 438 |
% \end{macrocode} |
| 439 |
% \end{macro} |
| 440 |
% |
| 441 |
% \begin{macro}[rEXP]{\@@_hexadecimal_use:NTF} |
| 442 |
% \TeX{} detects uppercase hexadecimal digits for us (see |
| 443 |
% \cs{@@_octal_use:NTF}), but not the lowercase letters, which we |
| 444 |
% need to detect and replace by their uppercase counterpart. |
| 445 |
% \begin{macrocode} |
| 446 |
\prg_new_conditional:Npnn \@@_hexadecimal_use:N #1 { TF } |
| 447 |
{ |
| 448 |
\if_int_compare:w 1 < "1 \token_to_str:N #1 \exp_stop_f: |
| 449 |
#1 \prg_return_true: |
| 450 |
\else: |
| 451 |
\if_case:w \int_eval:n { \exp_after:wN ` \token_to_str:N #1 - `a } |
| 452 |
A |
| 453 |
\or: B |
| 454 |
\or: C |
| 455 |
\or: D |
| 456 |
\or: E |
| 457 |
\or: F |
| 458 |
\else: |
| 459 |
\prg_return_false: |
| 460 |
\exp_after:wN \use_none:n |
| 461 |
\fi: |
| 462 |
\prg_return_true: |
| 463 |
\fi: |
| 464 |
} |
| 465 |
% \end{macrocode} |
| 466 |
% \end{macro} |
| 467 |
% |
| 468 |
% \subsection{Conversions} |
| 469 |
% |
| 470 |
% \subsubsection{Producing one byte or character} |
| 471 |
% |
| 472 |
% \begin{variable}{\c_@@_byte_0_tl, \c_@@_byte_1_tl, \c_@@_byte_255_tl} |
| 473 |
% \begin{variable}{\c_@@_byte_-1_tl} |
| 474 |
% For each integer $N$ in the range $[0,255]$, we create a constant |
| 475 |
% token list which holds three character tokens with category code |
| 476 |
% other: the character with character code $N$, followed by the |
| 477 |
% representation of $N$ as two hexadecimal digits. The value $-1$ is |
| 478 |
% given a default token list which ensures that later functions give |
| 479 |
% an empty result for the input $-1$. |
| 480 |
% \begin{macrocode} |
| 481 |
\group_begin: |
| 482 |
\__kernel_tl_set:Nx \l_@@_tmp_tl { \tl_to_str:n { 0123456789ABCDEF } } |
| 483 |
\tl_map_inline:Nn \l_@@_tmp_tl |
| 484 |
{ |
| 485 |
\tl_map_inline:Nn \l_@@_tmp_tl |
| 486 |
{ |
| 487 |
\tl_const:ce { c_@@_byte_ \int_eval:n {"#1##1} _tl } |
| 488 |
{ \char_generate:nn { "#1##1 } { 12 } #1 ##1 } |
| 489 |
} |
| 490 |
} |
| 491 |
\group_end: |
| 492 |
\tl_const:cn { c_@@_byte_-1_tl } { { } \use_none:n { } } |
| 493 |
% \end{macrocode} |
| 494 |
% \end{variable} |
| 495 |
% \end{variable} |
| 496 |
% |
| 497 |
% \begin{macro}[EXP]{\@@_output_byte:n} |
| 498 |
% \begin{macro}[EXP]{\@@_output_byte:w} |
| 499 |
% \begin{macro}[EXP]{\@@_output_hexadecimal:n} |
| 500 |
% \begin{macro}[EXP]{\@@_output_end:} |
| 501 |
% Those functions must be used carefully: feeding them a value outside |
| 502 |
% the range $[-1,255]$ will attempt to use the undefined token list |
| 503 |
% variable \cs{c_@@_byte_\meta{number}_tl}. Assuming that the |
| 504 |
% argument is in the right range, we expand the corresponding token |
| 505 |
% list, and pick either the byte (first token) or the hexadecimal |
| 506 |
% representations (second and third tokens). The value $-1$ produces |
| 507 |
% an empty result in both cases. |
| 508 |
% \begin{macrocode} |
| 509 |
\cs_new:Npn \@@_output_byte:n #1 |
| 510 |
{ \@@_output_byte:w #1 \@@_output_end: } |
| 511 |
\cs_new:Npn \@@_output_byte:w |
| 512 |
{ |
| 513 |
\exp_after:wN \exp_after:wN |
| 514 |
\exp_after:wN \use_i:nnn |
| 515 |
\cs:w c_@@_byte_ \int_eval:w |
| 516 |
} |
| 517 |
\cs_new:Npn \@@_output_hexadecimal:n #1 |
| 518 |
{ |
| 519 |
\exp_after:wN \exp_after:wN |
| 520 |
\exp_after:wN \use_none:n |
| 521 |
\cs:w c_@@_byte_ \int_eval:n {#1} _tl \cs_end: |
| 522 |
} |
| 523 |
\cs_new:Npn \@@_output_end: |
| 524 |
{ \scan_stop: _tl \cs_end: } |
| 525 |
% \end{macrocode} |
| 526 |
% \end{macro} |
| 527 |
% \end{macro} |
| 528 |
% \end{macro} |
| 529 |
% \end{macro} |
| 530 |
% |
| 531 |
% \begin{macro}[rEXP]{\@@_output_byte_pair_be:n} |
| 532 |
% \begin{macro}[rEXP]{\@@_output_byte_pair_le:n} |
| 533 |
% \begin{macro}[rEXP]{\@@_output_byte_pair:nnN} |
| 534 |
% Convert a number in the range $[0,65535]$ to a pair of bytes, either |
| 535 |
% big-endian or little-endian. |
| 536 |
% \begin{macrocode} |
| 537 |
\cs_new:Npn \@@_output_byte_pair_be:n #1 |
| 538 |
{ |
| 539 |
\exp_args:Nf \@@_output_byte_pair:nnN |
| 540 |
{ \int_div_truncate:nn { #1 } { "100 } } {#1} \use:nn |
| 541 |
} |
| 542 |
\cs_new:Npn \@@_output_byte_pair_le:n #1 |
| 543 |
{ |
| 544 |
\exp_args:Nf \@@_output_byte_pair:nnN |
| 545 |
{ \int_div_truncate:nn { #1 } { "100 } } {#1} \use_ii_i:nn |
| 546 |
} |
| 547 |
\cs_new:Npn \@@_output_byte_pair:nnN #1#2#3 |
| 548 |
{ |
| 549 |
#3 |
| 550 |
{ \@@_output_byte:n { #1 } } |
| 551 |
{ \@@_output_byte:n { #2 - #1 * "100 } } |
| 552 |
} |
| 553 |
% \end{macrocode} |
| 554 |
% \end{macro} |
| 555 |
% \end{macro} |
| 556 |
% \end{macro} |
| 557 |
% |
| 558 |
% \subsubsection{Mapping functions for conversions} |
| 559 |
% |
| 560 |
% \begin{macro}{\@@_convert_gmap:N} |
| 561 |
% \begin{macro}[rEXP]{\@@_convert_gmap_loop:NN} |
| 562 |
% This maps the function |#1| over all characters in |
| 563 |
% \cs{g_@@_result_tl}, which should be a byte string in most cases, |
| 564 |
% sometimes a native string. |
| 565 |
% \begin{macrocode} |
| 566 |
\cs_new_protected:Npn \@@_convert_gmap:N #1 |
| 567 |
{ |
| 568 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 569 |
{ |
| 570 |
\exp_after:wN \@@_convert_gmap_loop:NN |
| 571 |
\exp_after:wN #1 |
| 572 |
\g_@@_result_tl { ? \prg_break: } |
| 573 |
\prg_break_point: |
| 574 |
} |
| 575 |
} |
| 576 |
\cs_new:Npn \@@_convert_gmap_loop:NN #1#2 |
| 577 |
{ |
| 578 |
\use_none:n #2 |
| 579 |
#1#2 |
| 580 |
\@@_convert_gmap_loop:NN #1 |
| 581 |
} |
| 582 |
% \end{macrocode} |
| 583 |
% \end{macro} |
| 584 |
% \end{macro} |
| 585 |
% |
| 586 |
% \begin{macro}{\@@_convert_gmap_internal:N} |
| 587 |
% \begin{macro}[rEXP]{\@@_convert_gmap_internal_loop:Nw} |
| 588 |
% This maps the function |#1| over all character codes in |
| 589 |
% \cs{g_@@_result_tl}, which must be in the internal representation. |
| 590 |
% \begin{macrocode} |
| 591 |
\cs_new_protected:Npn \@@_convert_gmap_internal:N #1 |
| 592 |
{ |
| 593 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 594 |
{ |
| 595 |
\exp_after:wN \@@_convert_gmap_internal_loop:Nww |
| 596 |
\exp_after:wN #1 |
| 597 |
\g_@@_result_tl \s_@@ \s_@@_stop \prg_break: \s_@@ |
| 598 |
\prg_break_point: |
| 599 |
} |
| 600 |
} |
| 601 |
\cs_new:Npn \@@_convert_gmap_internal_loop:Nww #1 #2 \s_@@ #3 \s_@@ |
| 602 |
{ |
| 603 |
\@@_use_none_delimit_by_s_stop:w #3 \s_@@_stop |
| 604 |
#1 {#3} |
| 605 |
\@@_convert_gmap_internal_loop:Nww #1 |
| 606 |
} |
| 607 |
% \end{macrocode} |
| 608 |
% \end{macro} |
| 609 |
% \end{macro} |
| 610 |
% |
| 611 |
% \subsubsection{Error-reporting during conversion} |
| 612 |
% |
| 613 |
% \begin{macro}{\@@_if_flag_error:Nne} |
| 614 |
% \begin{macro}{\@@_if_flag_no_error:Nne} |
| 615 |
% When converting using the function \cs{str_set_convert:Nnnn}, errors |
| 616 |
% should be reported to the user after each step in the |
| 617 |
% conversion. Errors are signaled by raising some flag (typically |
| 618 |
% \texttt{@@_error}), so here we test that flag: if it is raised, |
| 619 |
% give the user an error, otherwise remove the arguments. On the other |
| 620 |
% hand, in the conditional functions \cs{str_set_convert:NnnnTF}, |
| 621 |
% errors should be suppressed. This is done by changing |
| 622 |
% \cs{@@_if_flag_error:Nne} into \cs{@@_if_flag_no_error:Nne} |
| 623 |
% locally. |
| 624 |
% \begin{macrocode} |
| 625 |
\cs_new_protected:Npn \@@_if_flag_error:Nne #1 |
| 626 |
{ |
| 627 |
\flag_if_raised:NTF #1 |
| 628 |
{ \msg_error:nne { str } } |
| 629 |
{ \use_none:nn } |
| 630 |
} |
| 631 |
\cs_new_protected:Npn \@@_if_flag_no_error:Nne #1#2#3 |
| 632 |
{ \flag_if_raised:NT #1 { \bool_gset_true:N \g_@@_error_bool } } |
| 633 |
% \end{macrocode} |
| 634 |
% \end{macro} |
| 635 |
% \end{macro} |
| 636 |
% |
| 637 |
% \begin{macro}[rEXP]{\@@_if_flag_times:NT} |
| 638 |
% At the end of each conversion step, we raise all relevant errors as |
| 639 |
% one error message, built on the fly. The height of each flag |
| 640 |
% indicates how many times a given error was encountered. This |
| 641 |
% function prints |#2| followed by the number of occurrences of an |
| 642 |
% error if it occurred, nothing otherwise. |
| 643 |
% \begin{macrocode} |
| 644 |
\cs_new:Npn \@@_if_flag_times:NT #1#2 |
| 645 |
{ \flag_if_raised:NT #1 { #2~(x \flag_height:N #1 ) } } |
| 646 |
% \end{macrocode} |
| 647 |
% \end{macro} |
| 648 |
% |
| 649 |
% \subsubsection{Framework for conversions} |
| 650 |
% |
| 651 |
% Most functions in this module expect to be working with |
| 652 |
% \enquote{native} strings. Strings can also be stored as bytes, in one |
| 653 |
% of many encodings, for instance \textsc{utf8}. The bytes themselves |
| 654 |
% can be expressed in various ways in terms of \TeX{} tokens, for |
| 655 |
% instance as pairs of hexadecimal digits. The questions of going from |
| 656 |
% arbitrary Unicode code points to bytes, and from bytes to tokens are |
| 657 |
% mostly independent. |
| 658 |
% |
| 659 |
% Conversions are done in four steps: |
| 660 |
% \begin{itemize} |
| 661 |
% \item \enquote{unescape} produces a string of bytes; |
| 662 |
% \item \enquote{decode} takes in a string of bytes, and converts it |
| 663 |
% to a list of Unicode characters in an internal representation, |
| 664 |
% with items of the form |
| 665 |
% \begin{quote} |
| 666 |
% \meta{bytes} \cs{s_@@} \meta{Unicode code point} \cs{s_@@} |
| 667 |
% \end{quote} |
| 668 |
% where we have collected the \meta{bytes} which combined to form |
| 669 |
% this particular Unicode character, and the \meta{Unicode code |
| 670 |
% point} is in the range $[0,\hexnum{10FFFF}]$. |
| 671 |
% \item \enquote{encode} encodes the internal list of code points as a |
| 672 |
% byte string in the new encoding; |
| 673 |
% \item \enquote{escape} escapes bytes as requested. |
| 674 |
% \end{itemize} |
| 675 |
% The process is modified in case one of the encoding is empty (or the |
| 676 |
% conversion function has been set equal to the empty encoding because |
| 677 |
% it was not found): then the unescape or escape step is ignored, and |
| 678 |
% the decode or encode steps work on tokens instead of bytes. Otherwise, |
| 679 |
% each step must ensure that it passes a correct byte string or internal |
| 680 |
% string to the next step. |
| 681 |
% |
| 682 |
% \begin{macro}{\str_set_convert:Nnnn, \str_gset_convert:Nnnn} |
| 683 |
% \begin{macro}[TF]{\str_set_convert:Nnnn, \str_gset_convert:Nnnn} |
| 684 |
% \begin{macro}{\@@_convert:nNNnnn} |
| 685 |
% The input string is stored in \cs{g_@@_result_tl}, then we: |
| 686 |
% unescape and decode; encode and escape; exit the group and store the |
| 687 |
% result in the user's variable. The various conversion functions all |
| 688 |
% act on \cs{g_@@_result_tl}. Errors are silenced for the conditional |
| 689 |
% functions by redefining \cs{@@_if_flag_error:Nne} locally. |
| 690 |
% \begin{macrocode} |
| 691 |
\cs_new_protected:Npn \str_set_convert:Nnnn |
| 692 |
{ \@@_convert:nNNnnn { } \tl_set_eq:NN } |
| 693 |
\cs_new_protected:Npn \str_gset_convert:Nnnn |
| 694 |
{ \@@_convert:nNNnnn { } \tl_gset_eq:NN } |
| 695 |
\prg_new_protected_conditional:Npnn |
| 696 |
\str_set_convert:Nnnn #1#2#3#4 { T , F , TF } |
| 697 |
{ |
| 698 |
\bool_gset_false:N \g_@@_error_bool |
| 699 |
\@@_convert:nNNnnn |
| 700 |
{ \cs_set_eq:NN \@@_if_flag_error:Nne \@@_if_flag_no_error:Nne } |
| 701 |
\tl_set_eq:NN #1 {#2} {#3} {#4} |
| 702 |
\bool_if:NTF \g_@@_error_bool \prg_return_false: \prg_return_true: |
| 703 |
} |
| 704 |
\prg_new_protected_conditional:Npnn |
| 705 |
\str_gset_convert:Nnnn #1#2#3#4 { T , F , TF } |
| 706 |
{ |
| 707 |
\bool_gset_false:N \g_@@_error_bool |
| 708 |
\@@_convert:nNNnnn |
| 709 |
{ \cs_set_eq:NN \@@_if_flag_error:Nne \@@_if_flag_no_error:Nne } |
| 710 |
\tl_gset_eq:NN #1 {#2} {#3} {#4} |
| 711 |
\bool_if:NTF \g_@@_error_bool \prg_return_false: \prg_return_true: |
| 712 |
} |
| 713 |
\cs_new_protected:Npn \@@_convert:nNNnnn #1#2#3#4#5#6 |
| 714 |
{ |
| 715 |
\group_begin: |
| 716 |
#1 |
| 717 |
\__kernel_tl_gset:Nx \g_@@_result_tl { \__kernel_str_to_other_fast:n {#4} } |
| 718 |
\exp_after:wN \@@_convert:wwwnn |
| 719 |
\tl_to_str:n {#5} /// \s_@@_stop |
| 720 |
{ decode } { unescape } |
| 721 |
\prg_do_nothing: |
| 722 |
\@@_convert_decode_: |
| 723 |
\exp_after:wN \@@_convert:wwwnn |
| 724 |
\tl_to_str:n {#6} /// \s_@@_stop |
| 725 |
{ encode } { escape } |
| 726 |
\use_ii_i:nn |
| 727 |
\@@_convert_encode_: |
| 728 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 729 |
{ \tl_to_str:V \g_@@_result_tl } |
| 730 |
\group_end: |
| 731 |
#2 #3 \g_@@_result_tl |
| 732 |
} |
| 733 |
% \end{macrocode} |
| 734 |
% \end{macro} |
| 735 |
% \end{macro} |
| 736 |
% \end{macro} |
| 737 |
% |
| 738 |
% \begin{macro}{\@@_convert:wwwnn} |
| 739 |
% \begin{macro}{\@@_convert:NNnNN} |
| 740 |
% The task of \cs{@@_convert:wwwnn} is to split |
| 741 |
% \meta{encoding}/\meta{escaping} pairs into their components, |#1| |
| 742 |
% and |#2|. Calls to \cs{@@_convert:nnn} ensure that the |
| 743 |
% corresponding conversion functions are defined. The third auxiliary |
| 744 |
% does the main work. |
| 745 |
% \begin{itemize} |
| 746 |
% \item |#1| is the encoding conversion function; |
| 747 |
% \item |#2| is the escaping function; |
| 748 |
% \item |#3| is the escaping name for use in an error message; |
| 749 |
% \item |#4| is \cs{prg_do_nothing:} for unescaping/decoding, and |
| 750 |
% \cs{use_ii_i:nn} for encoding/escaping; |
| 751 |
% \item |#5| is the default encoding function (either |
| 752 |
% \enquote{decode} or \enquote{encode}), for which there should be |
| 753 |
% no escaping. |
| 754 |
% \end{itemize} |
| 755 |
% Let us ignore the native encoding for a second. In the |
| 756 |
% unescaping/decoding phase, we want to do |#2#1| in this order, and |
| 757 |
% in the encoding/escaping phase, the order should be reversed: |
| 758 |
% |#4#2#1| does exactly that. If one of the encodings is the default |
| 759 |
% (native), then the escaping should be ignored, with an error if any |
| 760 |
% was given, and only the encoding, |#1|, should be performed. |
| 761 |
% \begin{macrocode} |
| 762 |
\cs_new_protected:Npn \@@_convert:wwwnn |
| 763 |
#1 / #2 // #3 \s_@@_stop #4#5 |
| 764 |
{ |
| 765 |
\@@_convert:nnn {enc} {#4} {#1} |
| 766 |
\@@_convert:nnn {esc} {#5} {#2} |
| 767 |
\exp_args:Ncc \@@_convert:NNnNN |
| 768 |
{ @@_convert_#4_#1: } { @@_convert_#5_#2: } {#2} |
| 769 |
} |
| 770 |
\cs_new_protected:Npn \@@_convert:NNnNN #1#2#3#4#5 |
| 771 |
{ |
| 772 |
\if_meaning:w #1 #5 |
| 773 |
\tl_if_empty:nF {#3} |
| 774 |
{ \msg_error:nne { str } { native-escaping } {#3} } |
| 775 |
#1 |
| 776 |
\else: |
| 777 |
#4 #2 #1 |
| 778 |
\fi: |
| 779 |
} |
| 780 |
% \end{macrocode} |
| 781 |
% \end{macro} |
| 782 |
% \end{macro} |
| 783 |
% |
| 784 |
% \begin{macro}{\@@_convert:nnn} |
| 785 |
% \begin{macro}{\@@_convert:nnnn} |
| 786 |
% The arguments of \cs{@@_convert:nnn} are: \texttt{enc} or |
| 787 |
% \texttt{esc}, used to build filenames, the type of the conversion |
| 788 |
% (unescape, decode, encode, escape), and the encoding or escaping |
| 789 |
% name. If the function is already defined, no need to do anything. |
| 790 |
% Otherwise, filter out all non-alphanumerics in the name, and |
| 791 |
% lowercase it. Feed that, and the same three arguments, to |
| 792 |
% \cs{@@_convert:nnnn}. The task is then to make sure that the |
| 793 |
% conversion function |#3_#1| corresponding to the type |#3| and |
| 794 |
% filtered name |#1| is defined, then set our initial conversion |
| 795 |
% function |#3_#4| equal to that. |
| 796 |
% |
| 797 |
% How do we get the |#3_#1| conversion to be defined if it isn't? |
| 798 |
% Two main cases. |
| 799 |
% |
| 800 |
% First, if |#1| is a key in \cs{g_@@_alias_prop}, then the value |
| 801 |
% \cs{l_@@_tmp_tl} tells us what file to load. Loading is |
| 802 |
% skipped if the file was already read, i.e., if the conversion |
| 803 |
% command based on \cs{l_@@_tmp_tl} already exists. Otherwise, |
| 804 |
% try to load the file; if that fails, there is an error, use the |
| 805 |
% default empty name instead. |
| 806 |
% |
| 807 |
% Second, |#1| may be absent from the property list. The |
| 808 |
% \cs{cs_if_exist:cF} test is automatically false, and we search for a |
| 809 |
% file defining the encoding or escaping |#1| (this should allow |
| 810 |
% third-party \texttt{.def} files). If the file is not found, there is |
| 811 |
% an error, use the default empty name instead. |
| 812 |
% |
| 813 |
% In all cases, the conversion based on \cs{l_@@_tmp_tl} is |
| 814 |
% defined, so we can set the |#3_#1| function equal to that. In some |
| 815 |
% cases (\emph{e.g.}, \texttt{utf16be}), the |#3_#1| function is |
| 816 |
% actually defined within the file we just loaded, and it is different |
| 817 |
% from the \cs{l_@@_tmp_tl}-based function: we mustn't clobber |
| 818 |
% that different definition. |
| 819 |
% \begin{macrocode} |
| 820 |
\cs_new_protected:Npn \@@_convert:nnn #1#2#3 |
| 821 |
{ |
| 822 |
\cs_if_exist:cF { @@_convert_#2_#3: } |
| 823 |
{ |
| 824 |
\exp_args:Ne \@@_convert:nnnn |
| 825 |
{ \@@_convert_lowercase_alphanum:n {#3} } |
| 826 |
{#1} {#2} {#3} |
| 827 |
} |
| 828 |
} |
| 829 |
\cs_new_protected:Npn \@@_convert:nnnn #1#2#3#4 |
| 830 |
{ |
| 831 |
\cs_if_exist:cF { @@_convert_#3_#1: } |
| 832 |
{ |
| 833 |
\prop_get:NnNF \g_@@_alias_prop {#1} \l_@@_tmp_tl |
| 834 |
{ \tl_set:Nn \l_@@_tmp_tl {#1} } |
| 835 |
\cs_if_exist:cF { @@_convert_#3_ \l_@@_tmp_tl : } |
| 836 |
{ |
| 837 |
\file_if_exist:nTF { l3str-#2- \l_@@_tmp_tl .def } |
| 838 |
{ |
| 839 |
\group_begin: |
| 840 |
\cctab_select:N \c_code_cctab |
| 841 |
\file_input:n { l3str-#2- \l_@@_tmp_tl .def } |
| 842 |
\group_end: |
| 843 |
} |
| 844 |
{ |
| 845 |
\tl_clear:N \l_@@_tmp_tl |
| 846 |
\msg_error:nnee { str } { unknown-#2 } {#4} {#1} |
| 847 |
} |
| 848 |
} |
| 849 |
\cs_if_exist:cF { @@_convert_#3_#1: } |
| 850 |
{ |
| 851 |
\cs_gset_eq:cc { @@_convert_#3_#1: } |
| 852 |
{ @@_convert_#3_ \l_@@_tmp_tl : } |
| 853 |
} |
| 854 |
} |
| 855 |
\cs_gset_eq:cc { @@_convert_#3_#4: } { @@_convert_#3_#1: } |
| 856 |
} |
| 857 |
% \end{macrocode} |
| 858 |
% \end{macro} |
| 859 |
% \end{macro} |
| 860 |
% |
| 861 |
% \begin{macro}[rEXP]{\@@_convert_lowercase_alphanum:n} |
| 862 |
% \begin{macro}[rEXP]{\@@_convert_lowercase_alphanum_loop:N} |
| 863 |
% This function keeps only letters and digits, with upper case letters |
| 864 |
% converted to lower case. |
| 865 |
% \begin{macrocode} |
| 866 |
\cs_new:Npn \@@_convert_lowercase_alphanum:n #1 |
| 867 |
{ |
| 868 |
\exp_after:wN \@@_convert_lowercase_alphanum_loop:N |
| 869 |
\tl_to_str:n {#1} { ? \prg_break: } |
| 870 |
\prg_break_point: |
| 871 |
} |
| 872 |
\cs_new:Npn \@@_convert_lowercase_alphanum_loop:N #1 |
| 873 |
{ |
| 874 |
\use_none:n #1 |
| 875 |
\if_int_compare:w `#1 > `Z \exp_stop_f: |
| 876 |
\if_int_compare:w `#1 > `z \exp_stop_f: \else: |
| 877 |
\if_int_compare:w `#1 < `a \exp_stop_f: \else: |
| 878 |
#1 |
| 879 |
\fi: |
| 880 |
\fi: |
| 881 |
\else: |
| 882 |
\if_int_compare:w `#1 < `A \exp_stop_f: |
| 883 |
\if_int_compare:w 1 < 1#1 \exp_stop_f: |
| 884 |
#1 |
| 885 |
\fi: |
| 886 |
\else: |
| 887 |
\@@_output_byte:n { `#1 + `a - `A } |
| 888 |
\fi: |
| 889 |
\fi: |
| 890 |
\@@_convert_lowercase_alphanum_loop:N |
| 891 |
} |
| 892 |
% \end{macrocode} |
| 893 |
% \end{macro} |
| 894 |
% \end{macro} |
| 895 |
% |
| 896 |
% \subsubsection{Byte unescape and escape} |
| 897 |
% |
| 898 |
% Strings of bytes may need to be stored in auxiliary files in safe |
| 899 |
% \enquote{escaping} formats. Each such escaping is only loaded as |
| 900 |
% needed. By default, on input any non-byte is filtered out, while the |
| 901 |
% output simply consists in letting bytes through. |
| 902 |
% |
| 903 |
% \begin{macro}[rEXP]{\@@_filter_bytes:n} |
| 904 |
% \begin{macro}[rEXP]{\@@_filter_bytes_aux:N} |
| 905 |
% In the case of 8-bit engines, every character is a byte. For |
| 906 |
% Unicode-aware engines, test the character code; non-bytes cause us |
| 907 |
% to raise the flag \cs{l_@@_byte_flag}. Spaces have already been given |
| 908 |
% the correct category code when this function is called. |
| 909 |
% \begin{macrocode} |
| 910 |
\bool_lazy_any:nTF |
| 911 |
{ |
| 912 |
\sys_if_engine_luatex_p: |
| 913 |
\sys_if_engine_xetex_p: |
| 914 |
} |
| 915 |
{ |
| 916 |
\cs_new:Npn \@@_filter_bytes:n #1 |
| 917 |
{ |
| 918 |
\@@_filter_bytes_aux:N #1 |
| 919 |
{ ? \prg_break: } |
| 920 |
\prg_break_point: |
| 921 |
} |
| 922 |
\cs_new:Npn \@@_filter_bytes_aux:N #1 |
| 923 |
{ |
| 924 |
\use_none:n #1 |
| 925 |
\if_int_compare:w `#1 < 256 \exp_stop_f: |
| 926 |
#1 |
| 927 |
\else: |
| 928 |
\flag_raise:N \l_@@_byte_flag |
| 929 |
\fi: |
| 930 |
\@@_filter_bytes_aux:N |
| 931 |
} |
| 932 |
} |
| 933 |
{ \cs_new_eq:NN \@@_filter_bytes:n \use:n } |
| 934 |
% \end{macrocode} |
| 935 |
% \end{macro} |
| 936 |
% \end{macro} |
| 937 |
% |
| 938 |
% \begin{macro}{\@@_convert_unescape_:} |
| 939 |
% \begin{macro}{\@@_convert_unescape_bytes:} |
| 940 |
% The simplest unescaping method removes non-bytes from |
| 941 |
% \cs{g_@@_result_tl}. |
| 942 |
% \begin{macrocode} |
| 943 |
\bool_lazy_any:nTF |
| 944 |
{ |
| 945 |
\sys_if_engine_luatex_p: |
| 946 |
\sys_if_engine_xetex_p: |
| 947 |
} |
| 948 |
{ |
| 949 |
\cs_new_protected:Npn \@@_convert_unescape_: |
| 950 |
{ |
| 951 |
\flag_clear:N \l_@@_byte_flag |
| 952 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 953 |
{ \exp_args:No \@@_filter_bytes:n \g_@@_result_tl } |
| 954 |
\@@_if_flag_error:Nne \l_@@_byte_flag { non-byte } { bytes } |
| 955 |
} |
| 956 |
} |
| 957 |
{ \cs_new_protected:Npn \@@_convert_unescape_: { } } |
| 958 |
\cs_new_eq:NN \@@_convert_unescape_bytes: \@@_convert_unescape_: |
| 959 |
% \end{macrocode} |
| 960 |
% \end{macro} |
| 961 |
% \end{macro} |
| 962 |
% |
| 963 |
% \begin{macro}{\@@_convert_escape_:} |
| 964 |
% \begin{macro}{\@@_convert_escape_bytes:} |
| 965 |
% The simplest form of escape leaves the bytes from the previous step |
| 966 |
% of the conversion unchanged. |
| 967 |
% \begin{macrocode} |
| 968 |
\cs_new_protected:Npn \@@_convert_escape_: { } |
| 969 |
\cs_new_eq:NN \@@_convert_escape_bytes: \@@_convert_escape_: |
| 970 |
% \end{macrocode} |
| 971 |
% \end{macro} |
| 972 |
% \end{macro} |
| 973 |
% |
| 974 |
% \subsubsection{Native strings} |
| 975 |
% |
| 976 |
% \begin{macro}{\@@_convert_decode_:} |
| 977 |
% \begin{macro}[rEXP]{\@@_decode_native_char:N} |
| 978 |
% Convert each character to its character code, one at a time. |
| 979 |
% \begin{macrocode} |
| 980 |
\cs_new_protected:Npn \@@_convert_decode_: |
| 981 |
{ \@@_convert_gmap:N \@@_decode_native_char:N } |
| 982 |
\cs_new:Npn \@@_decode_native_char:N #1 |
| 983 |
{ #1 \s_@@ \int_value:w `#1 \s_@@ } |
| 984 |
% \end{macrocode} |
| 985 |
% \end{macro} |
| 986 |
% \end{macro} |
| 987 |
% |
| 988 |
% \begin{macro}{\@@_convert_encode_:} |
| 989 |
% \begin{macro}[EXP]{\@@_encode_native_char:n} |
| 990 |
% The conversion from an internal string to native character tokens |
| 991 |
% basically maps \cs{char_generate:nn} through the code-points, but in |
| 992 |
% non-Unicode-aware engines we use a fall-back character |?| rather |
| 993 |
% than nothing when given a character code outside $[0,255]$. We |
| 994 |
% detect the presence of bad characters using a flag and only produce |
| 995 |
% a single error after the \texttt{e}-expanding assignment. |
| 996 |
% \begin{macrocode} |
| 997 |
\bool_lazy_any:nTF |
| 998 |
{ |
| 999 |
\sys_if_engine_luatex_p: |
| 1000 |
\sys_if_engine_xetex_p: |
| 1001 |
} |
| 1002 |
{ |
| 1003 |
\cs_new_protected:Npn \@@_convert_encode_: |
| 1004 |
{ \@@_convert_gmap_internal:N \@@_encode_native_char:n } |
| 1005 |
\cs_new:Npn \@@_encode_native_char:n #1 |
| 1006 |
{ \char_generate:nn {#1} {12} } |
| 1007 |
} |
| 1008 |
{ |
| 1009 |
\cs_new_protected:Npn \@@_convert_encode_: |
| 1010 |
{ |
| 1011 |
\flag_clear:N \l_@@_error_flag |
| 1012 |
\@@_convert_gmap_internal:N \@@_encode_native_char:n |
| 1013 |
\@@_if_flag_error:Nne \l_@@_error_flag |
| 1014 |
{ native-overflow } { } |
| 1015 |
} |
| 1016 |
\cs_new:Npn \@@_encode_native_char:n #1 |
| 1017 |
{ |
| 1018 |
\if_int_compare:w #1 > \c_@@_max_byte_int |
| 1019 |
\flag_raise:N \l_@@_error_flag |
| 1020 |
? |
| 1021 |
\else: |
| 1022 |
\char_generate:nn {#1} {12} |
| 1023 |
\fi: |
| 1024 |
} |
| 1025 |
\msg_new:nnnn { str } { native-overflow } |
| 1026 |
{ Character~code~too~large~for~this~engine. } |
| 1027 |
{ |
| 1028 |
This~engine~only~support~8-bit~characters:~ |
| 1029 |
valid~character~codes~are~in~the~range~[0,255].~ |
| 1030 |
To~manipulate~arbitrary~Unicode,~use~LuaTeX~or~XeTeX. |
| 1031 |
} |
| 1032 |
} |
| 1033 |
% \end{macrocode} |
| 1034 |
% \end{macro} |
| 1035 |
% \end{macro} |
| 1036 |
% |
| 1037 |
% \subsubsection{\texttt{clist}} |
| 1038 |
% |
| 1039 |
% \begin{macro}{\@@_convert_decode_clist:} |
| 1040 |
% \begin{macro}[rEXP]{\@@_decode_clist_char:n} |
| 1041 |
% Convert each integer to the internal form. We first turn |
| 1042 |
% \cs{g_@@_result_tl} into a clist variable, as this avoids problems |
| 1043 |
% with leading or trailing commas. |
| 1044 |
% \begin{macrocode} |
| 1045 |
\cs_new_protected:Npn \@@_convert_decode_clist: |
| 1046 |
{ |
| 1047 |
\clist_gset:No \g_@@_result_tl \g_@@_result_tl |
| 1048 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 1049 |
{ |
| 1050 |
\exp_args:No \clist_map_function:nN |
| 1051 |
\g_@@_result_tl \@@_decode_clist_char:n |
| 1052 |
} |
| 1053 |
} |
| 1054 |
\cs_new:Npn \@@_decode_clist_char:n #1 |
| 1055 |
{ #1 \s_@@ \int_eval:n {#1} \s_@@ } |
| 1056 |
% \end{macrocode} |
| 1057 |
% \end{macro} |
| 1058 |
% \end{macro} |
| 1059 |
% |
| 1060 |
% \begin{macro}{\@@_convert_encode_clist:} |
| 1061 |
% \begin{macro}[rEXP]{\@@_encode_clist_char:n} |
| 1062 |
% Convert the internal list of character codes to a comma-list of |
| 1063 |
% character codes. The first line produces a comma-list with a |
| 1064 |
% leading comma, removed in the next step (this also works in the |
| 1065 |
% empty case, since \cs{tl_tail:N} does not trigger an error in this |
| 1066 |
% case). |
| 1067 |
% \begin{macrocode} |
| 1068 |
\cs_new_protected:Npn \@@_convert_encode_clist: |
| 1069 |
{ |
| 1070 |
\@@_convert_gmap_internal:N \@@_encode_clist_char:n |
| 1071 |
\__kernel_tl_gset:Nx \g_@@_result_tl { \tl_tail:N \g_@@_result_tl } |
| 1072 |
} |
| 1073 |
\cs_new:Npn \@@_encode_clist_char:n #1 { , #1 } |
| 1074 |
% \end{macrocode} |
| 1075 |
% \end{macro} |
| 1076 |
% \end{macro} |
| 1077 |
% |
| 1078 |
% \subsubsection{8-bit encodings} |
| 1079 |
% |
| 1080 |
% It is not clear in what situations 8-bit encodings are used, hence it |
| 1081 |
% is not clear what should be optimized. The current approach is |
| 1082 |
% reasonably efficient to convert long strings, and it scales well when |
| 1083 |
% using many different encodings. |
| 1084 |
% |
| 1085 |
% The data needed to support a given 8-bit encoding is stored in a file |
| 1086 |
% that consists of a single function call |
| 1087 |
% \begin{quote}\ttfamily |
| 1088 |
% \cs{@@_declare_eight_bit_encoding:nnnn} \Arg{name} \Arg{modulo} |
| 1089 |
% \Arg{mapping} \Arg{missing} |
| 1090 |
% \end{quote} |
| 1091 |
% This declares the encoding \meta{name} to map bytes to Unicode |
| 1092 |
% characters according to the \meta{mapping}, and map those bytes which |
| 1093 |
% are not mentioned in the \meta{mapping} either to the replacement |
| 1094 |
% character (if they appear in \meta{missing}), or to themselves. The |
| 1095 |
% \meta{mapping} argument is a token list of pairs \Arg{byte} |
| 1096 |
% \Arg{Unicode} expressed in uppercase hexadecimal notation. The |
| 1097 |
% \meta{missing} argument is a token list of \Arg{byte}. Every |
| 1098 |
% \meta{byte} which does not appear in the \meta{mapping} nor the |
| 1099 |
% \meta{missing} lists maps to itself in Unicode, so for instance the |
| 1100 |
% \texttt{latin1} encoding has empty \meta{mapping} and \meta{missing} |
| 1101 |
% lists. The \meta{modulo} is a (decimal) integer between $256$ and |
| 1102 |
% $558$ inclusive, modulo which all Unicode code points supported by the |
| 1103 |
% encodings must be different. |
| 1104 |
% |
| 1105 |
% We use two integer arrays per encoding. When decoding we only use the |
| 1106 |
% \texttt{decode} integer array, with entry $n+1$ (offset needed because |
| 1107 |
% integer array indices start at~$1$) equal to the Unicode code point |
| 1108 |
% that corresponds to the $n$-th byte in the encoding under |
| 1109 |
% consideration, or $-1$ if the given byte is invalid in this encoding. |
| 1110 |
% When encoding we use both arrays: upon seeing a code point~$n$, we |
| 1111 |
% look up the entry ($1$~plus) $n$ modulo some number $M$ in the |
| 1112 |
% \texttt{encode} array, which tells us the byte that might encode the |
| 1113 |
% given Unicode code point, then we check in the \texttt{decode} array |
| 1114 |
% that indeed this byte encodes the Unicode code point we want. Here, |
| 1115 |
% $M$ is an encoding-dependent integer between $256$ and $558$ (it turns |
| 1116 |
% out), chosen so that among the Unicode code points that can be validly |
| 1117 |
% represented in the given encoding, no pair of code points have the |
| 1118 |
% same value modulo~$M$. |
| 1119 |
% |
| 1120 |
% \begin{macro} |
| 1121 |
% { |
| 1122 |
% \@@_declare_eight_bit_encoding:nnnn, |
| 1123 |
% \@@_declare_eight_bit_aux:NNnnn, |
| 1124 |
% \@@_declare_eight_bit_loop:Nnn, |
| 1125 |
% \@@_declare_eight_bit_loop:Nn |
| 1126 |
% } |
| 1127 |
% Loop through both lists of bytes to fill in the \texttt{decode} |
| 1128 |
% integer array, then fill the \texttt{encode} array accordingly. |
| 1129 |
% For bytes that are invalid in the given encoding, store $-1$ in the |
| 1130 |
% \texttt{decode} array. |
| 1131 |
% \begin{macrocode} |
| 1132 |
\cs_new_protected:Npn \@@_declare_eight_bit_encoding:nnnn #1 |
| 1133 |
{ |
| 1134 |
\tl_set:Nn \l_@@_tmp_tl {#1} |
| 1135 |
\cs_new_protected:cpn { @@_convert_decode_#1: } |
| 1136 |
{ \@@_convert_decode_eight_bit:n {#1} } |
| 1137 |
\cs_new_protected:cpn { @@_convert_encode_#1: } |
| 1138 |
{ \@@_convert_encode_eight_bit:n {#1} } |
| 1139 |
\exp_args:Ncc \@@_declare_eight_bit_aux:NNnnn |
| 1140 |
{ g_@@_decode_#1_intarray } { g_@@_encode_#1_intarray } |
| 1141 |
} |
| 1142 |
\cs_new_protected:Npn \@@_declare_eight_bit_aux:NNnnn #1#2#3#4#5 |
| 1143 |
{ |
| 1144 |
\intarray_new:Nn #1 { 256 } |
| 1145 |
\int_step_inline:nnn { 0 } { 255 } |
| 1146 |
{ \intarray_gset:Nnn #1 { 1 + ##1 } {##1} } |
| 1147 |
\@@_declare_eight_bit_loop:Nnn #1 |
| 1148 |
#4 { \s_@@_stop \prg_break: } { } |
| 1149 |
\prg_break_point: |
| 1150 |
\@@_declare_eight_bit_loop:Nn #1 |
| 1151 |
#5 { \s_@@_stop \prg_break: } |
| 1152 |
\prg_break_point: |
| 1153 |
\intarray_new:Nn #2 {#3} |
| 1154 |
\int_step_inline:nnn { 0 } { 255 } |
| 1155 |
{ |
| 1156 |
\int_compare:nNnF { \intarray_item:Nn #1 { 1 + ##1 } } = { -1 } |
| 1157 |
{ |
| 1158 |
\intarray_gset:Nnn #2 |
| 1159 |
{ |
| 1160 |
1 + |
| 1161 |
\int_mod:nn { \intarray_item:Nn #1 { 1 + ##1 } } |
| 1162 |
{ \intarray_count:N #2 } |
| 1163 |
} |
| 1164 |
{##1} |
| 1165 |
} |
| 1166 |
} |
| 1167 |
} |
| 1168 |
\cs_new_protected:Npn \@@_declare_eight_bit_loop:Nnn #1#2#3 |
| 1169 |
{ |
| 1170 |
\@@_use_none_delimit_by_s_stop:w #2 \s_@@_stop |
| 1171 |
\intarray_gset:Nnn #1 { 1 + "#2 } { "#3 } |
| 1172 |
\@@_declare_eight_bit_loop:Nnn #1 |
| 1173 |
} |
| 1174 |
\cs_new_protected:Npn \@@_declare_eight_bit_loop:Nn #1#2 |
| 1175 |
{ |
| 1176 |
\@@_use_none_delimit_by_s_stop:w #2 \s_@@_stop |
| 1177 |
\intarray_gset:Nnn #1 { 1 + "#2 } { -1 } |
| 1178 |
\@@_declare_eight_bit_loop:Nn #1 |
| 1179 |
} |
| 1180 |
% \end{macrocode} |
| 1181 |
% \end{macro} |
| 1182 |
% |
| 1183 |
% \begin{macro}{\@@_convert_decode_eight_bit:n} |
| 1184 |
% \begin{macro}[rEXP]{\@@_decode_eight_bit_aux:n, \@@_decode_eight_bit_aux:Nn} |
| 1185 |
% The map from bytes to Unicode code points is in the \texttt{decode} |
| 1186 |
% array corresponding to the given encoding. Define \cs{@@_tmp:w} and |
| 1187 |
% pass it successively all bytes in the string. It produces an |
| 1188 |
% internal representation with suitable \cs{s_@@} inserted, and the |
| 1189 |
% corresponding code point is obtained by looking it up in the integer |
| 1190 |
% array. If the entry is $-1$ then issue a replacement character and |
| 1191 |
% raise the flag indicating that there was an error. |
| 1192 |
% \begin{macrocode} |
| 1193 |
\cs_new_protected:Npn \@@_convert_decode_eight_bit:n #1 |
| 1194 |
{ |
| 1195 |
\cs_set:Npe \@@_tmp:w |
| 1196 |
{ |
| 1197 |
\exp_not:N \@@_decode_eight_bit_aux:Nn |
| 1198 |
\exp_not:c { g_@@_decode_#1_intarray } |
| 1199 |
} |
| 1200 |
\flag_clear:N \l_@@_error_flag |
| 1201 |
\@@_convert_gmap:N \@@_tmp:w |
| 1202 |
\@@_if_flag_error:Nne \l_@@_error_flag { decode-8-bit } {#1} |
| 1203 |
} |
| 1204 |
\cs_new:Npn \@@_decode_eight_bit_aux:Nn #1#2 |
| 1205 |
{ |
| 1206 |
#2 \s_@@ |
| 1207 |
\exp_args:Nf \@@_decode_eight_bit_aux:n |
| 1208 |
{ \intarray_item:Nn #1 { 1 + `#2 } } |
| 1209 |
\s_@@ |
| 1210 |
} |
| 1211 |
\cs_new:Npn \@@_decode_eight_bit_aux:n #1 |
| 1212 |
{ |
| 1213 |
\if_int_compare:w #1 < \c_zero_int |
| 1214 |
\flag_raise:N \l_@@_error_flag |
| 1215 |
\int_value:w \c_@@_replacement_char_int |
| 1216 |
\else: |
| 1217 |
#1 |
| 1218 |
\fi: |
| 1219 |
} |
| 1220 |
% \end{macrocode} |
| 1221 |
% \end{macro} |
| 1222 |
% \end{macro} |
| 1223 |
% |
| 1224 |
% \begin{macro}{\@@_convert_encode_eight_bit:n} |
| 1225 |
% \begin{macro}[rEXP]{\@@_encode_eight_bit_aux:nnN, \@@_encode_eight_bit_aux:NNn} |
| 1226 |
% It is not practical to make an integer array with indices in the |
| 1227 |
% full Unicode range, so we work modulo some number, which is simply |
| 1228 |
% the size of the \texttt{encode} integer array for the given |
| 1229 |
% encoding. This gives us a candidate byte for representing a given |
| 1230 |
% Unicode code point. Of course taking the modulo leads to collisions |
| 1231 |
% so we check in the \texttt{decode} array that the byte we got is |
| 1232 |
% indeed correct. Otherwise the Unicode code point we started from is |
| 1233 |
% simply not representable in the given encoding. |
| 1234 |
% \begin{macrocode} |
| 1235 |
\int_new:N \l_@@_modulo_int |
| 1236 |
\cs_new_protected:Npn \@@_convert_encode_eight_bit:n #1 |
| 1237 |
{ |
| 1238 |
\cs_set:Npe \@@_tmp:w |
| 1239 |
{ |
| 1240 |
\exp_not:N \@@_encode_eight_bit_aux:NNn |
| 1241 |
\exp_not:c { g_@@_encode_#1_intarray } |
| 1242 |
\exp_not:c { g_@@_decode_#1_intarray } |
| 1243 |
} |
| 1244 |
\flag_clear:N \l_@@_error_flag |
| 1245 |
\@@_convert_gmap_internal:N \@@_tmp:w |
| 1246 |
\@@_if_flag_error:Nne \l_@@_error_flag { encode-8-bit } {#1} |
| 1247 |
} |
| 1248 |
\cs_new:Npn \@@_encode_eight_bit_aux:NNn #1#2#3 |
| 1249 |
{ |
| 1250 |
\exp_args:Nf \@@_encode_eight_bit_aux:nnN |
| 1251 |
{ |
| 1252 |
\intarray_item:Nn #1 |
| 1253 |
{ 1 + \int_mod:nn {#3} { \intarray_count:N #1 } } |
| 1254 |
} |
| 1255 |
{#3} |
| 1256 |
#2 |
| 1257 |
} |
| 1258 |
\cs_new:Npn \@@_encode_eight_bit_aux:nnN #1#2#3 |
| 1259 |
{ |
| 1260 |
\int_compare:nNnTF { \intarray_item:Nn #3 { 1 + #1 } } = {#2} |
| 1261 |
{ \@@_output_byte:n {#1} } |
| 1262 |
{ \flag_raise:N \l_@@_error_flag } |
| 1263 |
} |
| 1264 |
% \end{macrocode} |
| 1265 |
% \end{macro} |
| 1266 |
% \end{macro} |
| 1267 |
% |
| 1268 |
% \subsection{Messages} |
| 1269 |
% |
| 1270 |
% General messages, and messages for the encodings and escapings loaded |
| 1271 |
% by default (\enquote{native}, and \enquote{bytes}). |
| 1272 |
% \begin{macrocode} |
| 1273 |
\msg_new:nnn { str } { unknown-esc } |
| 1274 |
{ Escaping~scheme~'#1'~(filtered:~'#2')~unknown. } |
| 1275 |
\msg_new:nnn { str } { unknown-enc } |
| 1276 |
{ Encoding~scheme~'#1'~(filtered:~'#2')~unknown. } |
| 1277 |
\msg_new:nnnn { str } { native-escaping } |
| 1278 |
{ The~'native'~encoding~scheme~does~not~support~any~escaping. } |
| 1279 |
{ |
| 1280 |
Since~native~strings~do~not~consist~in~bytes,~ |
| 1281 |
none~of~the~escaping~methods~make~sense.~ |
| 1282 |
The~specified~escaping,~'#1',~will~be~ignored. |
| 1283 |
} |
| 1284 |
\msg_new:nnn { str } { file-not-found } |
| 1285 |
{ File~'l3str-#1.def'~not~found. } |
| 1286 |
% \end{macrocode} |
| 1287 |
% |
| 1288 |
% Message used when the \enquote{bytes} unescaping fails because the |
| 1289 |
% string given to \cs{str_set_convert:Nnnn} contains a non-byte. This |
| 1290 |
% cannot happen for the -8-bit engines. |
| 1291 |
% Messages used for other escapings and |
| 1292 |
% encodings are defined in each definition file. |
| 1293 |
% \begin{macrocode} |
| 1294 |
\bool_lazy_any:nT |
| 1295 |
{ |
| 1296 |
\sys_if_engine_luatex_p: |
| 1297 |
\sys_if_engine_xetex_p: |
| 1298 |
} |
| 1299 |
{ |
| 1300 |
\msg_new:nnnn { str } { non-byte } |
| 1301 |
{ String~invalid~in~escaping~'#1':~it~may~only~contain~bytes. } |
| 1302 |
{ |
| 1303 |
Some~characters~in~the~string~you~asked~to~convert~are~not~ |
| 1304 |
8-bit~characters.~Perhaps~the~string~is~a~'native'~Unicode~string?~ |
| 1305 |
If~it~is,~try~using\\ |
| 1306 |
\\ |
| 1307 |
\iow_indent:n |
| 1308 |
{ |
| 1309 |
\iow_char:N\\str_set_convert:Nnnn \\ |
| 1310 |
\ \ <str~var>~\{~<string>~\}~\{~native~\}~\{~<target~encoding>~\} |
| 1311 |
} |
| 1312 |
} |
| 1313 |
} |
| 1314 |
% \end{macrocode} |
| 1315 |
% |
| 1316 |
% Those messages are used when converting to and from 8-bit encodings. |
| 1317 |
% \begin{macrocode} |
| 1318 |
\msg_new:nnnn { str } { decode-8-bit } |
| 1319 |
{ Invalid~string~in~encoding~'#1'. } |
| 1320 |
{ |
| 1321 |
LaTeX~came~across~a~byte~which~is~not~defined~to~represent~ |
| 1322 |
any~character~in~the~encoding~'#1'. |
| 1323 |
} |
| 1324 |
\msg_new:nnnn { str } { encode-8-bit } |
| 1325 |
{ Unicode~string~cannot~be~converted~to~encoding~'#1'. } |
| 1326 |
{ |
| 1327 |
The~encoding~'#1'~only~contains~a~subset~of~all~Unicode~characters.~ |
| 1328 |
LaTeX~was~asked~to~convert~a~string~to~that~encoding,~but~that~ |
| 1329 |
string~contains~a~character~that~'#1'~does~not~support. |
| 1330 |
} |
| 1331 |
% \end{macrocode} |
| 1332 |
% |
| 1333 |
% \subsection{Escaping definitions} |
| 1334 |
% |
| 1335 |
% Several of those encodings are defined by the pdf file format. The |
| 1336 |
% following byte storage methods are defined: |
| 1337 |
% \begin{itemize} |
| 1338 |
% \item \texttt{bytes} (default), non-bytes are filtered out, and |
| 1339 |
% bytes are left untouched (this is defined by default); |
| 1340 |
% \item \texttt{hex} or \texttt{hexadecimal}, as per the \pdfTeX{} |
| 1341 |
% primitive \tn{pdfescapehex} |
| 1342 |
% \item \texttt{name}, as per the \pdfTeX{} primitive |
| 1343 |
% \tn{pdfescapename} |
| 1344 |
% \item \texttt{string}, as per the \pdfTeX{} primitive |
| 1345 |
% \tn{pdfescapestring} |
| 1346 |
% \item \texttt{url}, as per the percent encoding of urls. |
| 1347 |
% \end{itemize} |
| 1348 |
% |
| 1349 |
% \subsubsection{Unescape methods} |
| 1350 |
% |
| 1351 |
% \begin{macro}{\@@_convert_unescape_hex:} |
| 1352 |
% \begin{macro}[rEXP]{\@@_unescape_hex_auxi:N} |
| 1353 |
% \begin{macro}[rEXP]{\@@_unescape_hex_auxii:N} |
| 1354 |
% Take chars two by two, and interpret each pair as the hexadecimal |
| 1355 |
% code for a byte. Anything else than hexadecimal digits is ignored, |
| 1356 |
% raising the flag. A string which contains an odd number of |
| 1357 |
% hexadecimal digits gets |0| appended to it: this is equivalent to |
| 1358 |
% appending a |0| in all cases, and dropping it if it is alone. |
| 1359 |
% \begin{macrocode} |
| 1360 |
\cs_new_protected:Npn \@@_convert_unescape_hex: |
| 1361 |
{ |
| 1362 |
\group_begin: |
| 1363 |
\flag_clear:N \l_@@_error_flag |
| 1364 |
\int_set:Nn \tex_escapechar:D { 92 } |
| 1365 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 1366 |
{ |
| 1367 |
\@@_output_byte:w " |
| 1368 |
\exp_last_unbraced:Nf \@@_unescape_hex_auxi:N |
| 1369 |
{ \tl_to_str:N \g_@@_result_tl } |
| 1370 |
0 { ? 0 - 1 \prg_break: } |
| 1371 |
\prg_break_point: |
| 1372 |
\@@_output_end: |
| 1373 |
} |
| 1374 |
\@@_if_flag_error:Nne \l_@@_error_flag { unescape-hex } { } |
| 1375 |
\group_end: |
| 1376 |
} |
| 1377 |
\cs_new:Npn \@@_unescape_hex_auxi:N #1 |
| 1378 |
{ |
| 1379 |
\use_none:n #1 |
| 1380 |
\@@_hexadecimal_use:NTF #1 |
| 1381 |
{ \@@_unescape_hex_auxii:N } |
| 1382 |
{ |
| 1383 |
\flag_raise:N \l_@@_error_flag |
| 1384 |
\@@_unescape_hex_auxi:N |
| 1385 |
} |
| 1386 |
} |
| 1387 |
\cs_new:Npn \@@_unescape_hex_auxii:N #1 |
| 1388 |
{ |
| 1389 |
\use_none:n #1 |
| 1390 |
\@@_hexadecimal_use:NTF #1 |
| 1391 |
{ |
| 1392 |
\@@_output_end: |
| 1393 |
\@@_output_byte:w " \@@_unescape_hex_auxi:N |
| 1394 |
} |
| 1395 |
{ |
| 1396 |
\flag_raise:N \l_@@_error_flag |
| 1397 |
\@@_unescape_hex_auxii:N |
| 1398 |
} |
| 1399 |
} |
| 1400 |
\msg_new:nnnn { str } { unescape-hex } |
| 1401 |
{ String~invalid~in~escaping~'hex':~only~hexadecimal~digits~allowed. } |
| 1402 |
{ |
| 1403 |
Some~characters~in~the~string~you~asked~to~convert~are~not~ |
| 1404 |
hexadecimal~digits~(0-9,~A-F,~a-f)~nor~spaces. |
| 1405 |
} |
| 1406 |
% \end{macrocode} |
| 1407 |
% \end{macro} |
| 1408 |
% \end{macro} |
| 1409 |
% \end{macro} |
| 1410 |
% |
| 1411 |
% \begin{macro}{\@@_convert_unescape_name:} |
| 1412 |
% \begin{macro}[rEXP]{\@@_unescape_name_loop:wNN} |
| 1413 |
% \begin{macro}{\@@_convert_unescape_url:} |
| 1414 |
% \begin{macro}[rEXP]{\@@_unescape_url_loop:wNN} |
| 1415 |
% The \cs{@@_convert_unescape_name:} function replaces each |
| 1416 |
% occurrence of |#| followed by two hexadecimal digits in |
| 1417 |
% \cs{g_@@_result_tl} by the corresponding byte. The \texttt{url} |
| 1418 |
% function is identical, with escape character |%| instead of |#|. |
| 1419 |
% Thus we define the two together. The arguments of \cs{@@_tmp:w} are |
| 1420 |
% the character code of |#| or |%| in hexadecimal, the name of the |
| 1421 |
% main function to define, and the name of the auxiliary which |
| 1422 |
% performs the loop. |
| 1423 |
% |
| 1424 |
% The looping auxiliary |#3| finds the next escape character, reads |
| 1425 |
% the following two characters, and tests them. The test |
| 1426 |
% \cs{@@_hexadecimal_use:NTF} leaves the upper-case digit in the |
| 1427 |
% input stream, hence we surround the test with |
| 1428 |
% \cs{@@_output_byte:w}~|"| and \cs{@@_output_end:}. If both |
| 1429 |
% characters are hexadecimal digits, they should be removed before |
| 1430 |
% looping: this is done by \cs{use_i:nnn}. If one of the characters |
| 1431 |
% is not a hexadecimal digit, then feed |"#1| to |
| 1432 |
% \cs{@@_output_byte:w} to produce the escape character, raise the |
| 1433 |
% flag, and call the looping function followed by the two characters |
| 1434 |
% (remove \cs{use_i:nnn}). |
| 1435 |
% \begin{macrocode} |
| 1436 |
\cs_set_protected:Npn \@@_tmp:w #1#2#3 |
| 1437 |
{ |
| 1438 |
\cs_new_protected:cpn { @@_convert_unescape_#2: } |
| 1439 |
{ |
| 1440 |
\group_begin: |
| 1441 |
\flag_clear:N \l_@@_byte_flag |
| 1442 |
\flag_clear:N \l_@@_error_flag |
| 1443 |
\int_set:Nn \tex_escapechar:D { 92 } |
| 1444 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 1445 |
{ |
| 1446 |
\exp_after:wN #3 \g_@@_result_tl |
| 1447 |
#1 ? { ? \prg_break: } |
| 1448 |
\prg_break_point: |
| 1449 |
} |
| 1450 |
\@@_if_flag_error:Nne \l_@@_byte_flag { non-byte } { #2 } |
| 1451 |
\@@_if_flag_error:Nne \l_@@_error_flag { unescape-#2 } { } |
| 1452 |
\group_end: |
| 1453 |
} |
| 1454 |
\cs_new:Npn #3 ##1#1##2##3 |
| 1455 |
{ |
| 1456 |
\@@_filter_bytes:n {##1} |
| 1457 |
\use_none:n ##3 |
| 1458 |
\@@_output_byte:w " |
| 1459 |
\@@_hexadecimal_use:NTF ##2 |
| 1460 |
{ |
| 1461 |
\@@_hexadecimal_use:NTF ##3 |
| 1462 |
{ } |
| 1463 |
{ |
| 1464 |
\flag_raise:N \l_@@_error_flag |
| 1465 |
* 0 + `#1 \use_i:nn |
| 1466 |
} |
| 1467 |
} |
| 1468 |
{ |
| 1469 |
\flag_raise:N \l_@@_error_flag |
| 1470 |
0 + `#1 \use_i:nn |
| 1471 |
} |
| 1472 |
\@@_output_end: |
| 1473 |
\use_i:nnn #3 ##2##3 |
| 1474 |
} |
| 1475 |
\msg_new:nnnn { str } { unescape-#2 } |
| 1476 |
{ String~invalid~in~escaping~'#2'. } |
| 1477 |
{ |
| 1478 |
LaTeX~came~across~the~escape~character~'#1'~not~followed~by~ |
| 1479 |
two~hexadecimal~digits.~This~is~invalid~in~the~escaping~'#2'. |
| 1480 |
} |
| 1481 |
} |
| 1482 |
\exp_after:wN \@@_tmp:w \c_hash_str { name } |
| 1483 |
\@@_unescape_name_loop:wNN |
| 1484 |
\exp_after:wN \@@_tmp:w \c_percent_str { url } |
| 1485 |
\@@_unescape_url_loop:wNN |
| 1486 |
% \end{macrocode} |
| 1487 |
% \end{macro} |
| 1488 |
% \end{macro} |
| 1489 |
% \end{macro} |
| 1490 |
% \end{macro} |
| 1491 |
% |
| 1492 |
% \begin{macro}{\@@_convert_unescape_string:} |
| 1493 |
% \begin{macro}[rEXP]{\@@_unescape_string_newlines:wN} |
| 1494 |
% \begin{macro}[rEXP]{\@@_unescape_string_loop:wNNN} |
| 1495 |
% \begin{macro}[rEXP]{\@@_unescape_string_repeat:NNNNNN} |
| 1496 |
% The \texttt{string} escaping is somewhat similar to the |
| 1497 |
% \texttt{name} and \texttt{url} escapings, with escape character |\|. |
| 1498 |
% The first step is to convert all three line endings, |^^J|, |^^M|, |
| 1499 |
% and |^^M^^J| to the common |^^J|, as per the \textsc{pdf} |
| 1500 |
% specification. This step cannot raise the flag. |
| 1501 |
% |
| 1502 |
% Then the following escape sequences are decoded. |
| 1503 |
% \begin{itemize}\def\makelabel#1{\hss\llap{\ttfamily\string#1}} |
| 1504 |
% \item[\n] Line feed ($10$) |
| 1505 |
% \item[\r] Carriage return ($13$) |
| 1506 |
% \item[\t] Horizontal tab ($9$) |
| 1507 |
% \item[\b] Backspace ($8$) |
| 1508 |
% \item[\f] Form feed ($12$) |
| 1509 |
% \item[\(] Left parenthesis |
| 1510 |
% \item[\)] Right parenthesis |
| 1511 |
% \item[\\] Backslash |
| 1512 |
% \item[\ddd] (backslash followed by $1$ to $3$ octal digits) Byte |
| 1513 |
% \texttt{ddd} (octal), subtracting $256$ in case of overflow. |
| 1514 |
% \end{itemize} |
| 1515 |
% If followed by an end-of-line character, the backslash and the |
| 1516 |
% end-of-line are ignored. If followed by anything else, the backslash |
| 1517 |
% is ignored, raising the error flag. |
| 1518 |
% \begin{macrocode} |
| 1519 |
\group_begin: |
| 1520 |
\char_set_catcode_other:N \^^J |
| 1521 |
\char_set_catcode_other:N \^^M |
| 1522 |
\cs_set_protected:Npn \@@_tmp:w #1 |
| 1523 |
{ |
| 1524 |
\cs_new_protected:Npn \@@_convert_unescape_string: |
| 1525 |
{ |
| 1526 |
\group_begin: |
| 1527 |
\flag_clear:N \l_@@_byte_flag |
| 1528 |
\flag_clear:N \l_@@_error_flag |
| 1529 |
\int_set:Nn \tex_escapechar:D { 92 } |
| 1530 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 1531 |
{ |
| 1532 |
\exp_after:wN \@@_unescape_string_newlines:wN |
| 1533 |
\g_@@_result_tl \prg_break: ^^M ? |
| 1534 |
\prg_break_point: |
| 1535 |
} |
| 1536 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 1537 |
{ |
| 1538 |
\exp_after:wN \@@_unescape_string_loop:wNNN |
| 1539 |
\g_@@_result_tl #1 ?? { ? \prg_break: } |
| 1540 |
\prg_break_point: |
| 1541 |
} |
| 1542 |
\@@_if_flag_error:Nne \l_@@_byte_flag { non-byte } { string } |
| 1543 |
\@@_if_flag_error:Nne \l_@@_error_flag { unescape-string } { } |
| 1544 |
\group_end: |
| 1545 |
} |
| 1546 |
} |
| 1547 |
\exp_args:No \@@_tmp:w { \c_backslash_str } |
| 1548 |
\exp_last_unbraced:NNNNo |
| 1549 |
\cs_new:Npn \@@_unescape_string_loop:wNNN #1 \c_backslash_str #2#3#4 |
| 1550 |
{ |
| 1551 |
\@@_filter_bytes:n {#1} |
| 1552 |
\use_none:n #4 |
| 1553 |
\@@_output_byte:w ' |
| 1554 |
\@@_octal_use:NTF #2 |
| 1555 |
{ |
| 1556 |
\@@_octal_use:NTF #3 |
| 1557 |
{ |
| 1558 |
\@@_octal_use:NTF #4 |
| 1559 |
{ |
| 1560 |
\if_int_compare:w #2 > 3 \exp_stop_f: |
| 1561 |
- 256 |
| 1562 |
\fi: |
| 1563 |
\@@_unescape_string_repeat:NNNNNN |
| 1564 |
} |
| 1565 |
{ \@@_unescape_string_repeat:NNNNNN ? } |
| 1566 |
} |
| 1567 |
{ \@@_unescape_string_repeat:NNNNNN ?? } |
| 1568 |
} |
| 1569 |
{ |
| 1570 |
\str_case_e:nnF {#2} |
| 1571 |
{ |
| 1572 |
{ \c_backslash_str } { 134 } |
| 1573 |
{ ( } { 50 } |
| 1574 |
{ ) } { 51 } |
| 1575 |
{ r } { 15 } |
| 1576 |
{ f } { 14 } |
| 1577 |
{ n } { 12 } |
| 1578 |
{ t } { 11 } |
| 1579 |
{ b } { 10 } |
| 1580 |
{ ^^J } { 0 - 1 } |
| 1581 |
} |
| 1582 |
{ |
| 1583 |
\flag_raise:N \l_@@_error_flag |
| 1584 |
0 - 1 \use_i:nn |
| 1585 |
} |
| 1586 |
} |
| 1587 |
\@@_output_end: |
| 1588 |
\use_i:nn \@@_unescape_string_loop:wNNN #2#3#4 |
| 1589 |
} |
| 1590 |
\cs_new:Npn \@@_unescape_string_repeat:NNNNNN #1#2#3#4#5#6 |
| 1591 |
{ \@@_output_end: \@@_unescape_string_loop:wNNN } |
| 1592 |
\cs_new:Npn \@@_unescape_string_newlines:wN #1 ^^M #2 |
| 1593 |
{ |
| 1594 |
#1 |
| 1595 |
\if_charcode:w ^^J #2 \else: ^^J \fi: |
| 1596 |
\@@_unescape_string_newlines:wN #2 |
| 1597 |
} |
| 1598 |
\msg_new:nnnn { str } { unescape-string } |
| 1599 |
{ String~invalid~in~escaping~'string'. } |
| 1600 |
{ |
| 1601 |
LaTeX~came~across~an~escape~character~'\c_backslash_str'~ |
| 1602 |
not~followed~by~any~of:~'n',~'r',~'t',~'b',~'f',~'(',~')',~ |
| 1603 |
'\c_backslash_str',~one~to~three~octal~digits,~or~the~end~ |
| 1604 |
of~a~line. |
| 1605 |
} |
| 1606 |
\group_end: |
| 1607 |
% \end{macrocode} |
| 1608 |
% \end{macro} |
| 1609 |
% \end{macro} |
| 1610 |
% \end{macro} |
| 1611 |
% \end{macro} |
| 1612 |
% |
| 1613 |
% \subsubsection{Escape methods} |
| 1614 |
% |
| 1615 |
% Currently, none of the escape methods can lead to errors, assuming |
| 1616 |
% that their input is made out of bytes. |
| 1617 |
% |
| 1618 |
% \begin{macro}{\@@_convert_escape_hex:} |
| 1619 |
% \begin{macro}[rEXP]{\@@_escape_hex_char:N} |
| 1620 |
% Loop and convert each byte to hexadecimal. |
| 1621 |
% \begin{macrocode} |
| 1622 |
\cs_new_protected:Npn \@@_convert_escape_hex: |
| 1623 |
{ \@@_convert_gmap:N \@@_escape_hex_char:N } |
| 1624 |
\cs_new:Npn \@@_escape_hex_char:N #1 |
| 1625 |
{ \@@_output_hexadecimal:n { `#1 } } |
| 1626 |
% \end{macrocode} |
| 1627 |
% \end{macro} |
| 1628 |
% \end{macro} |
| 1629 |
% |
| 1630 |
% \begin{macro}{\@@_convert_escape_name:} |
| 1631 |
% \begin{macro}[rEXP]{\@@_escape_name_char:n} |
| 1632 |
% \begin{macro}[rEXP]{\@@_if_escape_name:nTF} |
| 1633 |
% \begin{variable}{\c_@@_escape_name_str} |
| 1634 |
% \begin{variable}{\c_@@_escape_name_not_str} |
| 1635 |
% For each byte, test whether it should be output as is, or be |
| 1636 |
% \enquote{hash-encoded}. Roughly, bytes outside the range |
| 1637 |
% $[\hexnum{2A},\hexnum{7E}]$ are hash-encoded. We keep two lists of |
| 1638 |
% exceptions: characters in \cs{c_@@_escape_name_not_str} are not |
| 1639 |
% hash-encoded, and characters in the \cs{c_@@_escape_name_str} are |
| 1640 |
% encoded. |
| 1641 |
% \begin{macrocode} |
| 1642 |
\str_const:Nn \c_@@_escape_name_not_str { ! " $ & ' } %$ |
| 1643 |
\str_const:Nn \c_@@_escape_name_str { {}/<>[] } |
| 1644 |
\cs_new_protected:Npn \@@_convert_escape_name: |
| 1645 |
{ \@@_convert_gmap:N \@@_escape_name_char:n } |
| 1646 |
\cs_new:Npn \@@_escape_name_char:n #1 |
| 1647 |
{ |
| 1648 |
\@@_if_escape_name:nTF {#1} {#1} |
| 1649 |
{ \c_hash_str \@@_output_hexadecimal:n {`#1} } |
| 1650 |
} |
| 1651 |
\prg_new_conditional:Npnn \@@_if_escape_name:n #1 { TF } |
| 1652 |
{ |
| 1653 |
\if_int_compare:w `#1 < "2A \exp_stop_f: |
| 1654 |
\@@_if_contains_char:NnTF \c_@@_escape_name_not_str {#1} |
| 1655 |
\prg_return_true: \prg_return_false: |
| 1656 |
\else: |
| 1657 |
\if_int_compare:w `#1 > "7E \exp_stop_f: |
| 1658 |
\prg_return_false: |
| 1659 |
\else: |
| 1660 |
\@@_if_contains_char:NnTF \c_@@_escape_name_str {#1} |
| 1661 |
\prg_return_false: \prg_return_true: |
| 1662 |
\fi: |
| 1663 |
\fi: |
| 1664 |
} |
| 1665 |
% \end{macrocode} |
| 1666 |
% \end{variable} |
| 1667 |
% \end{variable} |
| 1668 |
% \end{macro} |
| 1669 |
% \end{macro} |
| 1670 |
% \end{macro} |
| 1671 |
% |
| 1672 |
% \begin{macro}{\@@_convert_escape_string:} |
| 1673 |
% \begin{macro}[rEXP]{\@@_escape_string_char:N} |
| 1674 |
% \begin{macro}[rEXP]{\@@_if_escape_string:NTF} |
| 1675 |
% \begin{variable}{\c_@@_escape_string_str} |
| 1676 |
% Any character below (and including) space, and any character above |
| 1677 |
% (and including) \texttt{del}, are converted to octal. One backslash |
| 1678 |
% is added before each parenthesis and backslash. |
| 1679 |
% \begin{macrocode} |
| 1680 |
\str_const:Ne \c_@@_escape_string_str |
| 1681 |
{ \c_backslash_str ( ) } |
| 1682 |
\cs_new_protected:Npn \@@_convert_escape_string: |
| 1683 |
{ \@@_convert_gmap:N \@@_escape_string_char:N } |
| 1684 |
\cs_new:Npn \@@_escape_string_char:N #1 |
| 1685 |
{ |
| 1686 |
\@@_if_escape_string:NTF #1 |
| 1687 |
{ |
| 1688 |
\@@_if_contains_char:NnT |
| 1689 |
\c_@@_escape_string_str {#1} |
| 1690 |
{ \c_backslash_str } |
| 1691 |
#1 |
| 1692 |
} |
| 1693 |
{ |
| 1694 |
\c_backslash_str |
| 1695 |
\int_div_truncate:nn {`#1} {64} |
| 1696 |
\int_mod:nn { \int_div_truncate:nn {`#1} { 8 } } { 8 } |
| 1697 |
\int_mod:nn {`#1} { 8 } |
| 1698 |
} |
| 1699 |
} |
| 1700 |
\prg_new_conditional:Npnn \@@_if_escape_string:N #1 { TF } |
| 1701 |
{ |
| 1702 |
\if_int_compare:w `#1 < "27 \exp_stop_f: |
| 1703 |
\prg_return_false: |
| 1704 |
\else: |
| 1705 |
\if_int_compare:w `#1 > "7A \exp_stop_f: |
| 1706 |
\prg_return_false: |
| 1707 |
\else: |
| 1708 |
\prg_return_true: |
| 1709 |
\fi: |
| 1710 |
\fi: |
| 1711 |
} |
| 1712 |
% \end{macrocode} |
| 1713 |
% \end{variable} |
| 1714 |
% \end{macro} |
| 1715 |
% \end{macro} |
| 1716 |
% \end{macro} |
| 1717 |
% |
| 1718 |
% \begin{macro}{\@@_convert_escape_url:} |
| 1719 |
% \begin{macro}[rEXP]{\@@_escape_url_char:n} |
| 1720 |
% \begin{macro}[rEXP]{\@@_if_escape_url:nTF} |
| 1721 |
% This function is similar to \cs{@@_convert_escape_name:}, escaping |
| 1722 |
% different characters. |
| 1723 |
% \begin{macrocode} |
| 1724 |
\cs_new_protected:Npn \@@_convert_escape_url: |
| 1725 |
{ \@@_convert_gmap:N \@@_escape_url_char:n } |
| 1726 |
\cs_new:Npn \@@_escape_url_char:n #1 |
| 1727 |
{ |
| 1728 |
\@@_if_escape_url:nTF {#1} {#1} |
| 1729 |
{ \c_percent_str \@@_output_hexadecimal:n { `#1 } } |
| 1730 |
} |
| 1731 |
\prg_new_conditional:Npnn \@@_if_escape_url:n #1 { TF } |
| 1732 |
{ |
| 1733 |
\if_int_compare:w `#1 < "30 \exp_stop_f: |
| 1734 |
\@@_if_contains_char:nnTF { "-. } {#1} |
| 1735 |
\prg_return_true: \prg_return_false: |
| 1736 |
\else: |
| 1737 |
\if_int_compare:w `#1 > "7E \exp_stop_f: |
| 1738 |
\prg_return_false: |
| 1739 |
\else: |
| 1740 |
\@@_if_contains_char:nnTF { : ; = ? @ [ ] } {#1} |
| 1741 |
\prg_return_false: \prg_return_true: |
| 1742 |
\fi: |
| 1743 |
\fi: |
| 1744 |
} |
| 1745 |
% \end{macrocode} |
| 1746 |
% \end{macro} |
| 1747 |
% \end{macro} |
| 1748 |
% \end{macro} |
| 1749 |
% |
| 1750 |
% \subsection{Encoding definitions} |
| 1751 |
% |
| 1752 |
% The \texttt{native} encoding is automatically defined. Other encodings |
| 1753 |
% are loaded as needed. The following encodings are supported: |
| 1754 |
% \begin{itemize} |
| 1755 |
% \item \textsc{utf-8}; |
| 1756 |
% \item \textsc{utf-16}, big-, little-endian, or with byte order mark; |
| 1757 |
% \item \textsc{utf-32}, big-, little-endian, or with byte order mark; |
| 1758 |
% \item the \textsc{iso 8859} code pages, numbered from $1$ to $16$, |
| 1759 |
% skipping the inexistent \textsc{iso 8859-12}. |
| 1760 |
% \end{itemize} |
| 1761 |
% |
| 1762 |
% \subsubsection{\textsc{utf-8} support} |
| 1763 |
% |
| 1764 |
% \begin{macro}{\@@_convert_encode_utf8:} |
| 1765 |
% \begin{macro}[rEXP]{\@@_encode_utf_viii_char:n} |
| 1766 |
% \begin{macro}[rEXP]{\@@_encode_utf_viii_loop:wwnnw} |
| 1767 |
% Loop through the internal string, and convert each character to its |
| 1768 |
% \textsc{utf-8} representation. The representation is built from the |
| 1769 |
% right-most (least significant) byte to the left-most (most |
| 1770 |
% significant) byte. Continuation bytes are in the range $[128,191]$, |
| 1771 |
% taking $64$ different values, hence we roughly want to express the |
| 1772 |
% character code in base $64$, shifting the first digit in the |
| 1773 |
% representation by some number depending on how many continuation |
| 1774 |
% bytes there are. In the range $[0,127]$, output the corresponding |
| 1775 |
% byte directly. In the range $[128,2047]$, output the remainder |
| 1776 |
% modulo $64$, plus $128$ as a continuation byte, then output the |
| 1777 |
% quotient (which is in the range $[0,31]$), shifted by $192$. In the |
| 1778 |
% next range, $[2048,65535]$, split the character code into residue |
| 1779 |
% and quotient modulo $64$, output the residue as a first continuation |
| 1780 |
% byte, then repeat; this leaves us with a quotient in the range |
| 1781 |
% $[0,15]$, which we output shifted by $224$. The last range, |
| 1782 |
% $[65536,1114111]$, follows the same pattern: once we realize that |
| 1783 |
% dividing twice by $64$ leaves us with a number larger than $15$, we |
| 1784 |
% repeat, producing a last continuation byte, and offset the quotient |
| 1785 |
% by $240$ for the leading byte. |
| 1786 |
% |
| 1787 |
% How is that implemented? \cs{@@_encode_utf_vii_loop:wwnnw} takes |
| 1788 |
% successive quotients as its first argument, the quotient from the |
| 1789 |
% previous step as its second argument (except in step~$1$), the bound |
| 1790 |
% for quotients that trigger one more step or not, and finally the |
| 1791 |
% offset used if this step should produce the leading byte. Leading |
| 1792 |
% bytes can be in the ranges $[0,127]$, $[192,223]$, $[224,239]$, and |
| 1793 |
% $[240,247]$ (really, that last limit should be $244$ because Unicode |
| 1794 |
% stops at the code point $1114111$). At each step, if the quotient |
| 1795 |
% |#1| is less than the limit |#3| for that range, output the leading |
| 1796 |
% byte (|#1| shifted by |#4|) and stop. Otherwise, we need one more |
| 1797 |
% step: use the quotient of |#1| by $64$, and |#1| as arguments for |
| 1798 |
% the looping auxiliary, and output the continuation byte |
| 1799 |
% corresponding to the remainder $|#2|-64|#1|+128$. The bizarre |
| 1800 |
% construction |- 1 + 0 *| removes the spurious initial |
| 1801 |
% continuation byte (better methods welcome). |
| 1802 |
% \begin{macrocode} |
| 1803 |
\cs_new_protected:cpn { @@_convert_encode_utf8: } |
| 1804 |
{ \@@_convert_gmap_internal:N \@@_encode_utf_viii_char:n } |
| 1805 |
\cs_new:Npn \@@_encode_utf_viii_char:n #1 |
| 1806 |
{ |
| 1807 |
\@@_encode_utf_viii_loop:wwnnw #1 \@@_sep: - 1 + 0 * \@@_sep: |
| 1808 |
{ 128 } { 0 } |
| 1809 |
{ 32 } { 192 } |
| 1810 |
{ 16 } { 224 } |
| 1811 |
{ 8 } { 240 } |
| 1812 |
\s_@@_stop |
| 1813 |
} |
| 1814 |
\cs_new:Npn \@@_encode_utf_viii_loop:wwnnw |
| 1815 |
#1 \@@_sep: #2 \@@_sep: #3#4 #5 \s_@@_stop |
| 1816 |
{ |
| 1817 |
\if_int_compare:w #1 < #3 \exp_stop_f: |
| 1818 |
\@@_output_byte:n { #1 + #4 } |
| 1819 |
\exp_after:wN \@@_use_none_delimit_by_s_stop:w |
| 1820 |
\fi: |
| 1821 |
\exp_after:wN \@@_encode_utf_viii_loop:wwnnw |
| 1822 |
\int_value:w \int_div_truncate:nn {#1} {64} \@@_sep: #1 \@@_sep: |
| 1823 |
#5 \s_@@_stop |
| 1824 |
\@@_output_byte:n { #2 - 64 * ( #1 - 2 ) } |
| 1825 |
} |
| 1826 |
% \end{macrocode} |
| 1827 |
% \end{macro} |
| 1828 |
% \end{macro} |
| 1829 |
% \end{macro} |
| 1830 |
% |
| 1831 |
% \begin{variable} |
| 1832 |
% { |
| 1833 |
% @@_missing , |
| 1834 |
% @@_extra , |
| 1835 |
% @@_overlong , |
| 1836 |
% @@_overflow , |
| 1837 |
% } |
| 1838 |
% When decoding a string that is purportedly in the \textsc{utf-8} |
| 1839 |
% encoding, four different errors can occur, signaled by a specific |
| 1840 |
% flag for each (we define those flags using \cs{flag_clear_new:N} |
| 1841 |
% rather than \cs{flag_new:N}, because they are shared with other |
| 1842 |
% encoding definition files). |
| 1843 |
% \begin{itemize} |
| 1844 |
% \item \enquote{Missing continuation byte}: a leading byte is not |
| 1845 |
% followed by the right number of continuation bytes. |
| 1846 |
% \item \enquote{Extra continuation byte}: a continuation byte |
| 1847 |
% appears where it was not expected, i.e., not after an |
| 1848 |
% appropriate leading byte. |
| 1849 |
% \item \enquote{Overlong}: a Unicode character is expressed using |
| 1850 |
% more bytes than necessary, for instance, \hexnum{C0}\hexnum{80} |
| 1851 |
% for the code point $0$, instead of a single null byte. |
| 1852 |
% \item \enquote{Overflow}: this occurs when decoding produces |
| 1853 |
% Unicode code points greater than $1114111$. |
| 1854 |
% \end{itemize} |
| 1855 |
% We only raise one \LaTeX3 error message, combining all the errors |
| 1856 |
% which occurred. In the short message, the leading comma must be |
| 1857 |
% removed to get a grammatically correct sentence. In the long text, |
| 1858 |
% first remind the user what a correct \textsc{utf-8} string should |
| 1859 |
% look like, then add error-specific information. |
| 1860 |
% \begin{macrocode} |
| 1861 |
\flag_clear_new:N \l_@@_missing_flag |
| 1862 |
\flag_clear_new:N \l_@@_extra_flag |
| 1863 |
\flag_clear_new:N \l_@@_overlong_flag |
| 1864 |
\flag_clear_new:N \l_@@_overflow_flag |
| 1865 |
\msg_new:nnnn { str } { utf8-decode } |
| 1866 |
{ |
| 1867 |
Invalid~UTF-8~string: |
| 1868 |
\exp_last_unbraced:Nf \use_none:n |
| 1869 |
{ |
| 1870 |
\@@_if_flag_times:NT \l_@@_missing_flag { ,~missing~continuation~byte } |
| 1871 |
\@@_if_flag_times:NT \l_@@_extra_flag { ,~extra~continuation~byte } |
| 1872 |
\@@_if_flag_times:NT \l_@@_overlong_flag { ,~overlong~form } |
| 1873 |
\@@_if_flag_times:NT \l_@@_overflow_flag { ,~code~point~too~large } |
| 1874 |
} |
| 1875 |
. |
| 1876 |
} |
| 1877 |
{ |
| 1878 |
In~the~UTF-8~encoding,~each~Unicode~character~consists~in~ |
| 1879 |
1~to~4~bytes,~with~the~following~bit~pattern: \\ |
| 1880 |
\iow_indent:n |
| 1881 |
{ |
| 1882 |
Code~point~\ \ \ \ <~128:~0xxxxxxx \\ |
| 1883 |
Code~point~\ \ \ <~2048:~110xxxxx~10xxxxxx \\ |
| 1884 |
Code~point~\ \ <~65536:~1110xxxx~10xxxxxx~10xxxxxx \\ |
| 1885 |
Code~point~ <~1114112:~11110xxx~10xxxxxx~10xxxxxx~10xxxxxx \\ |
| 1886 |
} |
| 1887 |
Bytes~of~the~form~10xxxxxx~are~called~continuation~bytes. |
| 1888 |
\flag_if_raised:NT \l_@@_missing_flag |
| 1889 |
{ |
| 1890 |
\\\\ |
| 1891 |
A~leading~byte~(in~the~range~[192,255])~was~not~followed~by~ |
| 1892 |
the~appropriate~number~of~continuation~bytes. |
| 1893 |
} |
| 1894 |
\flag_if_raised:NT \l_@@_extra_flag |
| 1895 |
{ |
| 1896 |
\\\\ |
| 1897 |
LaTeX~came~across~a~continuation~byte~when~it~was~not~expected. |
| 1898 |
} |
| 1899 |
\flag_if_raised:NT \l_@@_overlong_flag |
| 1900 |
{ |
| 1901 |
\\\\ |
| 1902 |
Every~Unicode~code~point~must~be~expressed~in~the~shortest~ |
| 1903 |
possible~form.~For~instance,~'0xC0'~'0x83'~is~not~a~valid~ |
| 1904 |
representation~for~the~code~point~3. |
| 1905 |
} |
| 1906 |
\flag_if_raised:NT \l_@@_overflow_flag |
| 1907 |
{ |
| 1908 |
\\\\ |
| 1909 |
Unicode~limits~code~points~to~the~range~[0,1114111]. |
| 1910 |
} |
| 1911 |
} |
| 1912 |
\prop_gput:Nnn \g_msg_module_name_prop { str } { LaTeX } |
| 1913 |
\prop_gput:Nnn \g_msg_module_type_prop { str } { } |
| 1914 |
% \end{macrocode} |
| 1915 |
% \end{variable} |
| 1916 |
% |
| 1917 |
% \begin{macro}{\@@_convert_decode_utf8:} |
| 1918 |
% \begin{macro}[rEXP] |
| 1919 |
% { |
| 1920 |
% \@@_decode_utf_viii_start:N, |
| 1921 |
% \@@_decode_utf_viii_loop:N, |
| 1922 |
% \@@_decode_utf_viii_continuation:wwN, |
| 1923 |
% \@@_decode_utf_viii_aux:wNnnwN |
| 1924 |
% } |
| 1925 |
% \begin{macro}[rEXP] |
| 1926 |
% {\@@_decode_utf_viii_overflow:w, \@@_decode_utf_viii_end:} |
| 1927 |
% Decoding is significantly harder than encoding. As before, lower |
| 1928 |
% some flags, which are tested at the end (in bulk, to trigger at most |
| 1929 |
% one \LaTeX3 error, as explained above). We expect successive |
| 1930 |
% multi-byte sequences of the form \meta{start byte} |
| 1931 |
% \meta{continuation bytes}. The \texttt{_start} auxiliary tests the |
| 1932 |
% first byte: |
| 1933 |
% \begin{itemize} |
| 1934 |
% \item $[0,\hexnum{7F}]$: the byte stands alone, and is converted |
| 1935 |
% to its own character code; |
| 1936 |
% \item $[\hexnum{80}, \hexnum{BF}]$: unexpected continuation byte, |
| 1937 |
% raise the appropriate flag, and convert that byte to the |
| 1938 |
% replacement character \hexnum{FFFD}; |
| 1939 |
% \item $[\hexnum{C0}, \hexnum{FF}]$: this byte should be followed |
| 1940 |
% by some continuation byte(s). |
| 1941 |
% \end{itemize} |
| 1942 |
% In the first two cases, \cs{use_none_delimit_by_q_stop:w} removes |
| 1943 |
% data that only the third case requires, namely the limits of ranges |
| 1944 |
% of Unicode characters which can be expressed with $1$, $2$, $3$, or |
| 1945 |
% $4$ bytes. |
| 1946 |
% |
| 1947 |
% We can now concentrate on the multi-byte case and the |
| 1948 |
% \texttt{_continuation} auxiliary. We expect |#3| to be in the range |
| 1949 |
% $[\hexnum{80}, \hexnum{BF}]$. The test for this goes as follows: if |
| 1950 |
% the character code is less than \hexnum{80}, we compare it to |
| 1951 |
% $-\hexnum{C0}$, yielding \texttt{false}; otherwise to \hexnum{C0}, |
| 1952 |
% yielding \texttt{true} in the range $[\hexnum{80}, \hexnum{BF}]$ and |
| 1953 |
% \texttt{false} otherwise. If we find that the byte is not a |
| 1954 |
% continuation range, stop the current slew of bytes, output the |
| 1955 |
% replacement character, and continue parsing with the \texttt{_start} |
| 1956 |
% auxiliary, starting at the byte we just tested. Once we know that |
| 1957 |
% the byte is a continuation byte, leave it behind us in the input |
| 1958 |
% stream, compute what code point the bytes read so far would produce, |
| 1959 |
% and feed that number to the \texttt{_aux} function. |
| 1960 |
% |
| 1961 |
% The \texttt{_aux} function tests whether we should look for more |
| 1962 |
% continuation bytes or not. If the number it receives as |#1| is less |
| 1963 |
% than the maximum |#4| for the current range, then we are done: check |
| 1964 |
% for an overlong representation by comparing |#1| with the maximum |
| 1965 |
% |#3| for the previous range. Otherwise, we call the |
| 1966 |
% \texttt{_continuation} auxiliary again, after shifting the |
| 1967 |
% \enquote{current code point} by |#4| (maximum from the range we just |
| 1968 |
% checked). |
| 1969 |
% |
| 1970 |
% Two additional tests are needed: if we reach the end of the list of |
| 1971 |
% range maxima and we are still not done, then we are faced with an |
| 1972 |
% overflow. Clean up, and again insert the code point \hexnum{FFFD} |
| 1973 |
% for the replacement character. Also, every time we read a byte, we |
| 1974 |
% need to check whether we reached the end of the string. In a correct |
| 1975 |
% \textsc{utf-8} string, this happens automatically when the |
| 1976 |
% \texttt{_start} auxiliary leaves its first argument in the input |
| 1977 |
% stream: the end-marker begins with \cs{prg_break:}, which ends |
| 1978 |
% the loop. On the other hand, if the end is reached when looking for |
| 1979 |
% a continuation byte, the \cs{use_none:n} |#3| construction removes |
| 1980 |
% the first token from the end-marker, and leaves the \texttt{_end} |
| 1981 |
% auxiliary, which raises the appropriate error flag before ending the |
| 1982 |
% mapping. |
| 1983 |
% \begin{macrocode} |
| 1984 |
\cs_new_protected:cpn { @@_convert_decode_utf8: } |
| 1985 |
{ |
| 1986 |
\flag_clear:N \l_@@_error_flag |
| 1987 |
\flag_clear:N \l_@@_missing_flag |
| 1988 |
\flag_clear:N \l_@@_extra_flag |
| 1989 |
\flag_clear:N \l_@@_overlong_flag |
| 1990 |
\flag_clear:N \l_@@_overflow_flag |
| 1991 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 1992 |
{ |
| 1993 |
\exp_after:wN \@@_decode_utf_viii_start:N \g_@@_result_tl |
| 1994 |
{ \prg_break: \@@_decode_utf_viii_end: } |
| 1995 |
\prg_break_point: |
| 1996 |
} |
| 1997 |
\@@_if_flag_error:Nne \l_@@_error_flag { utf8-decode } { } |
| 1998 |
} |
| 1999 |
\cs_new:Npn \@@_decode_utf_viii_loop:N #1 |
| 2000 |
{ |
| 2001 |
#1 |
| 2002 |
\if_int_compare:w `#1 < "C0 \exp_stop_f: |
| 2003 |
\s_@@ |
| 2004 |
\if_int_compare:w `#1 < "80 \exp_stop_f: |
| 2005 |
\int_value:w `#1 |
| 2006 |
\else: |
| 2007 |
\flag_raise:N \l_@@_extra_flag |
| 2008 |
\flag_raise:N \l_@@_error_flag |
| 2009 |
\int_use:N \c_@@_replacement_char_int |
| 2010 |
\fi: |
| 2011 |
\else: |
| 2012 |
\exp_after:wN \@@_decode_utf_viii_continuation:wwN |
| 2013 |
\int_value:w \int_eval:n { `#1 - "C0 } \exp_after:wN |
| 2014 |
\fi: |
| 2015 |
\s_@@ |
| 2016 |
\@@_use_none_delimit_by_s_stop:w {"80} {"800} {"10000} {"110000} \s_@@_stop |
| 2017 |
\@@_decode_utf_viii_loop:N |
| 2018 |
} |
| 2019 |
\cs_new_eq:NN \@@_decode_utf_viii_start:N |
| 2020 |
\@@_decode_utf_viii_loop:N |
| 2021 |
\cs_new:Npn \@@_decode_utf_viii_continuation:wwN |
| 2022 |
#1 \s_@@ #2 \@@_decode_utf_viii_loop:N #3 |
| 2023 |
{ |
| 2024 |
\use_none:n #3 |
| 2025 |
\if_int_compare:w `#3 < |
| 2026 |
\if_int_compare:w `#3 < "80 \exp_stop_f: - \fi: |
| 2027 |
"C0 \exp_stop_f: |
| 2028 |
#3 |
| 2029 |
\exp_after:wN \@@_decode_utf_viii_aux:wNnnwN |
| 2030 |
\int_value:w \int_eval:n { #1 * "40 + `#3 - "80 } \exp_after:wN |
| 2031 |
\else: |
| 2032 |
\s_@@ |
| 2033 |
\flag_raise:N \l_@@_missing_flag |
| 2034 |
\flag_raise:N \l_@@_error_flag |
| 2035 |
\int_use:N \c_@@_replacement_char_int |
| 2036 |
\fi: |
| 2037 |
\s_@@ |
| 2038 |
#2 |
| 2039 |
\@@_decode_utf_viii_loop:N #3 |
| 2040 |
} |
| 2041 |
\cs_new:Npn \@@_decode_utf_viii_aux:wNnnwN |
| 2042 |
#1 \s_@@ #2#3#4 #5 \@@_decode_utf_viii_loop:N #6 |
| 2043 |
{ |
| 2044 |
\if_int_compare:w #1 < #4 \exp_stop_f: |
| 2045 |
\s_@@ |
| 2046 |
\if_int_compare:w #1 < #3 \exp_stop_f: |
| 2047 |
\flag_raise:N \l_@@_overlong_flag |
| 2048 |
\flag_raise:N \l_@@_error_flag |
| 2049 |
\int_use:N \c_@@_replacement_char_int |
| 2050 |
\else: |
| 2051 |
#1 |
| 2052 |
\fi: |
| 2053 |
\else: |
| 2054 |
\if_meaning:w \s_@@_stop #5 |
| 2055 |
\@@_decode_utf_viii_overflow:w #1 |
| 2056 |
\fi: |
| 2057 |
\exp_after:wN \@@_decode_utf_viii_continuation:wwN |
| 2058 |
\int_value:w \int_eval:n { #1 - #4 } \exp_after:wN |
| 2059 |
\fi: |
| 2060 |
\s_@@ |
| 2061 |
#2 {#4} #5 |
| 2062 |
\@@_decode_utf_viii_loop:N |
| 2063 |
} |
| 2064 |
\cs_new:Npn \@@_decode_utf_viii_overflow:w #1 \fi: #2 \fi: |
| 2065 |
{ |
| 2066 |
\fi: \fi: |
| 2067 |
\flag_raise:N \l_@@_overflow_flag |
| 2068 |
\flag_raise:N \l_@@_error_flag |
| 2069 |
\int_use:N \c_@@_replacement_char_int |
| 2070 |
} |
| 2071 |
\cs_new:Npn \@@_decode_utf_viii_end: |
| 2072 |
{ |
| 2073 |
\s_@@ |
| 2074 |
\flag_raise:N \l_@@_missing_flag |
| 2075 |
\flag_raise:N \l_@@_error_flag |
| 2076 |
\int_use:N \c_@@_replacement_char_int \s_@@ |
| 2077 |
\prg_break: |
| 2078 |
} |
| 2079 |
% \end{macrocode} |
| 2080 |
% \end{macro} |
| 2081 |
% \end{macro} |
| 2082 |
% \end{macro} |
| 2083 |
% \begin{macro} |
| 2084 |
% { |
| 2085 |
% \@@_decode_utf_viii_start:N , |
| 2086 |
% \@@_decode_utf_viii_start_auxi:N |
| 2087 |
% \@@_decode_utf_viii_start_auxii:N |
| 2088 |
% } |
| 2089 |
% For up\TeX{}, the input approach is more complex as characters in |
| 2090 |
% the Japanese range are not bytes, but others are. To cover this, we |
| 2091 |
% can filter out the problem cases so that internally things more or |
| 2092 |
% less work. |
| 2093 |
% \begin{macrocode} |
| 2094 |
\sys_if_engine_uptex:T |
| 2095 |
{ |
| 2096 |
\cs_new_eq:NN \@@_decode_utf_viii_start_auxi:N |
| 2097 |
\@@_decode_utf_viii_start:N |
| 2098 |
\cs_gset:Npn \@@_decode_utf_viii_start:N #1 |
| 2099 |
{ |
| 2100 |
\if_int_compare:w \tex_kcatcode:D `#1 > 15 \exp_stop_f: |
| 2101 |
\exp_after:wN \@@_decode_utf_viii_start_auxii:N |
| 2102 |
\else: |
| 2103 |
\exp_after:wN \@@_decode_utf_viii_start_auxi:N |
| 2104 |
\fi: |
| 2105 |
#1 |
| 2106 |
} |
| 2107 |
\cs_new:Npn \@@_decode_utf_viii_start_auxii:N #1 |
| 2108 |
{ |
| 2109 |
#1 |
| 2110 |
\s_@@ |
| 2111 |
\int_eval:n {`#1} |
| 2112 |
\s_@@ |
| 2113 |
\prg_break: \@@_decode_utf_viii_end: |
| 2114 |
} |
| 2115 |
} |
| 2116 |
% \end{macrocode} |
| 2117 |
% \end{macro} |
| 2118 |
% |
| 2119 |
% \subsubsection{\textsc{utf-16} support} |
| 2120 |
% |
| 2121 |
% The definitions are done in a category code régime where the bytes |
| 2122 |
% $254$ and $255$ used by the byte order mark have catcode~$12$. |
| 2123 |
% \begin{macrocode} |
| 2124 |
\group_begin: |
| 2125 |
\char_set_catcode_other:N \^^fe |
| 2126 |
\char_set_catcode_other:N \^^ff |
| 2127 |
% \end{macrocode} |
| 2128 |
% |
| 2129 |
% \begin{macro} |
| 2130 |
% { |
| 2131 |
% \@@_convert_encode_utf16: , |
| 2132 |
% \@@_convert_encode_utf16be: , |
| 2133 |
% \@@_convert_encode_utf16le: , |
| 2134 |
% } |
| 2135 |
% \begin{macro}[rEXP] |
| 2136 |
% { |
| 2137 |
% \@@_encode_utf_xvi_aux:N , |
| 2138 |
% \@@_encode_utf_xvi_char:n , |
| 2139 |
% } |
| 2140 |
% When the endianness is not specified, it is big-endian by default, |
| 2141 |
% and we add a byte-order mark. Convert characters one by one in a |
| 2142 |
% loop, with different behaviors depending on the character code. |
| 2143 |
% \begin{itemize} |
| 2144 |
% \item $[0, \hexnum{D7FF}]$: converted to two bytes; |
| 2145 |
% \item $[\hexnum{D800}, \hexnum{DFFF}]$ are used as surrogates: |
| 2146 |
% they cannot be converted and are replaced by the replacement |
| 2147 |
% character; |
| 2148 |
% \item $[\hexnum{E000}, \hexnum{FFFF}]$: converted to two bytes; |
| 2149 |
% \item $[\hexnum{10000}, \hexnum{10FFFF}]$: converted to a pair of |
| 2150 |
% surrogates, each two bytes. The magic \hexnum{D7C0} is |
| 2151 |
% $\hexnum{D800}-\hexnum{10000}/\hexnum{400}$. |
| 2152 |
% \end{itemize} |
| 2153 |
% For the duration of this operation, \cs{@@_tmp:w} is defined as a |
| 2154 |
% function to convert a number in the range $[0, \hexnum{FFFF}]$ to a |
| 2155 |
% pair of bytes (either big endian or little endian), by feeding the |
| 2156 |
% quotient of the division of |#1| by \hexnum{100}, followed by |#1| |
| 2157 |
% to \cs{@@_encode_utf_xvi_be:nn} or its \texttt{le} analog: those |
| 2158 |
% compute the remainder, and output two bytes for the quotient and |
| 2159 |
% remainder. |
| 2160 |
% \begin{macrocode} |
| 2161 |
\cs_new_protected:cpn { @@_convert_encode_utf16: } |
| 2162 |
{ |
| 2163 |
\@@_encode_utf_xvi_aux:N \@@_output_byte_pair_be:n |
| 2164 |
\tl_gput_left:Ne \g_@@_result_tl { ^^fe ^^ff } |
| 2165 |
} |
| 2166 |
\cs_new_protected:cpn { @@_convert_encode_utf16be: } |
| 2167 |
{ \@@_encode_utf_xvi_aux:N \@@_output_byte_pair_be:n } |
| 2168 |
\cs_new_protected:cpn { @@_convert_encode_utf16le: } |
| 2169 |
{ \@@_encode_utf_xvi_aux:N \@@_output_byte_pair_le:n } |
| 2170 |
\cs_new_protected:Npn \@@_encode_utf_xvi_aux:N #1 |
| 2171 |
{ |
| 2172 |
\flag_clear:N \l_@@_error_flag |
| 2173 |
\cs_set_eq:NN \@@_tmp:w #1 |
| 2174 |
\@@_convert_gmap_internal:N \@@_encode_utf_xvi_char:n |
| 2175 |
\@@_if_flag_error:Nne \l_@@_error_flag { utf16-encode } { } |
| 2176 |
} |
| 2177 |
\cs_new:Npn \@@_encode_utf_xvi_char:n #1 |
| 2178 |
{ |
| 2179 |
\if_int_compare:w #1 < "D800 \exp_stop_f: |
| 2180 |
\@@_tmp:w {#1} |
| 2181 |
\else: |
| 2182 |
\if_int_compare:w #1 < "10000 \exp_stop_f: |
| 2183 |
\if_int_compare:w #1 < "E000 \exp_stop_f: |
| 2184 |
\flag_raise:N \l_@@_error_flag |
| 2185 |
\@@_tmp:w { \c_@@_replacement_char_int } |
| 2186 |
\else: |
| 2187 |
\@@_tmp:w {#1} |
| 2188 |
\fi: |
| 2189 |
\else: |
| 2190 |
\exp_args:Nf \@@_tmp:w { \int_div_truncate:nn {#1} {"400} + "D7C0 } |
| 2191 |
\exp_args:Nf \@@_tmp:w { \int_mod:nn {#1} {"400} + "DC00 } |
| 2192 |
\fi: |
| 2193 |
\fi: |
| 2194 |
} |
| 2195 |
% \end{macrocode} |
| 2196 |
% \end{macro} |
| 2197 |
% \end{macro} |
| 2198 |
% |
| 2199 |
% \begin{variable} |
| 2200 |
% { |
| 2201 |
% @@_missing , |
| 2202 |
% @@_extra , |
| 2203 |
% @@_end , |
| 2204 |
% } |
| 2205 |
% When encoding a Unicode string to \textsc{utf-16}, only one error |
| 2206 |
% can occur: code points in the range $[\hexnum{D800}, |
| 2207 |
% \hexnum{DFFF}]$, corresponding to surrogates, cannot be encoded. We |
| 2208 |
% use the all-purpose flag \texttt{@@_error} to signal that error. |
| 2209 |
% |
| 2210 |
% When decoding a Unicode string which is purportedly in |
| 2211 |
% \textsc{utf-16}, three errors can occur: a missing trail surrogate, |
| 2212 |
% an unexpected trail surrogate, and a string containing an odd number |
| 2213 |
% of bytes. |
| 2214 |
% \begin{macrocode} |
| 2215 |
\flag_clear_new:N \l_@@_missing_flag |
| 2216 |
\flag_clear_new:N \l_@@_extra_flag |
| 2217 |
\flag_clear_new:N \l_@@_end_flag |
| 2218 |
\msg_new:nnnn { str } { utf16-encode } |
| 2219 |
{ Unicode~string~cannot~be~expressed~in~UTF-16:~surrogate. } |
| 2220 |
{ |
| 2221 |
Surrogate~code~points~(in~the~range~[U+D800,~U+DFFF])~ |
| 2222 |
can~be~expressed~in~the~UTF-8~and~UTF-32~encodings,~ |
| 2223 |
but~not~in~the~UTF-16~encoding. |
| 2224 |
} |
| 2225 |
\msg_new:nnnn { str } { utf16-decode } |
| 2226 |
{ |
| 2227 |
Invalid~UTF-16~string: |
| 2228 |
\exp_last_unbraced:Nf \use_none:n |
| 2229 |
{ |
| 2230 |
\@@_if_flag_times:NT \l_@@_missing_flag { ,~missing~trail~surrogate } |
| 2231 |
\@@_if_flag_times:NT \l_@@_extra_flag { ,~extra~trail~surrogate } |
| 2232 |
\@@_if_flag_times:NT \l_@@_end_flag { ,~odd~number~of~bytes } |
| 2233 |
} |
| 2234 |
. |
| 2235 |
} |
| 2236 |
{ |
| 2237 |
In~the~UTF-16~encoding,~each~Unicode~character~is~encoded~as~ |
| 2238 |
2~or~4~bytes: \\ |
| 2239 |
\iow_indent:n |
| 2240 |
{ |
| 2241 |
Code~point~in~[U+0000,~U+D7FF]:~two~bytes \\ |
| 2242 |
Code~point~in~[U+D800,~U+DFFF]:~illegal \\ |
| 2243 |
Code~point~in~[U+E000,~U+FFFF]:~two~bytes \\ |
| 2244 |
Code~point~in~[U+10000,~U+10FFFF]:~ |
| 2245 |
a~lead~surrogate~and~a~trail~surrogate \\ |
| 2246 |
} |
| 2247 |
Lead~surrogates~are~pairs~of~bytes~in~the~range~[0xD800,~0xDBFF],~ |
| 2248 |
and~trail~surrogates~are~in~the~range~[0xDC00,~0xDFFF]. |
| 2249 |
\flag_if_raised:NT \l_@@_missing_flag |
| 2250 |
{ |
| 2251 |
\\\\ |
| 2252 |
A~lead~surrogate~was~not~followed~by~a~trail~surrogate. |
| 2253 |
} |
| 2254 |
\flag_if_raised:NT \l_@@_extra_flag |
| 2255 |
{ |
| 2256 |
\\\\ |
| 2257 |
LaTeX~came~across~a~trail~surrogate~when~it~was~not~expected. |
| 2258 |
} |
| 2259 |
\flag_if_raised:NT \l_@@_end_flag |
| 2260 |
{ |
| 2261 |
\\\\ |
| 2262 |
The~string~contained~an~odd~number~of~bytes.~This~is~invalid:~ |
| 2263 |
the~basic~code~unit~for~UTF-16~is~16~bits~(2~bytes). |
| 2264 |
} |
| 2265 |
} |
| 2266 |
% \end{macrocode} |
| 2267 |
% \end{variable} |
| 2268 |
% |
| 2269 |
% \begin{macro} |
| 2270 |
% { |
| 2271 |
% \@@_convert_decode_utf16: , |
| 2272 |
% \@@_convert_decode_utf16be: , |
| 2273 |
% \@@_convert_decode_utf16le: , |
| 2274 |
% } |
| 2275 |
% \begin{macro}{\@@_decode_utf_xvi_bom:NN, \@@_decode_utf_xvi:Nw} |
| 2276 |
% As for \textsc{utf-8}, decoding \textsc{utf-16} is harder than |
| 2277 |
% encoding it. If the endianness is unknown, check the first two |
| 2278 |
% bytes: if those are \hexnum{FE} and \hexnum{FF} in either order, |
| 2279 |
% remove them and use the corresponding endianness, otherwise assume |
| 2280 |
% big-endianness. The three endianness cases are based on a common |
| 2281 |
% auxiliary whose first argument is $1$ for big-endian and $2$ for |
| 2282 |
% little-endian, and whose second argument, delimited by the scan mark |
| 2283 |
% \cs{s_@@_stop}, is expanded once (the string may be long; passing |
| 2284 |
% \cs{g_@@_result_tl} as an argument before expansion is cheaper). |
| 2285 |
% |
| 2286 |
% The \cs{@@_decode_utf_xvi:Nw} function defines \cs{@@_tmp:w} to |
| 2287 |
% take two arguments and return the character code of the first one if |
| 2288 |
% the string is big-endian, and the second one if the string is |
| 2289 |
% little-endian, then loops over the string using |
| 2290 |
% \cs{@@_decode_utf_xvi_pair:NN} described below. |
| 2291 |
% \begin{macrocode} |
| 2292 |
\cs_new_protected:cpn { @@_convert_decode_utf16be: } |
| 2293 |
{ \@@_decode_utf_xvi:Nw 1 \g_@@_result_tl \s_@@_stop } |
| 2294 |
\cs_new_protected:cpn { @@_convert_decode_utf16le: } |
| 2295 |
{ \@@_decode_utf_xvi:Nw 2 \g_@@_result_tl \s_@@_stop } |
| 2296 |
\cs_new_protected:cpn { @@_convert_decode_utf16: } |
| 2297 |
{ |
| 2298 |
\exp_after:wN \@@_decode_utf_xvi_bom:NN |
| 2299 |
\g_@@_result_tl \s_@@_stop \s_@@_stop \s_@@_stop |
| 2300 |
} |
| 2301 |
\cs_new_protected:Npn \@@_decode_utf_xvi_bom:NN #1#2 |
| 2302 |
{ |
| 2303 |
\str_if_eq:nnTF { #1#2 } { ^^ff ^^fe } |
| 2304 |
{ \@@_decode_utf_xvi:Nw 2 } |
| 2305 |
{ |
| 2306 |
\str_if_eq:nnTF { #1#2 } { ^^fe ^^ff } |
| 2307 |
{ \@@_decode_utf_xvi:Nw 1 } |
| 2308 |
{ \@@_decode_utf_xvi:Nw 1 #1#2 } |
| 2309 |
} |
| 2310 |
} |
| 2311 |
\cs_new_protected:Npn \@@_decode_utf_xvi:Nw #1#2 \s_@@_stop |
| 2312 |
{ |
| 2313 |
\flag_clear:N \l_@@_error_flag |
| 2314 |
\flag_clear:N \l_@@_missing_flag |
| 2315 |
\flag_clear:N \l_@@_extra_flag |
| 2316 |
\flag_clear:N \l_@@_end_flag |
| 2317 |
\cs_set:Npn \@@_tmp:w ##1 ##2 { ` ## #1 } |
| 2318 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 2319 |
{ |
| 2320 |
\exp_after:wN \@@_decode_utf_xvi_pair:NN |
| 2321 |
#2 \q_@@_nil \q_@@_nil |
| 2322 |
\prg_break_point: |
| 2323 |
} |
| 2324 |
\@@_if_flag_error:Nne \l_@@_error_flag { utf16-decode } { } |
| 2325 |
} |
| 2326 |
% \end{macrocode} |
| 2327 |
% \end{macro} |
| 2328 |
% \end{macro} |
| 2329 |
% |
| 2330 |
% \begin{macro}[rEXP] |
| 2331 |
% { |
| 2332 |
% \@@_decode_utf_xvi_pair:NN , |
| 2333 |
% \@@_decode_utf_xvi_quad:NNwNN , |
| 2334 |
% \@@_decode_utf_xvi_pair_end:Nw , |
| 2335 |
% } |
| 2336 |
% \begin{macro}[rEXP] |
| 2337 |
% { |
| 2338 |
% \@@_decode_utf_xvi_error:nNN , |
| 2339 |
% \@@_decode_utf_xvi_extra:NNw , |
| 2340 |
% } |
| 2341 |
% Bytes are read two at a time. At this stage, |\@@_tmp:w #1#2| |
| 2342 |
% expands to the character code of the most significant byte, and we |
| 2343 |
% distinguish cases depending on which range it lies in: |
| 2344 |
% \begin{itemize} |
| 2345 |
% \item $[\hexnum{D8}, \hexnum{DB}]$ signals a lead surrogate, and |
| 2346 |
% the integer expression yields $1$ (\eTeX{} rounds ties away from |
| 2347 |
% zero); |
| 2348 |
% \item $[\hexnum{DC}, \hexnum{DF}]$ signals a trail surrogate, |
| 2349 |
% unexpected here, and the integer expression yields $2$; |
| 2350 |
% \item any other value signals a code point in the Basic |
| 2351 |
% Multilingual Plane, which stands for itself, and the |
| 2352 |
% \cs{if_case:w} construction expands to nothing (cases other than |
| 2353 |
% $1$ or $2$), leaving the relevant material in the input stream, |
| 2354 |
% followed by another call to the \texttt{_pair} auxiliary. |
| 2355 |
% \end{itemize} |
| 2356 |
% The case of a lead surrogate is treated by the \texttt{_quad} |
| 2357 |
% auxiliary, whose arguments |#1|, |#2|, |#4| and |#5| are the four |
| 2358 |
% bytes. We expect the most significant byte of |#4#5| to be in the |
| 2359 |
% range $[\hexnum{DC}, \hexnum{DF}]$ (trail surrogate). The test is |
| 2360 |
% similar to the test used for continuation bytes in the |
| 2361 |
% \textsc{utf-8} decoding functions. In the case where |#4#5| is |
| 2362 |
% indeed a trail surrogate, leave |#1#2#4#5| \cs{s_@@} |
| 2363 |
% \meta{code~point} \cs{s_@@}, and remove the pair |#4#5| before |
| 2364 |
% looping with \cs{@@_decode_utf_xvi_pair:NN}. Otherwise, of course, |
| 2365 |
% complain about the missing surrogate. |
| 2366 |
% |
| 2367 |
% The magic number \hexnum{D7F7} is such that |
| 2368 |
% $\hexnum{D7F7}*\hexnum{400} = \hexnum{D800}*\hexnum{400} + |
| 2369 |
% \hexnum{DC00} - \hexnum{10000}$. |
| 2370 |
% |
| 2371 |
% Every time we read a pair of bytes, we test for the end-marker |
| 2372 |
% \cs{q_@@_nil}. When reaching the end, we additionally check that the |
| 2373 |
% string had an even length. Also, if the end is reached when |
| 2374 |
% expecting a trail surrogate, we treat that as a missing surrogate. |
| 2375 |
% \begin{macrocode} |
| 2376 |
\cs_new:Npn \@@_decode_utf_xvi_pair:NN #1#2 |
| 2377 |
{ |
| 2378 |
\if_meaning:w \q_@@_nil #2 |
| 2379 |
\@@_decode_utf_xvi_pair_end:Nw #1 |
| 2380 |
\fi: |
| 2381 |
\if_case:w |
| 2382 |
\int_eval:n { ( \@@_tmp:w #1#2 - "D6 ) / 4 } \scan_stop: |
| 2383 |
\or: \exp_after:wN \@@_decode_utf_xvi_quad:NNwNN |
| 2384 |
\or: \exp_after:wN \@@_decode_utf_xvi_extra:NNw |
| 2385 |
\fi: |
| 2386 |
#1#2 \s_@@ |
| 2387 |
\int_eval:n { "100 * \@@_tmp:w #1#2 + \@@_tmp:w #2#1 } \s_@@ |
| 2388 |
\@@_decode_utf_xvi_pair:NN |
| 2389 |
} |
| 2390 |
\cs_new:Npn \@@_decode_utf_xvi_quad:NNwNN |
| 2391 |
#1#2 #3 \@@_decode_utf_xvi_pair:NN #4#5 |
| 2392 |
{ |
| 2393 |
\if_meaning:w \q_@@_nil #5 |
| 2394 |
\@@_decode_utf_xvi_error:nNN { missing } #1#2 |
| 2395 |
\@@_decode_utf_xvi_pair_end:Nw #4 |
| 2396 |
\fi: |
| 2397 |
\if_int_compare:w |
| 2398 |
\if_int_compare:w \@@_tmp:w #4#5 < "DC \exp_stop_f: |
| 2399 |
0 = 1 |
| 2400 |
\else: |
| 2401 |
\@@_tmp:w #4#5 < "E0 |
| 2402 |
\fi: |
| 2403 |
\exp_stop_f: |
| 2404 |
#1 #2 #4 #5 \s_@@ |
| 2405 |
\int_eval:n |
| 2406 |
{ |
| 2407 |
( "100 * \@@_tmp:w #1#2 + \@@_tmp:w #2#1 - "D7F7 ) * "400 |
| 2408 |
+ "100 * \@@_tmp:w #4#5 + \@@_tmp:w #5#4 |
| 2409 |
} |
| 2410 |
\s_@@ |
| 2411 |
\exp_after:wN \use_i:nnn |
| 2412 |
\else: |
| 2413 |
\@@_decode_utf_xvi_error:nNN { missing } #1#2 |
| 2414 |
\fi: |
| 2415 |
\@@_decode_utf_xvi_pair:NN #4#5 |
| 2416 |
} |
| 2417 |
\cs_new:Npn \@@_decode_utf_xvi_pair_end:Nw #1 \fi: |
| 2418 |
{ |
| 2419 |
\fi: |
| 2420 |
\if_meaning:w \q_@@_nil #1 |
| 2421 |
\else: |
| 2422 |
\@@_decode_utf_xvi_error:nNN { end } #1 \prg_do_nothing: |
| 2423 |
\fi: |
| 2424 |
\prg_break: |
| 2425 |
} |
| 2426 |
\cs_new:Npn \@@_decode_utf_xvi_extra:NNw #1#2 \s_@@ #3 \s_@@ |
| 2427 |
{ \@@_decode_utf_xvi_error:nNN { extra } #1#2 } |
| 2428 |
\cs_new:Npn \@@_decode_utf_xvi_error:nNN #1#2#3 |
| 2429 |
{ |
| 2430 |
\flag_raise:N \l_@@_error_flag |
| 2431 |
\flag_raise:c { l_@@_#1_flag } |
| 2432 |
#2 #3 \s_@@ |
| 2433 |
\int_use:N \c_@@_replacement_char_int \s_@@ |
| 2434 |
} |
| 2435 |
% \end{macrocode} |
| 2436 |
% \end{macro} |
| 2437 |
% \end{macro} |
| 2438 |
% |
| 2439 |
% Restore the original catcodes of bytes $254$ and $255$. |
| 2440 |
% \begin{macrocode} |
| 2441 |
\group_end: |
| 2442 |
% \end{macrocode} |
| 2443 |
% |
| 2444 |
% \subsubsection{\textsc{utf-32} support} |
| 2445 |
% |
| 2446 |
% The definitions are done in a category code régime where the bytes |
| 2447 |
% $0$, $254$ and $255$ used by the byte order mark have catcode |
| 2448 |
% \enquote{other}. |
| 2449 |
% \begin{macrocode} |
| 2450 |
\group_begin: |
| 2451 |
\char_set_catcode_other:N \^^00 |
| 2452 |
\char_set_catcode_other:N \^^fe |
| 2453 |
\char_set_catcode_other:N \^^ff |
| 2454 |
% \end{macrocode} |
| 2455 |
% |
| 2456 |
% \begin{macro} |
| 2457 |
% { |
| 2458 |
% \@@_convert_encode_utf32: , |
| 2459 |
% \@@_convert_encode_utf32be: , |
| 2460 |
% \@@_convert_encode_utf32le: , |
| 2461 |
% } |
| 2462 |
% \begin{macro}[rEXP] |
| 2463 |
% { |
| 2464 |
% \@@_encode_utf_xxxii_be:n , |
| 2465 |
% \@@_encode_utf_xxxii_be_aux:nn , |
| 2466 |
% \@@_encode_utf_xxxii_le:n , |
| 2467 |
% \@@_encode_utf_xxxii_le_aux:nn , |
| 2468 |
% } |
| 2469 |
% Convert each integer in the comma-list \cs{g_@@_result_tl} to a |
| 2470 |
% sequence of four bytes. The functions for big-endian and |
| 2471 |
% little-endian encodings are very similar, but the |
| 2472 |
% \cs{@@_output_byte:n} instructions are reversed. |
| 2473 |
% \begin{macrocode} |
| 2474 |
\cs_new_protected:cpn { @@_convert_encode_utf32: } |
| 2475 |
{ |
| 2476 |
\@@_convert_gmap_internal:N \@@_encode_utf_xxxii_be:n |
| 2477 |
\tl_gput_left:Ne \g_@@_result_tl { ^^00 ^^00 ^^fe ^^ff } |
| 2478 |
} |
| 2479 |
\cs_new_protected:cpn { @@_convert_encode_utf32be: } |
| 2480 |
{ \@@_convert_gmap_internal:N \@@_encode_utf_xxxii_be:n } |
| 2481 |
\cs_new_protected:cpn { @@_convert_encode_utf32le: } |
| 2482 |
{ \@@_convert_gmap_internal:N \@@_encode_utf_xxxii_le:n } |
| 2483 |
\cs_new:Npn \@@_encode_utf_xxxii_be:n #1 |
| 2484 |
{ |
| 2485 |
\exp_args:Nf \@@_encode_utf_xxxii_be_aux:nn |
| 2486 |
{ \int_div_truncate:nn {#1} { "100 } } {#1} |
| 2487 |
} |
| 2488 |
\cs_new:Npn \@@_encode_utf_xxxii_be_aux:nn #1#2 |
| 2489 |
{ |
| 2490 |
^^00 |
| 2491 |
\@@_output_byte_pair_be:n {#1} |
| 2492 |
\@@_output_byte:n { #2 - #1 * "100 } |
| 2493 |
} |
| 2494 |
\cs_new:Npn \@@_encode_utf_xxxii_le:n #1 |
| 2495 |
{ |
| 2496 |
\exp_args:Nf \@@_encode_utf_xxxii_le_aux:nn |
| 2497 |
{ \int_div_truncate:nn {#1} { "100 } } {#1} |
| 2498 |
} |
| 2499 |
\cs_new:Npn \@@_encode_utf_xxxii_le_aux:nn #1#2 |
| 2500 |
{ |
| 2501 |
\@@_output_byte:n { #2 - #1 * "100 } |
| 2502 |
\@@_output_byte_pair_le:n {#1} |
| 2503 |
^^00 |
| 2504 |
} |
| 2505 |
% \end{macrocode} |
| 2506 |
% \end{macro} |
| 2507 |
% \end{macro} |
| 2508 |
% |
| 2509 |
% \begin{variable}{@@_overflow, @@_end} |
| 2510 |
% There can be no error when encoding in \textsc{utf-32}. When |
| 2511 |
% decoding, the string may not have length $4n$, or it may contain |
| 2512 |
% code points larger than \hexnum{10FFFF}. The latter case often |
| 2513 |
% happens if the encoding was in fact not \textsc{utf-32}, because |
| 2514 |
% most arbitrary strings are not valid in \textsc{utf-32}. |
| 2515 |
% \begin{macrocode} |
| 2516 |
\flag_clear_new:N \l_@@_overflow_flag |
| 2517 |
\flag_clear_new:N \l_@@_end_flag |
| 2518 |
\msg_new:nnnn { str } { utf32-decode } |
| 2519 |
{ |
| 2520 |
Invalid~UTF-32~string: |
| 2521 |
\exp_last_unbraced:Nf \use_none:n |
| 2522 |
{ |
| 2523 |
\@@_if_flag_times:NT \l_@@_overflow_flag { ,~code~point~too~large } |
| 2524 |
\@@_if_flag_times:NT \l_@@_end_flag { ,~truncated~string } |
| 2525 |
} |
| 2526 |
. |
| 2527 |
} |
| 2528 |
{ |
| 2529 |
In~the~UTF-32~encoding,~every~Unicode~character~ |
| 2530 |
(in~the~range~[U+0000,~U+10FFFF])~is~encoded~as~4~bytes. |
| 2531 |
\flag_if_raised:NT \l_@@_overflow_flag |
| 2532 |
{ |
| 2533 |
\\\\ |
| 2534 |
LaTeX~came~across~a~code~point~larger~than~1114111,~ |
| 2535 |
the~maximum~code~point~defined~by~Unicode.~ |
| 2536 |
Perhaps~the~string~was~not~encoded~in~the~UTF-32~encoding? |
| 2537 |
} |
| 2538 |
\flag_if_raised:NT \l_@@_end_flag |
| 2539 |
{ |
| 2540 |
\\\\ |
| 2541 |
The~length~of~the~string~is~not~a~multiple~of~4.~ |
| 2542 |
Perhaps~the~string~was~truncated? |
| 2543 |
} |
| 2544 |
} |
| 2545 |
% \end{macrocode} |
| 2546 |
% \end{variable} |
| 2547 |
% |
| 2548 |
% \begin{macro} |
| 2549 |
% { |
| 2550 |
% \@@_convert_decode_utf32: , |
| 2551 |
% \@@_convert_decode_utf32be: , |
| 2552 |
% \@@_convert_decode_utf32le: , |
| 2553 |
% } |
| 2554 |
% \begin{macro} |
| 2555 |
% {\@@_decode_utf_xxxii_bom:NNNN, \@@_decode_utf_xxxii:Nw} |
| 2556 |
% \begin{macro}[rEXP] |
| 2557 |
% {\@@_decode_utf_xxxii_loop:NNNN, \@@_decode_utf_xxxii_end:w} |
| 2558 |
% |
| 2559 |
% The structure is similar to \textsc{utf-16} decoding functions. If |
| 2560 |
% the endianness is not given, test the first $4$ bytes of the string |
| 2561 |
% (possibly \cs{s_@@_stop} if the string is too short) for the presence |
| 2562 |
% of a byte-order mark. If there is a byte-order mark, use that |
| 2563 |
% endianness, and remove the $4$ bytes, otherwise default to |
| 2564 |
% big-endian, and leave the $4$ bytes in place. The |
| 2565 |
% \cs{@@_decode_utf_xxxii:Nw} auxiliary receives $1$ or $2$ as its |
| 2566 |
% first argument indicating endianness, and the string to convert as |
| 2567 |
% its second argument (expanded or not). It sets \cs{@@_tmp:w} to |
| 2568 |
% expand to the character code of either of its two arguments |
| 2569 |
% depending on endianness, then triggers the \texttt{_loop} auxiliary |
| 2570 |
% inside an \texttt{e}-expanding assignment to \cs{g_@@_result_tl}. |
| 2571 |
% |
| 2572 |
% The \texttt{_loop} auxiliary first checks for the end-of-string |
| 2573 |
% marker \cs{s_@@_stop}, calling the \texttt{_end} auxiliary if |
| 2574 |
% appropriate. Otherwise, leave the \meta{4~bytes} \cs{s_@@} behind, |
| 2575 |
% then check that the code point is not overflowing: the leading byte |
| 2576 |
% must be $0$, and the following byte at most $16$. |
| 2577 |
% |
| 2578 |
% In the ending code, we check that there remains no byte: there |
| 2579 |
% should be nothing left until the first \cs{s_@@_stop}. Break the map. |
| 2580 |
% \begin{macrocode} |
| 2581 |
\cs_new_protected:cpn { @@_convert_decode_utf32be: } |
| 2582 |
{ \@@_decode_utf_xxxii:Nw 1 \g_@@_result_tl \s_@@_stop } |
| 2583 |
\cs_new_protected:cpn { @@_convert_decode_utf32le: } |
| 2584 |
{ \@@_decode_utf_xxxii:Nw 2 \g_@@_result_tl \s_@@_stop } |
| 2585 |
\cs_new_protected:cpn { @@_convert_decode_utf32: } |
| 2586 |
{ |
| 2587 |
\exp_after:wN \@@_decode_utf_xxxii_bom:NNNN \g_@@_result_tl |
| 2588 |
\s_@@_stop \s_@@_stop \s_@@_stop \s_@@_stop \s_@@_stop |
| 2589 |
} |
| 2590 |
\cs_new_protected:Npn \@@_decode_utf_xxxii_bom:NNNN #1#2#3#4 |
| 2591 |
{ |
| 2592 |
\str_if_eq:nnTF { #1#2#3#4 } { ^^ff ^^fe ^^00 ^^00 } |
| 2593 |
{ \@@_decode_utf_xxxii:Nw 2 } |
| 2594 |
{ |
| 2595 |
\str_if_eq:nnTF { #1#2#3#4 } { ^^00 ^^00 ^^fe ^^ff } |
| 2596 |
{ \@@_decode_utf_xxxii:Nw 1 } |
| 2597 |
{ \@@_decode_utf_xxxii:Nw 1 #1#2#3#4 } |
| 2598 |
} |
| 2599 |
} |
| 2600 |
\cs_new_protected:Npn \@@_decode_utf_xxxii:Nw #1#2 \s_@@_stop |
| 2601 |
{ |
| 2602 |
\flag_clear:N \l_@@_overflow_flag |
| 2603 |
\flag_clear:N \l_@@_end_flag |
| 2604 |
\flag_clear:N \l_@@_error_flag |
| 2605 |
\cs_set:Npn \@@_tmp:w ##1 ##2 { ` ## #1 } |
| 2606 |
\__kernel_tl_gset:Nx \g_@@_result_tl |
| 2607 |
{ |
| 2608 |
\exp_after:wN \@@_decode_utf_xxxii_loop:NNNN |
| 2609 |
#2 \s_@@_stop \s_@@_stop \s_@@_stop \s_@@_stop |
| 2610 |
\prg_break_point: |
| 2611 |
} |
| 2612 |
\@@_if_flag_error:Nne \l_@@_error_flag { utf32-decode } { } |
| 2613 |
} |
| 2614 |
\cs_new:Npn \@@_decode_utf_xxxii_loop:NNNN #1#2#3#4 |
| 2615 |
{ |
| 2616 |
\if_meaning:w \s_@@_stop #4 |
| 2617 |
\exp_after:wN \@@_decode_utf_xxxii_end:w |
| 2618 |
\fi: |
| 2619 |
#1#2#3#4 \s_@@ |
| 2620 |
\if_int_compare:w \@@_tmp:w #1#4 > \c_zero_int |
| 2621 |
\flag_raise:N \l_@@_overflow_flag |
| 2622 |
\flag_raise:N \l_@@_error_flag |
| 2623 |
\int_use:N \c_@@_replacement_char_int |
| 2624 |
\else: |
| 2625 |
\if_int_compare:w \@@_tmp:w #2#3 > 16 \exp_stop_f: |
| 2626 |
\flag_raise:N \l_@@_overflow_flag |
| 2627 |
\flag_raise:N \l_@@_error_flag |
| 2628 |
\int_use:N \c_@@_replacement_char_int |
| 2629 |
\else: |
| 2630 |
\int_eval:n |
| 2631 |
{ \@@_tmp:w #2#3*"10000 + \@@_tmp:w #3#2*"100 + \@@_tmp:w #4#1 } |
| 2632 |
\fi: |
| 2633 |
\fi: |
| 2634 |
\s_@@ |
| 2635 |
\@@_decode_utf_xxxii_loop:NNNN |
| 2636 |
} |
| 2637 |
\cs_new:Npn \@@_decode_utf_xxxii_end:w #1 \s_@@_stop |
| 2638 |
{ |
| 2639 |
\tl_if_empty:nF {#1} |
| 2640 |
{ |
| 2641 |
\flag_raise:N \l_@@_end_flag |
| 2642 |
\flag_raise:N \l_@@_error_flag |
| 2643 |
#1 \s_@@ |
| 2644 |
\int_use:N \c_@@_replacement_char_int \s_@@ |
| 2645 |
} |
| 2646 |
\prg_break: |
| 2647 |
} |
| 2648 |
% \end{macrocode} |
| 2649 |
% \end{macro} |
| 2650 |
% \end{macro} |
| 2651 |
% \end{macro} |
| 2652 |
% |
| 2653 |
% Restore the original catcodes of bytes $0$, $254$ and $255$. |
| 2654 |
% \begin{macrocode} |
| 2655 |
\group_end: |
| 2656 |
% \end{macrocode} |
| 2657 |
% |
| 2658 |
% \subsection{PDF names and strings by expansion} |
| 2659 |
% |
| 2660 |
% \begin{macro}[EXP]{\str_convert_pdfname:n} |
| 2661 |
% \begin{macro}[EXP]{\@@_convert_pdfname:n} |
| 2662 |
% \begin{macro}[EXP] |
| 2663 |
% {\@@_convert_pdfname_bytes:n, \@@_convert_pdfname_bytes_aux:n} |
| 2664 |
% \begin{macro}[EXP]{\@@_convert_pdfname_bytes_aux:nnn} |
| 2665 |
% To convert to PDF names by expansion, we work purely on UTF-8 input. The |
| 2666 |
% first step is to make a string with \enquote{other} spaces, |
| 2667 |
% after which we use a simple token-by-token approach. In Unicode |
| 2668 |
% engines, we break down everything before one-byte codepoints, but for |
| 2669 |
% $8$-bit engines there is no need to worry. Actual escaping is covered |
| 2670 |
% by the same code as used in the non-expandable route. |
| 2671 |
% \begin{macrocode} |
| 2672 |
\cs_new:Npn \str_convert_pdfname:n #1 |
| 2673 |
{ |
| 2674 |
\exp_args:Ne \tl_to_str:n |
| 2675 |
{ \str_map_function:nN {#1} \@@_convert_pdfname:n } |
| 2676 |
} |
| 2677 |
\sys_if_engine_opentype:TF |
| 2678 |
{ |
| 2679 |
\cs_new:Npn \@@_convert_pdfname:n #1 |
| 2680 |
{ |
| 2681 |
\int_compare:nNnTF { `#1 } > { "7F } |
| 2682 |
{ \@@_convert_pdfname_bytes:n {#1} } |
| 2683 |
{ \@@_escape_name_char:n {#1} } |
| 2684 |
} |
| 2685 |
\cs_new:Npn \@@_convert_pdfname_bytes:n #1 |
| 2686 |
{ |
| 2687 |
\exp_args:Ne \@@_convert_pdfname_bytes_aux:n |
| 2688 |
{ \__kernel_codepoint_to_bytes:n {`#1} } |
| 2689 |
} |
| 2690 |
\cs_new:Npn \@@_convert_pdfname_bytes_aux:n #1 |
| 2691 |
{ \@@_convert_pdfname_bytes_aux:nnnn #1 } |
| 2692 |
\cs_new:Npe \@@_convert_pdfname_bytes_aux:nnnn #1#2#3#4 |
| 2693 |
{ |
| 2694 |
\c_hash_str \exp_not:N \@@_output_hexadecimal:n {#1} |
| 2695 |
\c_hash_str \exp_not:N \@@_output_hexadecimal:n {#2} |
| 2696 |
\exp_not:N \tl_if_blank:nF {#3} |
| 2697 |
{ |
| 2698 |
\c_hash_str \exp_not:N \@@_output_hexadecimal:n {#3} |
| 2699 |
\exp_not:N \tl_if_blank:nF {#4} |
| 2700 |
{ |
| 2701 |
\c_hash_str \exp_not:N \@@_output_hexadecimal:n {#4} |
| 2702 |
} |
| 2703 |
} |
| 2704 |
} |
| 2705 |
} |
| 2706 |
{ \cs_new_eq:NN \@@_convert_pdfname:n \@@_escape_name_char:n } |
| 2707 |
% \end{macrocode} |
| 2708 |
% \end{macro} |
| 2709 |
% \end{macro} |
| 2710 |
% \end{macro} |
| 2711 |
% \end{macro} |
| 2712 |
% |
| 2713 |
% \begin{macrocode} |
| 2714 |
%</code> |
| 2715 |
% \end{macrocode} |
| 2716 |
% |
| 2717 |
% \subsubsection{\textsc{iso 8859} support} |
| 2718 |
% |
| 2719 |
% The \textsc{iso-8859-1} encoding exactly matches with the $256$ first |
| 2720 |
% Unicode characters. For other 8-bit encodings of the \textsc{iso-8859} |
| 2721 |
% family, we keep track only of differences, and of unassigned bytes. |
| 2722 |
% \begin{macrocode} |
| 2723 |
%<*iso88591> |
| 2724 |
\@@_declare_eight_bit_encoding:nnnn { iso88591 } { 256 } |
| 2725 |
{ |
| 2726 |
} |
| 2727 |
{ |
| 2728 |
} |
| 2729 |
%</iso88591> |
| 2730 |
% \end{macrocode} |
| 2731 |
% |
| 2732 |
% \begin{macrocode} |
| 2733 |
%<*iso88592> |
| 2734 |
\@@_declare_eight_bit_encoding:nnnn { iso88592 } { 399 } |
| 2735 |
{ |
| 2736 |
{ A1 } { 0104 } |
| 2737 |
{ A2 } { 02D8 } |
| 2738 |
{ A3 } { 0141 } |
| 2739 |
{ A5 } { 013D } |
| 2740 |
{ A6 } { 015A } |
| 2741 |
{ A9 } { 0160 } |
| 2742 |
{ AA } { 015E } |
| 2743 |
{ AB } { 0164 } |
| 2744 |
{ AC } { 0179 } |
| 2745 |
{ AE } { 017D } |
| 2746 |
{ AF } { 017B } |
| 2747 |
{ B1 } { 0105 } |
| 2748 |
{ B2 } { 02DB } |
| 2749 |
{ B3 } { 0142 } |
| 2750 |
{ B5 } { 013E } |
| 2751 |
{ B6 } { 015B } |
| 2752 |
{ B7 } { 02C7 } |
| 2753 |
{ B9 } { 0161 } |
| 2754 |
{ BA } { 015F } |
| 2755 |
{ BB } { 0165 } |
| 2756 |
{ BC } { 017A } |
| 2757 |
{ BD } { 02DD } |
| 2758 |
{ BE } { 017E } |
| 2759 |
{ BF } { 017C } |
| 2760 |
{ C0 } { 0154 } |
| 2761 |
{ C3 } { 0102 } |
| 2762 |
{ C5 } { 0139 } |
| 2763 |
{ C6 } { 0106 } |
| 2764 |
{ C8 } { 010C } |
| 2765 |
{ CA } { 0118 } |
| 2766 |
{ CC } { 011A } |
| 2767 |
{ CF } { 010E } |
| 2768 |
{ D0 } { 0110 } |
| 2769 |
{ D1 } { 0143 } |
| 2770 |
{ D2 } { 0147 } |
| 2771 |
{ D5 } { 0150 } |
| 2772 |
{ D8 } { 0158 } |
| 2773 |
{ D9 } { 016E } |
| 2774 |
{ DB } { 0170 } |
| 2775 |
{ DE } { 0162 } |
| 2776 |
{ E0 } { 0155 } |
| 2777 |
{ E3 } { 0103 } |
| 2778 |
{ E5 } { 013A } |
| 2779 |
{ E6 } { 0107 } |
| 2780 |
{ E8 } { 010D } |
| 2781 |
{ EA } { 0119 } |
| 2782 |
{ EC } { 011B } |
| 2783 |
{ EF } { 010F } |
| 2784 |
{ F0 } { 0111 } |
| 2785 |
{ F1 } { 0144 } |
| 2786 |
{ F2 } { 0148 } |
| 2787 |
{ F5 } { 0151 } |
| 2788 |
{ F8 } { 0159 } |
| 2789 |
{ F9 } { 016F } |
| 2790 |
{ FB } { 0171 } |
| 2791 |
{ FE } { 0163 } |
| 2792 |
{ FF } { 02D9 } |
| 2793 |
} |
| 2794 |
{ |
| 2795 |
} |
| 2796 |
%</iso88592> |
| 2797 |
% \end{macrocode} |
| 2798 |
% |
| 2799 |
% \begin{macrocode} |
| 2800 |
%<*iso88593> |
| 2801 |
\@@_declare_eight_bit_encoding:nnnn { iso88593 } { 384 } |
| 2802 |
{ |
| 2803 |
{ A1 } { 0126 } |
| 2804 |
{ A2 } { 02D8 } |
| 2805 |
{ A6 } { 0124 } |
| 2806 |
{ A9 } { 0130 } |
| 2807 |
{ AA } { 015E } |
| 2808 |
{ AB } { 011E } |
| 2809 |
{ AC } { 0134 } |
| 2810 |
{ AF } { 017B } |
| 2811 |
{ B1 } { 0127 } |
| 2812 |
{ B6 } { 0125 } |
| 2813 |
{ B9 } { 0131 } |
| 2814 |
{ BA } { 015F } |
| 2815 |
{ BB } { 011F } |
| 2816 |
{ BC } { 0135 } |
| 2817 |
{ BF } { 017C } |
| 2818 |
{ C5 } { 010A } |
| 2819 |
{ C6 } { 0108 } |
| 2820 |
{ D5 } { 0120 } |
| 2821 |
{ D8 } { 011C } |
| 2822 |
{ DD } { 016C } |
| 2823 |
{ DE } { 015C } |
| 2824 |
{ E5 } { 010B } |
| 2825 |
{ E6 } { 0109 } |
| 2826 |
{ F5 } { 0121 } |
| 2827 |
{ F8 } { 011D } |
| 2828 |
{ FD } { 016D } |
| 2829 |
{ FE } { 015D } |
| 2830 |
{ FF } { 02D9 } |
| 2831 |
} |
| 2832 |
{ |
| 2833 |
{ A5 } |
| 2834 |
{ AE } |
| 2835 |
{ BE } |
| 2836 |
{ C3 } |
| 2837 |
{ D0 } |
| 2838 |
{ E3 } |
| 2839 |
{ F0 } |
| 2840 |
} |
| 2841 |
%</iso88593> |
| 2842 |
% \end{macrocode} |
| 2843 |
% |
| 2844 |
% \begin{macrocode} |
| 2845 |
%<*iso88594> |
| 2846 |
\@@_declare_eight_bit_encoding:nnnn { iso88594 } { 383 } |
| 2847 |
{ |
| 2848 |
{ A1 } { 0104 } |
| 2849 |
{ A2 } { 0138 } |
| 2850 |
{ A3 } { 0156 } |
| 2851 |
{ A5 } { 0128 } |
| 2852 |
{ A6 } { 013B } |
| 2853 |
{ A9 } { 0160 } |
| 2854 |
{ AA } { 0112 } |
| 2855 |
{ AB } { 0122 } |
| 2856 |
{ AC } { 0166 } |
| 2857 |
{ AE } { 017D } |
| 2858 |
{ B1 } { 0105 } |
| 2859 |
{ B2 } { 02DB } |
| 2860 |
{ B3 } { 0157 } |
| 2861 |
{ B5 } { 0129 } |
| 2862 |
{ B6 } { 013C } |
| 2863 |
{ B7 } { 02C7 } |
| 2864 |
{ B9 } { 0161 } |
| 2865 |
{ BA } { 0113 } |
| 2866 |
{ BB } { 0123 } |
| 2867 |
{ BC } { 0167 } |
| 2868 |
{ BD } { 014A } |
| 2869 |
{ BE } { 017E } |
| 2870 |
{ BF } { 014B } |
| 2871 |
{ C0 } { 0100 } |
| 2872 |
{ C7 } { 012E } |
| 2873 |
{ C8 } { 010C } |
| 2874 |
{ CA } { 0118 } |
| 2875 |
{ CC } { 0116 } |
| 2876 |
{ CF } { 012A } |
| 2877 |
{ D0 } { 0110 } |
| 2878 |
{ D1 } { 0145 } |
| 2879 |
{ D2 } { 014C } |
| 2880 |
{ D3 } { 0136 } |
| 2881 |
{ D9 } { 0172 } |
| 2882 |
{ DD } { 0168 } |
| 2883 |
{ DE } { 016A } |
| 2884 |
{ E0 } { 0101 } |
| 2885 |
{ E7 } { 012F } |
| 2886 |
{ E8 } { 010D } |
| 2887 |
{ EA } { 0119 } |
| 2888 |
{ EC } { 0117 } |
| 2889 |
{ EF } { 012B } |
| 2890 |
{ F0 } { 0111 } |
| 2891 |
{ F1 } { 0146 } |
| 2892 |
{ F2 } { 014D } |
| 2893 |
{ F3 } { 0137 } |
| 2894 |
{ F9 } { 0173 } |
| 2895 |
{ FD } { 0169 } |
| 2896 |
{ FE } { 016B } |
| 2897 |
{ FF } { 02D9 } |
| 2898 |
} |
| 2899 |
{ |
| 2900 |
} |
| 2901 |
%</iso88594> |
| 2902 |
% \end{macrocode} |
| 2903 |
% |
| 2904 |
% \begin{macrocode} |
| 2905 |
%<*iso88595> |
| 2906 |
\@@_declare_eight_bit_encoding:nnnn { iso88595 } { 374 } |
| 2907 |
{ |
| 2908 |
{ A1 } { 0401 } |
| 2909 |
{ A2 } { 0402 } |
| 2910 |
{ A3 } { 0403 } |
| 2911 |
{ A4 } { 0404 } |
| 2912 |
{ A5 } { 0405 } |
| 2913 |
{ A6 } { 0406 } |
| 2914 |
{ A7 } { 0407 } |
| 2915 |
{ A8 } { 0408 } |
| 2916 |
{ A9 } { 0409 } |
| 2917 |
{ AA } { 040A } |
| 2918 |
{ AB } { 040B } |
| 2919 |
{ AC } { 040C } |
| 2920 |
{ AE } { 040E } |
| 2921 |
{ AF } { 040F } |
| 2922 |
{ B0 } { 0410 } |
| 2923 |
{ B1 } { 0411 } |
| 2924 |
{ B2 } { 0412 } |
| 2925 |
{ B3 } { 0413 } |
| 2926 |
{ B4 } { 0414 } |
| 2927 |
{ B5 } { 0415 } |
| 2928 |
{ B6 } { 0416 } |
| 2929 |
{ B7 } { 0417 } |
| 2930 |
{ B8 } { 0418 } |
| 2931 |
{ B9 } { 0419 } |
| 2932 |
{ BA } { 041A } |
| 2933 |
{ BB } { 041B } |
| 2934 |
{ BC } { 041C } |
| 2935 |
{ BD } { 041D } |
| 2936 |
{ BE } { 041E } |
| 2937 |
{ BF } { 041F } |
| 2938 |
{ C0 } { 0420 } |
| 2939 |
{ C1 } { 0421 } |
| 2940 |
{ C2 } { 0422 } |
| 2941 |
{ C3 } { 0423 } |
| 2942 |
{ C4 } { 0424 } |
| 2943 |
{ C5 } { 0425 } |
| 2944 |
{ C6 } { 0426 } |
| 2945 |
{ C7 } { 0427 } |
| 2946 |
{ C8 } { 0428 } |
| 2947 |
{ C9 } { 0429 } |
| 2948 |
{ CA } { 042A } |
| 2949 |
{ CB } { 042B } |
| 2950 |
{ CC } { 042C } |
| 2951 |
{ CD } { 042D } |
| 2952 |
{ CE } { 042E } |
| 2953 |
{ CF } { 042F } |
| 2954 |
{ D0 } { 0430 } |
| 2955 |
{ D1 } { 0431 } |
| 2956 |
{ D2 } { 0432 } |
| 2957 |
{ D3 } { 0433 } |
| 2958 |
{ D4 } { 0434 } |
| 2959 |
{ D5 } { 0435 } |
| 2960 |
{ D6 } { 0436 } |
| 2961 |
{ D7 } { 0437 } |
| 2962 |
{ D8 } { 0438 } |
| 2963 |
{ D9 } { 0439 } |
| 2964 |
{ DA } { 043A } |
| 2965 |
{ DB } { 043B } |
| 2966 |
{ DC } { 043C } |
| 2967 |
{ DD } { 043D } |
| 2968 |
{ DE } { 043E } |
| 2969 |
{ DF } { 043F } |
| 2970 |
{ E0 } { 0440 } |
| 2971 |
{ E1 } { 0441 } |
| 2972 |
{ E2 } { 0442 } |
| 2973 |
{ E3 } { 0443 } |
| 2974 |
{ E4 } { 0444 } |
| 2975 |
{ E5 } { 0445 } |
| 2976 |
{ E6 } { 0446 } |
| 2977 |
{ E7 } { 0447 } |
| 2978 |
{ E8 } { 0448 } |
| 2979 |
{ E9 } { 0449 } |
| 2980 |
{ EA } { 044A } |
| 2981 |
{ EB } { 044B } |
| 2982 |
{ EC } { 044C } |
| 2983 |
{ ED } { 044D } |
| 2984 |
{ EE } { 044E } |
| 2985 |
{ EF } { 044F } |
| 2986 |
{ F0 } { 2116 } |
| 2987 |
{ F1 } { 0451 } |
| 2988 |
{ F2 } { 0452 } |
| 2989 |
{ F3 } { 0453 } |
| 2990 |
{ F4 } { 0454 } |
| 2991 |
{ F5 } { 0455 } |
| 2992 |
{ F6 } { 0456 } |
| 2993 |
{ F7 } { 0457 } |
| 2994 |
{ F8 } { 0458 } |
| 2995 |
{ F9 } { 0459 } |
| 2996 |
{ FA } { 045A } |
| 2997 |
{ FB } { 045B } |
| 2998 |
{ FC } { 045C } |
| 2999 |
{ FD } { 00A7 } |
| 3000 |
{ FE } { 045E } |
| 3001 |
{ FF } { 045F } |
| 3002 |
} |
| 3003 |
{ |
| 3004 |
} |
| 3005 |
%</iso88595> |
| 3006 |
% \end{macrocode} |
| 3007 |
% |
| 3008 |
% \begin{macrocode} |
| 3009 |
%<*iso88596> |
| 3010 |
\@@_declare_eight_bit_encoding:nnnn { iso88596 } { 344 } |
| 3011 |
{ |
| 3012 |
{ AC } { 060C } |
| 3013 |
{ BB } { 061B } |
| 3014 |
{ BF } { 061F } |
| 3015 |
{ C1 } { 0621 } |
| 3016 |
{ C2 } { 0622 } |
| 3017 |
{ C3 } { 0623 } |
| 3018 |
{ C4 } { 0624 } |
| 3019 |
{ C5 } { 0625 } |
| 3020 |
{ C6 } { 0626 } |
| 3021 |
{ C7 } { 0627 } |
| 3022 |
{ C8 } { 0628 } |
| 3023 |
{ C9 } { 0629 } |
| 3024 |
{ CA } { 062A } |
| 3025 |
{ CB } { 062B } |
| 3026 |
{ CC } { 062C } |
| 3027 |
{ CD } { 062D } |
| 3028 |
{ CE } { 062E } |
| 3029 |
{ CF } { 062F } |
| 3030 |
{ D0 } { 0630 } |
| 3031 |
{ D1 } { 0631 } |
| 3032 |
{ D2 } { 0632 } |
| 3033 |
{ D3 } { 0633 } |
| 3034 |
{ D4 } { 0634 } |
| 3035 |
{ D5 } { 0635 } |
| 3036 |
{ D6 } { 0636 } |
| 3037 |
{ D7 } { 0637 } |
| 3038 |
{ D8 } { 0638 } |
| 3039 |
{ D9 } { 0639 } |
| 3040 |
{ DA } { 063A } |
| 3041 |
{ E0 } { 0640 } |
| 3042 |
{ E1 } { 0641 } |
| 3043 |
{ E2 } { 0642 } |
| 3044 |
{ E3 } { 0643 } |
| 3045 |
{ E4 } { 0644 } |
| 3046 |
{ E5 } { 0645 } |
| 3047 |
{ E6 } { 0646 } |
| 3048 |
{ E7 } { 0647 } |
| 3049 |
{ E8 } { 0648 } |
| 3050 |
{ E9 } { 0649 } |
| 3051 |
{ EA } { 064A } |
| 3052 |
{ EB } { 064B } |
| 3053 |
{ EC } { 064C } |
| 3054 |
{ ED } { 064D } |
| 3055 |
{ EE } { 064E } |
| 3056 |
{ EF } { 064F } |
| 3057 |
{ F0 } { 0650 } |
| 3058 |
{ F1 } { 0651 } |
| 3059 |
{ F2 } { 0652 } |
| 3060 |
} |
| 3061 |
{ |
| 3062 |
{ A1 } |
| 3063 |
{ A2 } |
| 3064 |
{ A3 } |
| 3065 |
{ A5 } |
| 3066 |
{ A6 } |
| 3067 |
{ A7 } |
| 3068 |
{ A8 } |
| 3069 |
{ A9 } |
| 3070 |
{ AA } |
| 3071 |
{ AB } |
| 3072 |
{ AE } |
| 3073 |
{ AF } |
| 3074 |
{ B0 } |
| 3075 |
{ B1 } |
| 3076 |
{ B2 } |
| 3077 |
{ B3 } |
| 3078 |
{ B4 } |
| 3079 |
{ B5 } |
| 3080 |
{ B6 } |
| 3081 |
{ B7 } |
| 3082 |
{ B8 } |
| 3083 |
{ B9 } |
| 3084 |
{ BA } |
| 3085 |
{ BC } |
| 3086 |
{ BD } |
| 3087 |
{ BE } |
| 3088 |
{ C0 } |
| 3089 |
{ DB } |
| 3090 |
{ DC } |
| 3091 |
{ DD } |
| 3092 |
{ DE } |
| 3093 |
{ DF } |
| 3094 |
} |
| 3095 |
%</iso88596> |
| 3096 |
% \end{macrocode} |
| 3097 |
% |
| 3098 |
% \begin{macrocode} |
| 3099 |
%<*iso88597> |
| 3100 |
\@@_declare_eight_bit_encoding:nnnn { iso88597 } { 498 } |
| 3101 |
{ |
| 3102 |
{ A1 } { 2018 } |
| 3103 |
{ A2 } { 2019 } |
| 3104 |
{ A4 } { 20AC } |
| 3105 |
{ A5 } { 20AF } |
| 3106 |
{ AA } { 037A } |
| 3107 |
{ AF } { 2015 } |
| 3108 |
{ B4 } { 0384 } |
| 3109 |
{ B5 } { 0385 } |
| 3110 |
{ B6 } { 0386 } |
| 3111 |
{ B8 } { 0388 } |
| 3112 |
{ B9 } { 0389 } |
| 3113 |
{ BA } { 038A } |
| 3114 |
{ BC } { 038C } |
| 3115 |
{ BE } { 038E } |
| 3116 |
{ BF } { 038F } |
| 3117 |
{ C0 } { 0390 } |
| 3118 |
{ C1 } { 0391 } |
| 3119 |
{ C2 } { 0392 } |
| 3120 |
{ C3 } { 0393 } |
| 3121 |
{ C4 } { 0394 } |
| 3122 |
{ C5 } { 0395 } |
| 3123 |
{ C6 } { 0396 } |
| 3124 |
{ C7 } { 0397 } |
| 3125 |
{ C8 } { 0398 } |
| 3126 |
{ C9 } { 0399 } |
| 3127 |
{ CA } { 039A } |
| 3128 |
{ CB } { 039B } |
| 3129 |
{ CC } { 039C } |
| 3130 |
{ CD } { 039D } |
| 3131 |
{ CE } { 039E } |
| 3132 |
{ CF } { 039F } |
| 3133 |
{ D0 } { 03A0 } |
| 3134 |
{ D1 } { 03A1 } |
| 3135 |
{ D3 } { 03A3 } |
| 3136 |
{ D4 } { 03A4 } |
| 3137 |
{ D5 } { 03A5 } |
| 3138 |
{ D6 } { 03A6 } |
| 3139 |
{ D7 } { 03A7 } |
| 3140 |
{ D8 } { 03A8 } |
| 3141 |
{ D9 } { 03A9 } |
| 3142 |
{ DA } { 03AA } |
| 3143 |
{ DB } { 03AB } |
| 3144 |
{ DC } { 03AC } |
| 3145 |
{ DD } { 03AD } |
| 3146 |
{ DE } { 03AE } |
| 3147 |
{ DF } { 03AF } |
| 3148 |
{ E0 } { 03B0 } |
| 3149 |
{ E1 } { 03B1 } |
| 3150 |
{ E2 } { 03B2 } |
| 3151 |
{ E3 } { 03B3 } |
| 3152 |
{ E4 } { 03B4 } |
| 3153 |
{ E5 } { 03B5 } |
| 3154 |
{ E6 } { 03B6 } |
| 3155 |
{ E7 } { 03B7 } |
| 3156 |
{ E8 } { 03B8 } |
| 3157 |
{ E9 } { 03B9 } |
| 3158 |
{ EA } { 03BA } |
| 3159 |
{ EB } { 03BB } |
| 3160 |
{ EC } { 03BC } |
| 3161 |
{ ED } { 03BD } |
| 3162 |
{ EE } { 03BE } |
| 3163 |
{ EF } { 03BF } |
| 3164 |
{ F0 } { 03C0 } |
| 3165 |
{ F1 } { 03C1 } |
| 3166 |
{ F2 } { 03C2 } |
| 3167 |
{ F3 } { 03C3 } |
| 3168 |
{ F4 } { 03C4 } |
| 3169 |
{ F5 } { 03C5 } |
| 3170 |
{ F6 } { 03C6 } |
| 3171 |
{ F7 } { 03C7 } |
| 3172 |
{ F8 } { 03C8 } |
| 3173 |
{ F9 } { 03C9 } |
| 3174 |
{ FA } { 03CA } |
| 3175 |
{ FB } { 03CB } |
| 3176 |
{ FC } { 03CC } |
| 3177 |
{ FD } { 03CD } |
| 3178 |
{ FE } { 03CE } |
| 3179 |
} |
| 3180 |
{ |
| 3181 |
{ AE } |
| 3182 |
{ D2 } |
| 3183 |
} |
| 3184 |
%</iso88597> |
| 3185 |
% \end{macrocode} |
| 3186 |
% |
| 3187 |
% \begin{macrocode} |
| 3188 |
%<*iso88598> |
| 3189 |
\@@_declare_eight_bit_encoding:nnnn { iso88598 } { 308 } |
| 3190 |
{ |
| 3191 |
{ AA } { 00D7 } |
| 3192 |
{ BA } { 00F7 } |
| 3193 |
{ DF } { 2017 } |
| 3194 |
{ E0 } { 05D0 } |
| 3195 |
{ E1 } { 05D1 } |
| 3196 |
{ E2 } { 05D2 } |
| 3197 |
{ E3 } { 05D3 } |
| 3198 |
{ E4 } { 05D4 } |
| 3199 |
{ E5 } { 05D5 } |
| 3200 |
{ E6 } { 05D6 } |
| 3201 |
{ E7 } { 05D7 } |
| 3202 |
{ E8 } { 05D8 } |
| 3203 |
{ E9 } { 05D9 } |
| 3204 |
{ EA } { 05DA } |
| 3205 |
{ EB } { 05DB } |
| 3206 |
{ EC } { 05DC } |
| 3207 |
{ ED } { 05DD } |
| 3208 |
{ EE } { 05DE } |
| 3209 |
{ EF } { 05DF } |
| 3210 |
{ F0 } { 05E0 } |
| 3211 |
{ F1 } { 05E1 } |
| 3212 |
{ F2 } { 05E2 } |
| 3213 |
{ F3 } { 05E3 } |
| 3214 |
{ F4 } { 05E4 } |
| 3215 |
{ F5 } { 05E5 } |
| 3216 |
{ F6 } { 05E6 } |
| 3217 |
{ F7 } { 05E7 } |
| 3218 |
{ F8 } { 05E8 } |
| 3219 |
{ F9 } { 05E9 } |
| 3220 |
{ FA } { 05EA } |
| 3221 |
{ FD } { 200E } |
| 3222 |
{ FE } { 200F } |
| 3223 |
} |
| 3224 |
{ |
| 3225 |
{ A1 } |
| 3226 |
{ BF } |
| 3227 |
{ C0 } |
| 3228 |
{ C1 } |
| 3229 |
{ C2 } |
| 3230 |
{ C3 } |
| 3231 |
{ C4 } |
| 3232 |
{ C5 } |
| 3233 |
{ C6 } |
| 3234 |
{ C7 } |
| 3235 |
{ C8 } |
| 3236 |
{ C9 } |
| 3237 |
{ CA } |
| 3238 |
{ CB } |
| 3239 |
{ CC } |
| 3240 |
{ CD } |
| 3241 |
{ CE } |
| 3242 |
{ CF } |
| 3243 |
{ D0 } |
| 3244 |
{ D1 } |
| 3245 |
{ D2 } |
| 3246 |
{ D3 } |
| 3247 |
{ D4 } |
| 3248 |
{ D5 } |
| 3249 |
{ D6 } |
| 3250 |
{ D7 } |
| 3251 |
{ D8 } |
| 3252 |
{ D9 } |
| 3253 |
{ DA } |
| 3254 |
{ DB } |
| 3255 |
{ DC } |
| 3256 |
{ DD } |
| 3257 |
{ DE } |
| 3258 |
{ FB } |
| 3259 |
{ FC } |
| 3260 |
} |
| 3261 |
%</iso88598> |
| 3262 |
% \end{macrocode} |
| 3263 |
% |
| 3264 |
% \begin{macrocode} |
| 3265 |
%<*iso88599> |
| 3266 |
\@@_declare_eight_bit_encoding:nnnn { iso88599 } { 352 } |
| 3267 |
{ |
| 3268 |
{ D0 } { 011E } |
| 3269 |
{ DD } { 0130 } |
| 3270 |
{ DE } { 015E } |
| 3271 |
{ F0 } { 011F } |
| 3272 |
{ FD } { 0131 } |
| 3273 |
{ FE } { 015F } |
| 3274 |
} |
| 3275 |
{ |
| 3276 |
} |
| 3277 |
%</iso88599> |
| 3278 |
% \end{macrocode} |
| 3279 |
% |
| 3280 |
% \begin{macrocode} |
| 3281 |
%<*iso885910> |
| 3282 |
\@@_declare_eight_bit_encoding:nnnn { iso885910 } { 383 } |
| 3283 |
{ |
| 3284 |
{ A1 } { 0104 } |
| 3285 |
{ A2 } { 0112 } |
| 3286 |
{ A3 } { 0122 } |
| 3287 |
{ A4 } { 012A } |
| 3288 |
{ A5 } { 0128 } |
| 3289 |
{ A6 } { 0136 } |
| 3290 |
{ A8 } { 013B } |
| 3291 |
{ A9 } { 0110 } |
| 3292 |
{ AA } { 0160 } |
| 3293 |
{ AB } { 0166 } |
| 3294 |
{ AC } { 017D } |
| 3295 |
{ AE } { 016A } |
| 3296 |
{ AF } { 014A } |
| 3297 |
{ B1 } { 0105 } |
| 3298 |
{ B2 } { 0113 } |
| 3299 |
{ B3 } { 0123 } |
| 3300 |
{ B4 } { 012B } |
| 3301 |
{ B5 } { 0129 } |
| 3302 |
{ B6 } { 0137 } |
| 3303 |
{ B8 } { 013C } |
| 3304 |
{ B9 } { 0111 } |
| 3305 |
{ BA } { 0161 } |
| 3306 |
{ BB } { 0167 } |
| 3307 |
{ BC } { 017E } |
| 3308 |
{ BD } { 2015 } |
| 3309 |
{ BE } { 016B } |
| 3310 |
{ BF } { 014B } |
| 3311 |
{ C0 } { 0100 } |
| 3312 |
{ C7 } { 012E } |
| 3313 |
{ C8 } { 010C } |
| 3314 |
{ CA } { 0118 } |
| 3315 |
{ CC } { 0116 } |
| 3316 |
{ D1 } { 0145 } |
| 3317 |
{ D2 } { 014C } |
| 3318 |
{ D7 } { 0168 } |
| 3319 |
{ D9 } { 0172 } |
| 3320 |
{ E0 } { 0101 } |
| 3321 |
{ E7 } { 012F } |
| 3322 |
{ E8 } { 010D } |
| 3323 |
{ EA } { 0119 } |
| 3324 |
{ EC } { 0117 } |
| 3325 |
{ F1 } { 0146 } |
| 3326 |
{ F2 } { 014D } |
| 3327 |
{ F7 } { 0169 } |
| 3328 |
{ F9 } { 0173 } |
| 3329 |
{ FF } { 0138 } |
| 3330 |
} |
| 3331 |
{ |
| 3332 |
} |
| 3333 |
%</iso885910> |
| 3334 |
% \end{macrocode} |
| 3335 |
% |
| 3336 |
% \begin{macrocode} |
| 3337 |
%<*iso885911> |
| 3338 |
\@@_declare_eight_bit_encoding:nnnn { iso885911 } { 369 } |
| 3339 |
{ |
| 3340 |
{ A1 } { 0E01 } |
| 3341 |
{ A2 } { 0E02 } |
| 3342 |
{ A3 } { 0E03 } |
| 3343 |
{ A4 } { 0E04 } |
| 3344 |
{ A5 } { 0E05 } |
| 3345 |
{ A6 } { 0E06 } |
| 3346 |
{ A7 } { 0E07 } |
| 3347 |
{ A8 } { 0E08 } |
| 3348 |
{ A9 } { 0E09 } |
| 3349 |
{ AA } { 0E0A } |
| 3350 |
{ AB } { 0E0B } |
| 3351 |
{ AC } { 0E0C } |
| 3352 |
{ AD } { 0E0D } |
| 3353 |
{ AE } { 0E0E } |
| 3354 |
{ AF } { 0E0F } |
| 3355 |
{ B0 } { 0E10 } |
| 3356 |
{ B1 } { 0E11 } |
| 3357 |
{ B2 } { 0E12 } |
| 3358 |
{ B3 } { 0E13 } |
| 3359 |
{ B4 } { 0E14 } |
| 3360 |
{ B5 } { 0E15 } |
| 3361 |
{ B6 } { 0E16 } |
| 3362 |
{ B7 } { 0E17 } |
| 3363 |
{ B8 } { 0E18 } |
| 3364 |
{ B9 } { 0E19 } |
| 3365 |
{ BA } { 0E1A } |
| 3366 |
{ BB } { 0E1B } |
| 3367 |
{ BC } { 0E1C } |
| 3368 |
{ BD } { 0E1D } |
| 3369 |
{ BE } { 0E1E } |
| 3370 |
{ BF } { 0E1F } |
| 3371 |
{ C0 } { 0E20 } |
| 3372 |
{ C1 } { 0E21 } |
| 3373 |
{ C2 } { 0E22 } |
| 3374 |
{ C3 } { 0E23 } |
| 3375 |
{ C4 } { 0E24 } |
| 3376 |
{ C5 } { 0E25 } |
| 3377 |
{ C6 } { 0E26 } |
| 3378 |
{ C7 } { 0E27 } |
| 3379 |
{ C8 } { 0E28 } |
| 3380 |
{ C9 } { 0E29 } |
| 3381 |
{ CA } { 0E2A } |
| 3382 |
{ CB } { 0E2B } |
| 3383 |
{ CC } { 0E2C } |
| 3384 |
{ CD } { 0E2D } |
| 3385 |
{ CE } { 0E2E } |
| 3386 |
{ CF } { 0E2F } |
| 3387 |
{ D0 } { 0E30 } |
| 3388 |
{ D1 } { 0E31 } |
| 3389 |
{ D2 } { 0E32 } |
| 3390 |
{ D3 } { 0E33 } |
| 3391 |
{ D4 } { 0E34 } |
| 3392 |
{ D5 } { 0E35 } |
| 3393 |
{ D6 } { 0E36 } |
| 3394 |
{ D7 } { 0E37 } |
| 3395 |
{ D8 } { 0E38 } |
| 3396 |
{ D9 } { 0E39 } |
| 3397 |
{ DA } { 0E3A } |
| 3398 |
{ DF } { 0E3F } |
| 3399 |
{ E0 } { 0E40 } |
| 3400 |
{ E1 } { 0E41 } |
| 3401 |
{ E2 } { 0E42 } |
| 3402 |
{ E3 } { 0E43 } |
| 3403 |
{ E4 } { 0E44 } |
| 3404 |
{ E5 } { 0E45 } |
| 3405 |
{ E6 } { 0E46 } |
| 3406 |
{ E7 } { 0E47 } |
| 3407 |
{ E8 } { 0E48 } |
| 3408 |
{ E9 } { 0E49 } |
| 3409 |
{ EA } { 0E4A } |
| 3410 |
{ EB } { 0E4B } |
| 3411 |
{ EC } { 0E4C } |
| 3412 |
{ ED } { 0E4D } |
| 3413 |
{ EE } { 0E4E } |
| 3414 |
{ EF } { 0E4F } |
| 3415 |
{ F0 } { 0E50 } |
| 3416 |
{ F1 } { 0E51 } |
| 3417 |
{ F2 } { 0E52 } |
| 3418 |
{ F3 } { 0E53 } |
| 3419 |
{ F4 } { 0E54 } |
| 3420 |
{ F5 } { 0E55 } |
| 3421 |
{ F6 } { 0E56 } |
| 3422 |
{ F7 } { 0E57 } |
| 3423 |
{ F8 } { 0E58 } |
| 3424 |
{ F9 } { 0E59 } |
| 3425 |
{ FA } { 0E5A } |
| 3426 |
{ FB } { 0E5B } |
| 3427 |
} |
| 3428 |
{ |
| 3429 |
{ DB } |
| 3430 |
{ DC } |
| 3431 |
{ DD } |
| 3432 |
{ DE } |
| 3433 |
} |
| 3434 |
%</iso885911> |
| 3435 |
% \end{macrocode} |
| 3436 |
% |
| 3437 |
% \begin{macrocode} |
| 3438 |
%<*iso885913> |
| 3439 |
\@@_declare_eight_bit_encoding:nnnn { iso885913 } { 399 } |
| 3440 |
{ |
| 3441 |
{ A1 } { 201D } |
| 3442 |
{ A5 } { 201E } |
| 3443 |
{ A8 } { 00D8 } |
| 3444 |
{ AA } { 0156 } |
| 3445 |
{ AF } { 00C6 } |
| 3446 |
{ B4 } { 201C } |
| 3447 |
{ B8 } { 00F8 } |
| 3448 |
{ BA } { 0157 } |
| 3449 |
{ BF } { 00E6 } |
| 3450 |
{ C0 } { 0104 } |
| 3451 |
{ C1 } { 012E } |
| 3452 |
{ C2 } { 0100 } |
| 3453 |
{ C3 } { 0106 } |
| 3454 |
{ C6 } { 0118 } |
| 3455 |
{ C7 } { 0112 } |
| 3456 |
{ C8 } { 010C } |
| 3457 |
{ CA } { 0179 } |
| 3458 |
{ CB } { 0116 } |
| 3459 |
{ CC } { 0122 } |
| 3460 |
{ CD } { 0136 } |
| 3461 |
{ CE } { 012A } |
| 3462 |
{ CF } { 013B } |
| 3463 |
{ D0 } { 0160 } |
| 3464 |
{ D1 } { 0143 } |
| 3465 |
{ D2 } { 0145 } |
| 3466 |
{ D4 } { 014C } |
| 3467 |
{ D8 } { 0172 } |
| 3468 |
{ D9 } { 0141 } |
| 3469 |
{ DA } { 015A } |
| 3470 |
{ DB } { 016A } |
| 3471 |
{ DD } { 017B } |
| 3472 |
{ DE } { 017D } |
| 3473 |
{ E0 } { 0105 } |
| 3474 |
{ E1 } { 012F } |
| 3475 |
{ E2 } { 0101 } |
| 3476 |
{ E3 } { 0107 } |
| 3477 |
{ E6 } { 0119 } |
| 3478 |
{ E7 } { 0113 } |
| 3479 |
{ E8 } { 010D } |
| 3480 |
{ EA } { 017A } |
| 3481 |
{ EB } { 0117 } |
| 3482 |
{ EC } { 0123 } |
| 3483 |
{ ED } { 0137 } |
| 3484 |
{ EE } { 012B } |
| 3485 |
{ EF } { 013C } |
| 3486 |
{ F0 } { 0161 } |
| 3487 |
{ F1 } { 0144 } |
| 3488 |
{ F2 } { 0146 } |
| 3489 |
{ F4 } { 014D } |
| 3490 |
{ F8 } { 0173 } |
| 3491 |
{ F9 } { 0142 } |
| 3492 |
{ FA } { 015B } |
| 3493 |
{ FB } { 016B } |
| 3494 |
{ FD } { 017C } |
| 3495 |
{ FE } { 017E } |
| 3496 |
{ FF } { 2019 } |
| 3497 |
} |
| 3498 |
{ |
| 3499 |
} |
| 3500 |
%</iso885913> |
| 3501 |
% \end{macrocode} |
| 3502 |
% |
| 3503 |
% \begin{macrocode} |
| 3504 |
%<*iso885914> |
| 3505 |
\@@_declare_eight_bit_encoding:nnnn { iso885914 } { 529 } |
| 3506 |
{ |
| 3507 |
{ A1 } { 1E02 } |
| 3508 |
{ A2 } { 1E03 } |
| 3509 |
{ A4 } { 010A } |
| 3510 |
{ A5 } { 010B } |
| 3511 |
{ A6 } { 1E0A } |
| 3512 |
{ A8 } { 1E80 } |
| 3513 |
{ AA } { 1E82 } |
| 3514 |
{ AB } { 1E0B } |
| 3515 |
{ AC } { 1EF2 } |
| 3516 |
{ AF } { 0178 } |
| 3517 |
{ B0 } { 1E1E } |
| 3518 |
{ B1 } { 1E1F } |
| 3519 |
{ B2 } { 0120 } |
| 3520 |
{ B3 } { 0121 } |
| 3521 |
{ B4 } { 1E40 } |
| 3522 |
{ B5 } { 1E41 } |
| 3523 |
{ B7 } { 1E56 } |
| 3524 |
{ B8 } { 1E81 } |
| 3525 |
{ B9 } { 1E57 } |
| 3526 |
{ BA } { 1E83 } |
| 3527 |
{ BB } { 1E60 } |
| 3528 |
{ BC } { 1EF3 } |
| 3529 |
{ BD } { 1E84 } |
| 3530 |
{ BE } { 1E85 } |
| 3531 |
{ BF } { 1E61 } |
| 3532 |
{ D0 } { 0174 } |
| 3533 |
{ D7 } { 1E6A } |
| 3534 |
{ DE } { 0176 } |
| 3535 |
{ F0 } { 0175 } |
| 3536 |
{ F7 } { 1E6B } |
| 3537 |
{ FE } { 0177 } |
| 3538 |
} |
| 3539 |
{ |
| 3540 |
} |
| 3541 |
%</iso885914> |
| 3542 |
% \end{macrocode} |
| 3543 |
% |
| 3544 |
% \begin{macrocode} |
| 3545 |
%<*iso885915> |
| 3546 |
\@@_declare_eight_bit_encoding:nnnn { iso885915 } { 383 } |
| 3547 |
{ |
| 3548 |
{ A4 } { 20AC } |
| 3549 |
{ A6 } { 0160 } |
| 3550 |
{ A8 } { 0161 } |
| 3551 |
{ B4 } { 017D } |
| 3552 |
{ B8 } { 017E } |
| 3553 |
{ BC } { 0152 } |
| 3554 |
{ BD } { 0153 } |
| 3555 |
{ BE } { 0178 } |
| 3556 |
} |
| 3557 |
{ |
| 3558 |
} |
| 3559 |
%</iso885915> |
| 3560 |
% \end{macrocode} |
| 3561 |
% |
| 3562 |
% \begin{macrocode} |
| 3563 |
%<*iso885916> |
| 3564 |
\@@_declare_eight_bit_encoding:nnnn { iso885916 } { 558 } |
| 3565 |
{ |
| 3566 |
{ A1 } { 0104 } |
| 3567 |
{ A2 } { 0105 } |
| 3568 |
{ A3 } { 0141 } |
| 3569 |
{ A4 } { 20AC } |
| 3570 |
{ A5 } { 201E } |
| 3571 |
{ A6 } { 0160 } |
| 3572 |
{ A8 } { 0161 } |
| 3573 |
{ AA } { 0218 } |
| 3574 |
{ AC } { 0179 } |
| 3575 |
{ AE } { 017A } |
| 3576 |
{ AF } { 017B } |
| 3577 |
{ B2 } { 010C } |
| 3578 |
{ B3 } { 0142 } |
| 3579 |
{ B4 } { 017D } |
| 3580 |
{ B5 } { 201D } |
| 3581 |
{ B8 } { 017E } |
| 3582 |
{ B9 } { 010D } |
| 3583 |
{ BA } { 0219 } |
| 3584 |
{ BC } { 0152 } |
| 3585 |
{ BD } { 0153 } |
| 3586 |
{ BE } { 0178 } |
| 3587 |
{ BF } { 017C } |
| 3588 |
{ C3 } { 0102 } |
| 3589 |
{ C5 } { 0106 } |
| 3590 |
{ D0 } { 0110 } |
| 3591 |
{ D1 } { 0143 } |
| 3592 |
{ D5 } { 0150 } |
| 3593 |
{ D7 } { 015A } |
| 3594 |
{ D8 } { 0170 } |
| 3595 |
{ DD } { 0118 } |
| 3596 |
{ DE } { 021A } |
| 3597 |
{ E3 } { 0103 } |
| 3598 |
{ E5 } { 0107 } |
| 3599 |
{ F0 } { 0111 } |
| 3600 |
{ F1 } { 0144 } |
| 3601 |
{ F5 } { 0151 } |
| 3602 |
{ F7 } { 015B } |
| 3603 |
{ F8 } { 0171 } |
| 3604 |
{ FD } { 0119 } |
| 3605 |
{ FE } { 021B } |
| 3606 |
} |
| 3607 |
{ |
| 3608 |
} |
| 3609 |
%</iso885916> |
| 3610 |
% \end{macrocode} |
| 3611 |
% |
| 3612 |
% \end{implementation} |
| 3613 |
% |
| 3614 |
% \PrintIndex |