summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/l3kernel/l3file.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/l3kernel/l3file.dtx')
-rw-r--r--macros/latex/contrib/l3kernel/l3file.dtx43
1 files changed, 40 insertions, 3 deletions
diff --git a/macros/latex/contrib/l3kernel/l3file.dtx b/macros/latex/contrib/l3kernel/l3file.dtx
index 6f39937f85..19807253e3 100644
--- a/macros/latex/contrib/l3kernel/l3file.dtx
+++ b/macros/latex/contrib/l3kernel/l3file.dtx
@@ -44,7 +44,7 @@
% }^^A
% }
%
-% \date{Released 2019-10-14}
+% \date{Released 2019-10-21}
%
% \maketitle
%
@@ -69,6 +69,11 @@
% using |"| tokens if they contain spaces: as a result, |"| tokens are
% \emph{not} permitted in file names.
%
+% Spaces are trimmed at the beginning and end of the file name:
+% this reflects the fact that some file systems do not allow or interact
+% unpredictably with spaces in these positions. When no extension is given,
+% this will trim spaces from the start of the name only.
+%
% \section{Input--output stream management}
%
% As \TeX{} engines have a limited number of input and output streams, direct
@@ -2362,6 +2367,10 @@
% \begin{macro}[rEXP]{\__kernel_file_name_expand_N_type:Nw}
% \begin{macro}[rEXP]{\__kernel_file_name_expand_group:nw}
% \begin{macro}[rEXP]{\__kernel_file_name_expand_space:w}
+% \begin{macro}[rEXP]{\__kernel_file_name_trim_spaces:n}
+% \begin{macro}[rEXP]{\__kernel_file_name_trim_spaces:nw}
+% \begin{macro}[rEXP]{\__kernel_file_name_trim_spaces_aux:n}
+% \begin{macro}[rEXP]{\__kernel_file_name_trim_spaces_aux:w}
% Expanding the file name without expanding active characters is done
% using the same token-by-token approach as for example case changing.
% The finale outcome only need be \texttt{e}-type expandable, so there
@@ -2369,8 +2378,11 @@
% \begin{macrocode}
\cs_new:Npn \__kernel_file_name_sanitize:n #1
{
- \__kernel_file_name_expand_loop:w #1
- \q_recursion_tail \q_recursion_stop
+ \exp_args:Ne \__kernel_file_name_trim_spaces:n
+ {
+ \__kernel_file_name_expand_loop:w #1
+ \q_recursion_tail \q_recursion_stop
+ }
}
\cs_new:Npn \__kernel_file_name_expand_loop:w #1 \q_recursion_stop
{
@@ -2419,6 +2431,31 @@
\exp_not:N \__kernel_file_name_expand_loop:w
}
% \end{macrocode}
+% Spaces need to be trimmed from the start of the name and from the end of
+% any extension. However, the name we are passed might not have an extension:
+% that means we have to look for one. If there is no extension, we still use
+% the standard trimming function but deliberately prevent any spaces being
+% removed at the end.
+% \begin{macrocode}
+\cs_new:Npn \__kernel_file_name_trim_spaces:n #1
+ { \__kernel_file_name_trim_spaces:nw {#1} #1 . \q_nil . \q_stop }
+\cs_new:Npn \__kernel_file_name_trim_spaces:nw #1#2 . #3 . #4 \q_stop
+ {
+ \quark_if_nil:nTF {#3}
+ {
+ \exp_args:Ne \__kernel_file_name_trim_spaces_aux:n
+ { \tl_trim_spaces:n { #1 \s_stop } }
+ }
+ { \tl_trim_spaces:n {#1} }
+ }
+\cs_new:Npn \__kernel_file_name_trim_spaces_aux:n #1
+ { \__kernel_file_name_trim_spaces_aux:w #1 }
+\cs_new:Npn \__kernel_file_name_trim_spaces_aux:w #1 \s_stop {#1}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}