Skip to content

Commit d823a51

Browse files
authoredNov 13, 2024
Merge pull request #116 from kornelski/named_args
Named args for macros
2 parents 5d9e4e4 + 93d0577 commit d823a51

8 files changed

+134
-134
lines changed
 

‎src/big5.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Big5Decoder {
7474
}
7575

7676
ascii_compatible_two_byte_decoder_functions!(
77-
{
77+
lead = {
7878
// If lead is between 0x81 and 0xFE, inclusive,
7979
// subtract offset 0x81.
8080
let non_ascii_minus_offset =
@@ -86,7 +86,7 @@ impl Big5Decoder {
8686
}
8787
non_ascii_minus_offset
8888
},
89-
{
89+
trail = {
9090
// If trail is between 0x40 and 0x7E, inclusive,
9191
// subtract offset 0x40. Else if trail is
9292
// between 0xA1 and 0xFE, inclusive, subtract
@@ -151,17 +151,17 @@ impl Big5Decoder {
151151
handle.write_bmp_excl_ascii(low_bits)
152152
}
153153
},
154-
self,
155-
non_ascii,
156-
byte,
157-
lead_minus_offset,
158-
unread_handle_trail,
159-
source,
160-
handle,
161-
'outermost,
162-
copy_ascii_from_check_space_astral,
163-
check_space_astral,
164-
false);
154+
self = self,
155+
non_ascii = non_ascii,
156+
byte = byte,
157+
lead_minus_offset = lead_minus_offset,
158+
unread_handle_trail = unread_handle_trail,
159+
source = source,
160+
handle = handle,
161+
outermost = 'outermost,
162+
copy_ascii = copy_ascii_from_check_space_astral,
163+
destination_check = check_space_astral,
164+
ascii_punctuation = false);
165165
}
166166

167167
pub struct Big5Encoder;

‎src/euc_kr.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl EucKrDecoder {
5050
}
5151

