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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
extern crate trees;
extern crate reflection;
extern crate serde;
pub mod ser;
pub use self::ser::{Serializer,to_string};
pub mod de;
pub use self::de::{Deserializer,from_str};
pub mod error;
pub use error::{Error,Result};
pub(crate) use error::ErrorCode;
mod table;
#[cfg(test)]
#[macro_use]
extern crate reflection_derive;
#[cfg(test)]
#[macro_use]
extern crate serde_derive;
const RESERVED_CHAR: [char;3] = [ '\\', '\t', '\n' ];
pub struct Config {
with_header : bool,
unit_str : String,
true_str : String,
false_str : String,
}
impl Config {
pub fn make_config(
with_header : bool,
unit_str : String,
true_str : String,
false_str : String
) -> Result<Self>
{
if true_str == false_str || unit_str.is_empty() || true_str.is_empty() || false_str.is_empty() {
return Err( Error::new( ErrorCode::InvalidConfig, 0, 0 ));
} else {
for i in 0..3 {
if unit_str.find( RESERVED_CHAR[i] ).is_some()
|| true_str.find( RESERVED_CHAR[i] ).is_some()
|| false_str.find( RESERVED_CHAR[i] ).is_some()
{
return Err( Error::new( ErrorCode::InvalidConfig, 0, 0 ));
}
}
}
Ok( Config{ with_header, unit_str, true_str, false_str })
}
}
impl Default for Config {
fn default() -> Self {
Config {
with_header : true,
unit_str : "-".to_string(),
true_str : "O".to_string(),
false_str : "X".to_string(),
}
}
}
pub struct Env {
config : Config,
escapes : Vec<String>,
}
impl Env {
pub fn make_env(
with_header : bool,
unit_str : String,
true_str : String,
false_str : String
) -> Result<Self>
{
let config = Config::make_config( with_header, unit_str, true_str, false_str )?;
let escapes = vec![ String::new() ];
Ok( Env{ config, escapes })
}
}
impl Default for Env {
fn default() -> Self {
Env{ config: Config::default(), escapes: vec![ String::new() ]}
}
}
pub mod fs {
use std::fs::File;
use std::io::Read;
pub fn read_file( name: &'static str ) -> ::std::io::Result<String> {
let mut file = File::open( name )?;
let mut contents = String::new();
file.read_to_string( &mut contents )?;
contents.pop();
Ok( contents )
}
}