Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named args for macros #116

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/big5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Big5Decoder {
}

ascii_compatible_two_byte_decoder_functions!(
{
lead = {
// If lead is between 0x81 and 0xFE, inclusive,
// subtract offset 0x81.
let non_ascii_minus_offset =
Expand All @@ -86,7 +86,7 @@ impl Big5Decoder {
}
non_ascii_minus_offset
},
{
trail = {
// If trail is between 0x40 and 0x7E, inclusive,
// subtract offset 0x40. Else if trail is
// between 0xA1 and 0xFE, inclusive, subtract
Expand Down Expand Up @@ -151,17 +151,17 @@ impl Big5Decoder {
handle.write_bmp_excl_ascii(low_bits)
}
},
self,
non_ascii,
byte,
lead_minus_offset,
unread_handle_trail,
source,
handle,
'outermost,
copy_ascii_from_check_space_astral,
check_space_astral,
false);
self = self,
non_ascii = non_ascii,
byte = byte,
lead_minus_offset = lead_minus_offset,
unread_handle_trail = unread_handle_trail,
source = source,
handle = handle,
outermost = 'outermost,
copy_ascii = copy_ascii_from_check_space_astral,
destination_check = check_space_astral,
ascii_punctuation = false);
}

pub struct Big5Encoder;
Expand Down
26 changes: 13 additions & 13 deletions src/euc_kr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl EucKrDecoder {
}

