blob: aacb70ec742e090769182c435b9f93fb395ac23b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
%D \module
%D [ file=syst-str,
%D version=2006.09.18,
%D title=\CONTEXT\ System Macros,
%D subtitle=String Processing,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\unprotect
%D We need a convenient way to change lccode vectors.
\dostepwiserecurse{0}{255}{1}
{\@EA\chardef\csname-\recurselevel\endcsname\recurselevel}
\newtoks\withminorcharacters
\newtoks\withlowercharacters
\newtoks\withuppercharacters
\dostepwiserecurse{0}{31}{1}
{\expanded
{\appendtoks\noexpand\withcharacter\csname-\recurselevel\endcsname
\noexpand\to\withminorcharacters}}
\dostepwiserecurse{32}{127}{1}
{\expanded
{\appendtoks\noexpand\withcharacter\csname-\recurselevel\endcsname
\noexpand\to\withlowercharacters}}
\dostepwiserecurse{128}{255}{1}
{\expanded
{\appendtoks\noexpand\withcharacter\csname-\recurselevel\endcsname
\noexpand\to\withuppercharacters}}
\chardef\obeyedlccode=`. % so <32 and >127 chars become .
%D \macros
%D {retainlccodes}
%D
%D One way of manipulating characters is changing the their
%D \type{\lccode} and applying \type{\lowcase}. An example of
%D this can be found in \type{spec-mis}.
\def\setownlccode #1{\lccode#1#1}
\def\setobeyedlccode#1{\lccode#1\obeyedlccode}
\def\obeylccodes
{\let\withcharacter\setownlccode
\the\withlowercharacters
\let\withcharacter\setobeyedlccode
\the\withminorcharacters
\the\withuppercharacters
\relax}
\def\retainlccodes
{\let\withcharacter\setownlccode
\the\withlowercharacters
\the\withminorcharacters
\the\withuppercharacters
\relax}
%D I got tired of making dedicated clean up macros using the
%D same mechanism again and again, so now we have:
%D
%D \starttyping
%D \def\xxxx{abc.d} \replacecharacters\xxxx{a.}{-} \xxxx
%D \stoptyping
\def\replacecharacters#1#2#3% macro characters replacement
{\bgroup
\edef\ascii{#1}%
\retainlccodes
\def\docommand##1{\lccode\expandafter`\csname##1\endcsname=\expandafter`\csname#3\endcsname}%
\handletokens#2\with\docommand
\lowercase\@EA{\@EA\xdef\@EA\globalascii\@EA{\ascii}}%
\egroup
\dodoglobal\let#1\globalascii}
% \bgroup
% \catcode`\ =\@@other % needed in order to get it visible
% \lccode`\ =`\-
% \lowercase{\xdef\globalascii{aap noot}}%
% \egroup
%
% [\globalascii] {\tttf [\globalascii]}
%
% interesting:
%
% \setvalue{xxx}{oeps}
% \setvalue{test-test}{\getvalue{xxx}oeps}
% \bgroup\lccode`\ =`\-\lowercase{\egroup\csname test test\endcsname}
%
% \setvalue{test\string~test}{\getvalue{xxx}oeps}
% \bgroup\lccode`\ =`\~\lowercase{\egroup\csname test test\endcsname}
%
% \bgroup\catcode`\~=\@@letter\lowercase{\egroup\csname test~test\endcsname}
\def\separatestring#1\to#2%
{\bgroup
\retainlccodes
\lccode `\ =`\,%
% when typesetting: \catcode`\ =\@@other
\edef\ascii{#1}%
\lowercase\@EA{\@EA\xdef\@EA\globalascii\@EA{\ascii}}%
\egroup
\let#2\globalascii}
\def\unspacefilename#1\to#2%
{\bgroup
\def\obeyedspace{-}%
\sanitizefilename#1\to\ascii
\retainlccodes
\lccode `\ =`\-%
% when typesetting: \catcode`\ =\@@other
\lowercase\@EA{\@EA\xdef\@EA\globalascii\@EA{\ascii}}%
\egroup
\let#2\globalascii}
\protect \endinput
|