impl Context::new

This commit is contained in:
Dmitry Belyaev 2019-07-27 11:30:40 +03:00
parent ebae59dcb0
commit befca99019
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -70,6 +70,24 @@ struct Context {
last_tag: String,
}
impl Context {
fn new() -> Context {
Context {
data: json::JsonValue::new_object(),
questions: json::JsonValue::new_array(),
cur_keyword_type: None,
cur_question: json::JsonValue::new_object(),
cur_question_pre: json::JsonValue::new_object(),
cur_tag: String::new(),
cur_content: Vec::<String>::new(),
cur_scope: DataScope::Global,
have_new_question: false,
last_keyword_type: None,
last_tag: String::new(),
}
}
}
fn parse_file(file: impl io::Read) -> Result<json::JsonValue, Box<std::error::Error>> {
let buf = io::BufReader::new(file);
let reader = TextReader::new(buf, KOI8_R, DecoderTrap::Ignore);
@ -99,20 +117,8 @@ fn parse_file(file: impl io::Read) -> Result<json::JsonValue, Box<std::error::Er
"Комментарий:",
"Комментарии:",
];
// init context
let mut context = Context {
data: json::JsonValue::new_object(),
questions: json::JsonValue::new_array(),
cur_keyword_type: None,
cur_question: json::JsonValue::new_object(),
cur_question_pre: json::JsonValue::new_object(),
cur_tag: String::new(),
cur_content: Vec::<String>::new(),
cur_scope: DataScope::Global,
have_new_question: false,
last_keyword_type: None,
last_tag: String::new(),
};
let mut context = Context::new();
let mut ctx = &mut context;
reader