ADDED: models and controllers for page "signal reducing"\n TODO: done table for page "signal reducing"
This commit is contained in:
@@ -4,29 +4,7 @@ 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) -> () {
|
||||
let (iter_start, iter_end) = input.buffer().bounds();
|
||||
let parsed_input: String = input
|
||||
.buffer()
|
||||
.text(&iter_start, &iter_end, false)
|
||||
.to_string()
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let operation = if mode == false {
|
||||
HammingMode::Encrypt
|
||||
} else {
|
||||
HammingMode::Decrypt
|
||||
};
|
||||
|
||||
match hamming(parsed_input, operation) {
|
||||
Ok(res) => output.buffer().set_text(res.trim_end()),
|
||||
Err(rej) => output.buffer().set_text(rej.as_str()),
|
||||
}
|
||||
}
|
||||
const ASCII_ZERO_CHAR_POSITION: u8 = 48;
|
||||
|
||||
pub fn processing_input(input: &String) -> String {
|
||||
input
|
||||
@@ -35,15 +13,11 @@ pub fn processing_input(input: &String) -> String {
|
||||
.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
|
||||
.as_str()
|
||||
.chars()
|
||||
.all(|c| c == '1' || c == '0' || c == ' ');
|
||||
|
||||
let second_condition = prepared_input.len() % l == 0;
|
||||
|
||||
(first_condition, second_condition)
|
||||
pub fn from_vec_bits_to_string(raw_data: &[u8]) -> String {
|
||||
raw_data
|
||||
.iter()
|
||||
.map(|bit| -> char { (bit + ASCII_ZERO_CHAR_POSITION).into() })
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn from_string_to_vec_bits(raw_data: String) -> Vec<u8> {
|
||||
|
||||
Reference in New Issue
Block a user