ascii_compatible_two_byte_decoder_functions!(
{
lead = {
// If lead is between 0x81 and 0xFE, inclusive,
// subtract offset 0x81.
let non_ascii_minus_offset =
Expand All @@ -62,7 +62,7 @@ impl EucKrDecoder {
}
non_ascii_minus_offset
},
{
trail = {
if lead_minus_offset >= 0x20 {
// Not the extension range above KS X 1001
let trail_minus_offset =
Expand Down Expand Up @@ -172,17 +172,17 @@ impl EucKrDecoder {
handle.write_upper_bmp(upper_bmp)
}
},
self,
non_ascii,
byte,
lead_minus_offset,
unread_handle_trail,
source,
handle,
'outermost,
copy_ascii_from_check_space_bmp,
check_space_bmp,
true);
self = self,
non_ascii = non_ascii,
byte = byte,
lead_minus_offset = lead_minus_offset,
unread_handle_trail = unread_handle_trail,
source = source,
handle = handle,
outermost = 'outermost,
copy_ascii = copy_ascii_from_check_space_bmp,
destination_check = check_space_bmp,
ascii_punctuation = true);
}

fn ksx1001_encode_misc(bmp: u16) -> Option<(usize, usize)> {
Expand Down
44 changes: 22 additions & 22 deletions src/iso_2022_jp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Iso2022JpDecoder {
}

decoder_functions!(
{
preamble = {
if self.pending_prepended {
// lead was set in EscapeStart and "prepended"
// in Escape.
Expand Down Expand Up @@ -127,8 +127,8 @@ impl Iso2022JpDecoder {
}
}
},
{},
{
loop_preamble = {},
eof = {
match self.decoder_state {
Iso2022JpDecoderState::TrailByte | Iso2022JpDecoderState::EscapeStart => {
self.decoder_state = self.output_state;
Expand All @@ -142,7 +142,7 @@ impl Iso2022JpDecoder {
_ => {}
}
},
{
body = {
match self.decoder_state {
Iso2022JpDecoderState::Ascii => {
if b == 0x1Bu8 {
Expand Down Expand Up @@ -353,14 +353,14 @@ impl Iso2022JpDecoder {
}
}
},
self,
src_consumed,
dest,
source,
b,
destination_handle,
unread_handle,
check_space_bmp
self = self,
src_consumed = src_consumed,
dest = dest,
source = source,
byte = b,
destination_handle = destination_handle,
unread_handle = unread_handle,
destination_check = check_space_bmp
);
}

Expand Down Expand Up @@ -517,7 +517,7 @@ impl Iso2022JpEncoder {
}

encoder_functions!(
{
eof = {
match self.state {
Iso2022JpEncoderState::Ascii => {}
_ => match dest.check_space_three() {
Expand All @@ -531,7 +531,7 @@ impl Iso2022JpEncoder {
},
}
},
{
body = {
match self.state {
Iso2022JpEncoderState::Ascii => {
if c == '\u{0E}' || c == '\u{0F}' || c == '\u{1B}' {
Expand Down Expand Up @@ -734,14 +734,14 @@ impl Iso2022JpEncoder {
}
}
},
self,
src_consumed,
source,
dest,
c,
destination_handle,
unread_handle,
check_space_three
self = self,
src_consumed = src_consumed,
source = source,
dest = dest,
c = c,
destination_handle = destination_handle,
unread_handle = unread_handle,
destination_check = check_space_three
);
}

Expand Down
78 changes: 39 additions & 39 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

macro_rules! decoder_function {
($preamble:block,
$loop_preable:block,
$loop_preamble:block,
$eof:block,
$body:block,
$slf:ident,
Expand Down Expand Up @@ -38,7 +38,7 @@ macro_rules! decoder_function {
}
loop {
{
$loop_preable
$loop_preamble
}
match $source.check_available() {
Space::Full($src_consumed) => {
Expand Down Expand Up @@ -72,22 +72,22 @@ macro_rules! decoder_function {

macro_rules! decoder_functions {
(
$preamble:block,
$loop_preable:block,
$eof:block,
$body:block,
$slf:ident,
$src_consumed:ident,
$dest:ident,
$source:ident,
$b:ident,
$destination_handle:ident,
$unread_handle:ident,
$destination_check:ident
preamble = $preamble:block,
loop_preamble = $loop_preamble:block,
eof = $eof:block,
body = $body:block,
self = $slf:ident,
src_consumed = $src_consumed:ident,
dest = $dest:ident,
source = $source:ident,
byte = $b:ident,
destination_handle = $destination_handle:ident,
unread_handle = $unread_handle:ident,
destination_check = $destination_check:ident
) => {
decoder_function!(
$preamble,
$loop_preable,
$loop_preamble,
$eof,
$body,
$slf,
Expand All @@ -104,7 +104,7 @@ macro_rules! decoder_functions {
);
decoder_function!(
$preamble,
$loop_preable,
$loop_preamble,
$eof,
$body,
$slf,
Expand Down Expand Up @@ -285,19 +285,19 @@ macro_rules! ascii_compatible_two_byte_decoder_function {

macro_rules! ascii_compatible_two_byte_decoder_functions {
(
$lead:block,
$trail:block,
$slf:ident,
$non_ascii:ident,
$byte:ident,
$lead_minus_offset:ident,
$unread_handle_trail:ident,
$source:ident,
$handle:ident,
$outermost:tt,
$copy_ascii:ident,
$destination_check:ident,
$ascii_punctuation:expr
lead = $lead:block,
trail = $trail:block,
self = $slf:ident,
non_ascii = $non_ascii:ident,
byte = $byte:ident,
lead_minus_offset = $lead_minus_offset:ident,
unread_handle_trail = $unread_handle_trail:ident,
source = $source:ident,
handle = $handle:ident,
outermost = $outermost:tt,
copy_ascii = $copy_ascii:ident,
destination_check = $destination_check:ident,
ascii_punctuation = $ascii_punctuation:expr
) => {
ascii_compatible_two_byte_decoder_function!(
$lead,
Expand Down Expand Up @@ -1010,16 +1010,16 @@ macro_rules! encoder_function {

macro_rules! encoder_functions {
(
$eof:block,
$body:block,
$slf:ident,
$src_consumed:ident,
$source:ident,
$dest:ident,
$c:ident,
$destination_handle:ident,
$unread_handle:ident,
$destination_check:ident
eof = $eof:block,
body = $body:block,
self = $slf:ident,
src_consumed = $src_consumed:ident,
source = $source:ident,
dest = $dest:ident,
c = $c:ident,
destination_handle = $destination_handle:ident,
unread_handle = $unread_handle:ident,
destination_check = $destination_check:ident
) => {
encoder_function!(
$eof,
Expand Down
26 changes: 13 additions & 13 deletions src/shift_jis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl ShiftJisDecoder {
}

ascii_compatible_two_byte_decoder_functions!(
{
lead = {
// If lead is between 0x81 and 0x9F, inclusive,
// subtract offset 0x81. Else if lead is
// between 0xE0 and 0xFC, inclusive, subtract
Expand Down Expand Up @@ -80,7 +80,7 @@ impl ShiftJisDecoder {
}
non_ascii_minus_offset
},
{
trail = {
// If trail is between 0x40 and 0x7E, inclusive,
// subtract offset 0x40. Else if trail is
// between 0x80 and 0xFC, inclusive, subtract
Expand Down Expand Up @@ -158,17 +158,17 @@ impl ShiftJisDecoder {
}
}
},
self,
non_ascii,
byte,
lead_minus_offset,
unread_handle_trail,
source,
handle,
'outermost,
copy_ascii_from_check_space_bmp,
check_space_bmp,
false);
self = self,
non_ascii = non_ascii,
byte = byte,
lead_minus_offset = lead_minus_offset,
unread_handle_trail = unread_handle_trail,
source = source,
handle = handle,
outermost = 'outermost,
copy_ascii = copy_ascii_from_check_space_bmp,
destination_check = check_space_bmp,
ascii_punctuation = false);
}

#[cfg(feature = "fast-kanji-encode")]
Expand Down
Loading