use crate::{
grid::config::Entity,
grid::records::{ExactRecords, PeekableRecords, Records, RecordsMut},
settings::{CellOption, TableOption},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Charset;
impl Charset {
pub fn clean() -> CleanCharset {
CleanCharset
}
}
#[derive(Debug, Default, Clone)]
pub struct CleanCharset;
impl<R, D, C> TableOption<R, C, D> for CleanCharset
where
R: Records + ExactRecords + RecordsMut<String> + PeekableRecords,
{
fn change(self, records: &mut R, _: &mut C, _: &mut D) {
for row in 0..records.count_rows() {
for col in 0..records.count_columns() {
let pos = (row, col);
let text = records.get_text(pos);
let text = text.replace(['\t', '\r'], "");
records.set(pos, text);
}
}
}
}
impl<R, C> CellOption<R, C> for CleanCharset
where
R: Records + ExactRecords + PeekableRecords + RecordsMut<String>,
{
fn change(self, records: &mut R, _: &mut C, entity: Entity) {
let count_rows = records.count_rows();
let count_cols = records.count_columns();
for pos in entity.iter(count_rows, count_cols) {
let text = records.get_text(pos);
let text = text.replace(['\t', '\r'], "");
records.set(pos, text);
}
}
}