REFACTOR: clean code and some bug fixed
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use std::ops::Deref;
|
||||
use gtk::{*, prelude::*};
|
||||
use bitvec::{order::Lsb0, view::AsBits};
|
||||
use gtk::{prelude::*, *};
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::{
|
||||
model::model::*,
|
||||
model_utils::hamming_code_seven_four::*
|
||||
};
|
||||
|
||||
pub fn parse_input(input : &TextView, output : &TextView, mode: bool) -> (){
|
||||
use crate::{model::model::*, model_utils::hamming_code_seven_four::*};
|
||||
|
||||
pub fn parse_input(input: &TextView, output: &TextView, mode: bool) -> () {
|
||||
let (iter_start, iter_end) = input.buffer().bounds();
|
||||
let parsed_input : String = input
|
||||
let parsed_input: String = input
|
||||
.buffer()
|
||||
.text(&iter_start, &iter_end, false)
|
||||
.to_string()
|
||||
@@ -30,39 +26,33 @@ pub fn parse_input(input : &TextView, output : &TextView, mode: bool) -> (){
|
||||
Ok(res) => output.buffer().set_text(res.trim_end()),
|
||||
Err(rej) => output.buffer().set_text(rej.as_str()),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn processing_input(input : &String) -> String {
|
||||
|
||||
pub fn processing_input(input: &String) -> String {
|
||||
input
|
||||
.split_ascii_whitespace()
|
||||
.filter(|&x| {
|
||||
x != ""
|
||||
})
|
||||
.fold(String::new(), |c: String, n: &str| { c + n })
|
||||
|
||||
.filter(|&x| x != "")
|
||||
.fold(String::new(), |c: String, n: &str| c + n)
|
||||
}
|
||||
|
||||
pub fn check_correct_input(input: &String, prepared_input: &String, l: usize) -> (bool, bool){
|
||||
|
||||
let first_condition = input
|
||||
.chars()
|
||||
.all(|c| {c == '1' || c == '0' || c == ' '});
|
||||
pub fn check_correct_input(input: &String, prepared_input: &String, l: usize) -> (bool, bool) {
|
||||
let first_condition = input.chars().all(|c| c == '1' || c == '0' || c == ' ');
|
||||
|
||||
let second_condition = prepared_input.len() % l == 0;
|
||||
|
||||
(first_condition, second_condition)
|
||||
|
||||
}
|
||||
|
||||
pub fn from_string_to_vec_bits(raw_data: String) -> Vec<u8>{
|
||||
|
||||
pub fn from_string_to_vec_bits(raw_data: String) -> Vec<u8> {
|
||||
raw_data
|
||||
.as_bits::<Lsb0>()
|
||||
.iter()
|
||||
.step_by(8)
|
||||
.map(|x| *x.deref() as u8)
|
||||
.collect()
|
||||
}
|
||||
|
||||
}
|
||||
pub fn clearing(output: &TextView, input: &TextView) {
|
||||
input.buffer().set_text("");
|
||||
output.buffer().set_text("");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user