Skip to content

Commit 1ff1e3d

Browse files
committed
replace macros with constants
1 parent 253bbd7 commit 1ff1e3d

File tree

4 files changed

+28
-54
lines changed

4 files changed

+28
-54
lines changed

src/finding.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
33
extern crate encoding_rs;
44

5-
use crate::ascii_enc_label;
65
use crate::input::ByteCounter;
76
use crate::input::INPUT_BUF_LEN;
87
use crate::mission::Mission;
98
use crate::options::Radix;
109
use crate::options::ARGS;
10+
use crate::options::ASCII_ENC_LABEL;
1111
use std::io::Write;
1212
use std::ops::Deref;
1313
use std::str;
@@ -251,7 +251,7 @@ impl<'a> Finding<'a> {
251251
// map 0 -> 'a', 1 -> 'b', 2 -> 'c' ...
252252
out.write_all(&[b'(', self.mission.mission_id + 97 as u8, b' '])?;
253253
out.write_all(if self.mission.print_encoding_as_ascii {
254-
ascii_enc_label!().as_bytes()
254+
ASCII_ENC_LABEL.as_bytes()
255255
} else {
256256
self.mission.encoding.name().as_bytes()
257257
})?;

src/help.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Help the user with command-line-arguments.
22
3-
use crate::ascii_enc_label;
43
use crate::mission::ASCII_FILTER_ALIASSE;
54
use crate::mission::UNICODE_BLOCK_FILTER_ALIASSE;
65
use crate::mission::{Missions, MISSIONS};
76
use crate::options::ARGS;
7+
use crate::options::ASCII_ENC_LABEL;
88
use crate::AUTHOR;
99
use crate::VERSION;
1010
use std::process;
@@ -52,7 +52,7 @@ pub fn help() {
5252
println!("Format: --encoding=[ENC_NAME],[MIN],[AF,UBF],[GREP]\n\n");
5353
println!("ENC_NAME (Encoding)=");
5454
let list: [&'static str; 41] = [
55-
ascii_enc_label!(),
55+
ASCII_ENC_LABEL,
5656
"Big5",
5757
"EUC-JP",
5858
"EUC-KR",

src/mission.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
44
extern crate anyhow;
55
extern crate encoding_rs;
6-
use crate::ascii_enc_label;
7-
use crate::chars_min_default;
8-
use crate::counter_offset_default;
9-
use crate::encoding_default;
106
use crate::input::ByteCounter;
117
use crate::options::ARGS;
8+
use crate::options::ASCII_ENC_LABEL;
9+
use crate::options::CHARS_MIN_DEFAULT;
10+
use crate::options::COUNTER_OFFSET_DEFAULT;
11+
use crate::options::ENCODING_DEFAULT;
12+
use crate::options::OUTPUT_LINE_CHAR_NB_MAX_DEFAULT;
1213
use crate::options::OUTPUT_LINE_CHAR_NB_MIN;
13-
use crate::output_line_char_nb_max_default;
1414
use anyhow::{anyhow, Context, Result};
1515
use encoding_rs::*;
1616
use lazy_static::lazy_static;
@@ -572,7 +572,7 @@ impl Missions {
572572
}
573573

574574
let mut v = Vec::new();
575-
let encoding_default: &[String; 1] = &[String::from_str(&*encoding_default!()).unwrap()];
575+
let encoding_default: &[String; 1] = &[ENCODING_DEFAULT.to_string()];
576576

577577
let enc_iter = if flag_encoding.is_empty() {
578578
encoding_default.iter()
@@ -588,12 +588,12 @@ impl Missions {
588588

589589
let mut enc_name = match enc_name {
590590
Some(s) => s,
591-
None => encoding_default!(),
591+
None => ENCODING_DEFAULT,
592592
};
593593

594594
let counter_offset = match flag_counter_offset {
595595
Some(n) => n,
596-
None => counter_offset_default!(),
596+
None => COUNTER_OFFSET_DEFAULT,
597597
};
598598

599599
// If `char_min_nb` is not defined in `enc_opt`
@@ -602,15 +602,15 @@ impl Missions {
602602
Some(n) => n,
603603
None => match flag_chars_min_nb {
604604
Some(n) => n,
605-
None => chars_min_default!(),
605+
None => CHARS_MIN_DEFAULT,
606606
},
607607
};
608608

609609
let require_same_unicode_block = flag_same_unicode_block;
610610

611611
let output_line_char_nb_max = match flag_output_line_len {
612612
Some(n) => n,
613-
None => output_line_char_nb_max_default!(),
613+
None => OUTPUT_LINE_CHAR_NB_MAX_DEFAULT,
614614
};
615615

616616
if output_line_char_nb_max < OUTPUT_LINE_CHAR_NB_MIN {
@@ -628,16 +628,15 @@ impl Missions {
628628
// "x-user-defined" and the `UTF8_FILTER_ASCII_MODE_DEFAULT`-filter,
629629
// if not otherwise specified.
630630

631-
let filter_af = filter_af.unwrap_or(flag_ascii_filter.unwrap_or(
632-
if enc_name == ascii_enc_label!() {
631+
let filter_af =
632+
filter_af.unwrap_or(flag_ascii_filter.unwrap_or(if enc_name == ASCII_ENC_LABEL {
633633
UTF8_FILTER_ASCII_MODE_DEFAULT.af
634634
} else {
635635
UTF8_FILTER_NON_ASCII_MODE_DEFAULT.af
636-
},
637-
));
636+
}));
638637

639638
let filter_ubf = filter_ubf.unwrap_or(flag_unicode_block_filter.unwrap_or(
640-
if enc_name == ascii_enc_label!() {
639+
if enc_name == ASCII_ENC_LABEL {
641640
UTF8_FILTER_ASCII_MODE_DEFAULT.ubf
642641
} else {
643642
UTF8_FILTER_NON_ASCII_MODE_DEFAULT.ubf
@@ -649,7 +648,7 @@ impl Missions {
649648
None => match flag_grep_char {
650649
Some(f) => Some(f),
651650
None => {
652-
if enc_name == ascii_enc_label!() {
651+
if enc_name == ASCII_ENC_LABEL {
653652
UTF8_FILTER_ASCII_MODE_DEFAULT.grep_char
654653
} else {
655654
UTF8_FILTER_NON_ASCII_MODE_DEFAULT.grep_char
@@ -677,7 +676,7 @@ impl Missions {
677676
};
678677

679678
let mut print_encoding_as_ascii = false;
680-
if enc_name == ascii_enc_label!() {
679+
if enc_name == ASCII_ENC_LABEL {
681680
print_encoding_as_ascii = true;
682681
enc_name = "x-user-defined"
683682
};

src/options.rs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,32 @@
11
//! This module deals with command-line arguments and directly related data
22
//! structures.
33
4+
use crate::input::ByteCounter;
45
use clap::arg_enum;
56
use lazy_static::lazy_static;
67
use std::path::PathBuf;
78
use structopt::StructOpt;
89

910
/// Encoding name literal used when simulating non-built-in
1011
/// ASCII-decoder.
11-
#[macro_export]
12-
macro_rules! ascii_enc_label {
13-
() => {
14-
"ascii"
15-
};
16-
}
12+
pub const ASCII_ENC_LABEL: &str = "ascii";
1713

1814
/// If no command-line argument `--chars_min` is given
1915
/// and none is specified in `--encoding` use this.
2016
/// Must be one of `--list-encodings`.
21-
#[macro_export]
22-
macro_rules! encoding_default {
23-
() => {
24-
//ascii_enc_label!()
25-
"UTF-8"
26-
};
27-
}
17+
pub const ENCODING_DEFAULT: &str = "UTF-8";
2818

2919
/// Default value, when no `--chars-min` command-line-argument
3020
/// is given. Must be `u8`.
31-
#[macro_export]
32-
macro_rules! chars_min_default {
33-
() => {
34-
4u8
35-
};
36-
}
21+
pub const CHARS_MIN_DEFAULT: u8 = 4;
3722

3823
/// Default value, when no `--counter-offset` command-line-argument
39-
/// is given. Must be of type `ByteCounter`.
40-
#[macro_export]
41-
macro_rules! counter_offset_default {
42-
() => {
43-
0
44-
};
45-
}
24+
/// is given.
25+
pub const COUNTER_OFFSET_DEFAULT: ByteCounter = 0;
4626

4727
/// Default value when no `--output-line-len`
48-
/// command-line-argument is given. Must be `usize`.
49-
#[macro_export]
50-
macro_rules! output_line_char_nb_max_default {
51-
() => {
52-
64usize
53-
};
54-
}
28+
/// command-line-argument is given.
29+
pub const OUTPUT_LINE_CHAR_NB_MAX_DEFAULT: usize = 64;
5530

5631
/// There must be space for at least 3 long Unicode characters,
5732
/// to guarantee progress in streaming. You want much longer lines.

0 commit comments

Comments
 (0)