AIT/src/controller/view_utils/input_utils.rs

38 lines
896 B
Rust

use gtk4 as gtk;
use bitvec::{order::Lsb0, view::AsBits};
use gtk::{prelude::*, *};
use std::ops::Deref;
const ASCII_ZERO_CHAR_POSITION: u8 = 48;
pub fn processing_input(input: impl Into<String>) -> String {
input
.into()
.split_ascii_whitespace()
.filter(|&x| !x.is_empty())
.fold(String::new(), |c: String, n: &str| c + n)
}
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: impl Into<String>) -> Vec<u8> {
raw_data
.into()
.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("");
}