5252
ascii_compatible_two_byte_decoder_functions!(
53-
{
53+
lead = {
5454
// If lead is between 0x81 and 0xFE, inclusive,
5555
// subtract offset 0x81.
5656
let non_ascii_minus_offset =
@@ -62,7 +62,7 @@ impl EucKrDecoder {
6262
}
6363
non_ascii_minus_offset
6464
},
65-
{
65+
trail = {
6666
if lead_minus_offset >= 0x20 {
6767
// Not the extension range above KS X 1001
6868
let trail_minus_offset =
@@ -172,17 +172,17 @@ impl EucKrDecoder {
172172
handle.write_upper_bmp(upper_bmp)
173173
}
174174
},
175-
self,
176-
non_ascii,
177-
byte,
178-
lead_minus_offset,
179-
unread_handle_trail,
180-
source,
181-
handle,
182-
'outermost,
183-
copy_ascii_from_check_space_bmp,
184-
check_space_bmp,
185-
true);
175+
self = self,
176+
non_ascii = non_ascii,
177+
byte = byte,
178+
lead_minus_offset = lead_minus_offset,
179+
unread_handle_trail = unread_handle_trail,
180+
source = source,
181+
handle = handle,
182+
outermost = 'outermost,
183+
copy_ascii = copy_ascii_from_check_space_bmp,
184+
destination_check = check_space_bmp,
185+
ascii_punctuation = true);
186186
}
187187

188188
fn ksx1001_encode_misc(bmp: u16) -> Option<(usize, usize)> {

‎src/iso_2022_jp.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Iso2022JpDecoder {
9696
}
9797

9898
decoder_functions!(
99-
{
99+
preamble = {
100100
if self.pending_prepended {
101101
// lead was set in EscapeStart and "prepended"
102102
// in Escape.
@@ -127,8 +127,8 @@ impl Iso2022JpDecoder {
127127
}
128128
}
129129
},
130-
{},
131-
{
130+
loop_preamble = {},
131+
eof = {
132132
match self.decoder_state {
133133
Iso2022JpDecoderState::TrailByte | Iso2022JpDecoderState::EscapeStart => {
134134
self.decoder_state = self.output_state;
@@ -142,7 +142,7 @@ impl Iso2022JpDecoder {
142142
_ => {}
143143
}
144144
},
145-
{
145+
body = {
146146
match self.decoder_state {
147147
Iso2022JpDecoderState::Ascii => {
148148
if b == 0x1Bu8 {
@@ -353,14 +353,14 @@ impl Iso2022JpDecoder {
353353
}
354354
}
355355
},
356-
self,
357-
src_consumed,
358-
dest,
359-
source,
360-
b,
361-
destination_handle,
362-
unread_handle,
363-
check_space_bmp
356+
self = self,
357+
src_consumed = src_consumed,
358+
dest = dest,
359+
source = source,
360+
byte = b,
361+
destination_handle = destination_handle,
362+
unread_handle = unread_handle,
363+
destination_check = check_space_bmp
364364
);
365365
}
366366

@@ -517,7 +517,7 @@ impl Iso2022JpEncoder {
517517
}
518518

519519
encoder_functions!(
520-
{
520+
eof = {
521521
match self.state {
522522
Iso2022JpEncoderState::Ascii => {}
523523
_ => match dest.check_space_three() {
@@ -531,7 +531,7 @@ impl Iso2022JpEncoder {
531531
},
532532
}
533533
},
534-
{
534+
body = {
535535
match self.state {
536536
Iso2022JpEncoderState::Ascii => {
537537
if c == '\u{0E}' || c == '\u{0F}' || c == '\u{1B}' {
@@ -734,14 +734,14 @@ impl Iso2022JpEncoder {
734734
}
735735
}
736736
},
737-
self,
738-
src_consumed,
739-
source,
740-
dest,
741-
c,
742-
destination_handle,
743-
unread_handle,
744-
check_space_three
737+
self = self,
738+
src_consumed = src_consumed,
739+
source = source,
740+
dest = dest,
741+
c = c,
742+
destination_handle = destination_handle,
743+
unread_handle = unread_handle,
744+
destination_check = check_space_three
745745
);
746746
}
747747

‎src/macros.rs

+39-39
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
macro_rules! decoder_function {
1111
($preamble:block,
12-
$loop_preable:block,
12+
$loop_preamble:block,
1313
$eof:block,
1414
$body:block,
1515
$slf:ident,
@@ -38,7 +38,7 @@ macro_rules! decoder_function {
3838
}
3939
loop {
4040
{
41-
$loop_preable
41+
$loop_preamble
4242
}
4343
match $source.check_available() {
4444
Space::Full($src_consumed) => {
@@ -72,22 +72,22 @@ macro_rules! decoder_function {
7272

7373
macro_rules! decoder_functions {
7474
(
75-
$preamble:block,
76-
$loop_preable:block,
77-
$eof:block,
78-
$body:block,
79-
$slf:ident,
80-
$src_consumed:ident,
81-
$dest:ident,
82-
$source:ident,
83-
$b:ident,
84-
$destination_handle:ident,
85-
$unread_handle:ident,
86-
$destination_check:ident
75+
preamble = $preamble:block,
76+
loop_preamble = $loop_preamble:block,
77+
eof = $eof:block,
78+
body = $body:block,
79+
self = $slf:ident,
80+
src_consumed = $src_consumed:ident,
81+
dest = $dest:ident,
82+
source = $source:ident,
83+
byte = $b:ident,
84+
destination_handle = $destination_handle:ident,
85+
unread_handle = $unread_handle:ident,
86+
destination_check = $destination_check:ident
8787
) => {
8888
decoder_function!(
8989
$preamble,
90-
$loop_preable,
90+
$loop_preamble,
9191
$eof,
9292
$body,
9393
$slf,
@@ -104,7 +104,7 @@ macro_rules! decoder_functions {
104104
);
105105
decoder_function!(
106106
$preamble,
107-
$loop_preable,
107+
$loop_preamble,
108108
$eof,
109109
$body,
110110
$slf,
@@ -286,19 +286,19 @@ macro_rules! ascii_compatible_two_byte_decoder_function {
286286

287287
macro_rules! ascii_compatible_two_byte_decoder_functions {
288288
(
289-
$lead:block,
290-
$trail:block,
291-
$slf:ident,
292-
$non_ascii:ident,
293-
$byte:ident,
294-
$lead_minus_offset:ident,
295-
$unread_handle_trail:ident,
296-
$source:ident,
297-
$handle:ident,
298-
$outermost:tt,
299-
$copy_ascii:ident,
300-
$destination_check:ident,
301-
$ascii_punctuation:expr
289+
lead = $lead:block,
290+
trail = $trail:block,
291+
self = $slf:ident,
292+
non_ascii = $non_ascii:ident,
293+
byte = $byte:ident,
294+
lead_minus_offset = $lead_minus_offset:ident,
295+
unread_handle_trail = $unread_handle_trail:ident,
296+
source = $source:ident,
297+
handle = $handle:ident,
298+
outermost = $outermost:tt,
299+
copy_ascii = $copy_ascii:ident,
300+
destination_check = $destination_check:ident,
301+
ascii_punctuation = $ascii_punctuation:expr
302302
) => {
303303
ascii_compatible_two_byte_decoder_function!(
304304
$lead,
@@ -1013,16 +1013,16 @@ macro_rules! encoder_function {
10131013

10141014
macro_rules! encoder_functions {
10151015
(
1016-
$eof:block,
1017-
$body:block,
1018-
$slf:ident,
1019-
$src_consumed:ident,
1020-
$source:ident,
1021-
$dest:ident,
1022-
$c:ident,
1023-
$destination_handle:ident,
1024-
$unread_handle:ident,
1025-
$destination_check:ident
1016+
eof = $eof:block,
1017+
body = $body:block,
1018+
self = $slf:ident,
1019+
src_consumed = $src_consumed:ident,
1020+
source = $source:ident,
1021+
dest = $dest:ident,
1022+
c = $c:ident,
1023+
destination_handle = $destination_handle:ident,
1024+
unread_handle = $unread_handle:ident,
1025+
destination_check = $destination_check:ident
10261026
) => {
10271027
encoder_function!(
10281028
$eof,

‎src/shift_jis.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl ShiftJisDecoder {
4949
}
5050

5151
ascii_compatible_two_byte_decoder_functions!(
52-
{
52+
lead = {
5353
// If lead is between 0x81 and 0x9F, inclusive,
5454
// subtract offset 0x81. Else if lead is
5555
// between 0xE0 and 0xFC, inclusive, subtract
@@ -80,7 +80,7 @@ impl ShiftJisDecoder {
8080
}
8181
non_ascii_minus_offset
8282
},
83-
{
83+
trail = {
8484
// If trail is between 0x40 and 0x7E, inclusive,
8585
// subtract offset 0x40. Else if trail is
8686
// between 0x80 and 0xFC, inclusive, subtract
@@ -158,17 +158,17 @@ impl ShiftJisDecoder {
158158
}
159159
}
160160
},
161-
self,
162-
non_ascii,
163-
byte,
164-
lead_minus_offset,
165-
unread_handle_trail,
166-
source,
167-
handle,
168-
'outermost,
169-
copy_ascii_from_check_space_bmp,
170-
check_space_bmp,
171-
false);
161+
self = self,
162+
non_ascii = non_ascii,
163+
byte = byte,
164+
lead_minus_offset = lead_minus_offset,
165+
unread_handle_trail = unread_handle_trail,
166+
source = source,
167+
handle = handle,
168+
outermost = 'outermost,
169+
copy_ascii = copy_ascii_from_check_space_bmp,
170+
destination_check = check_space_bmp,
171+
ascii_punctuation = false);
172172
}
173173

174174
#[cfg(feature = "fast-kanji-encode")]

0 commit comments

Comments
 (0)
Failed to load comments.