Skip to content

Make Charset a builder. #497

@zhiburt

Description

@zhiburt

Now we had to call Charset and TabSize to correctly handle arbitrarily data.
Which at the end of the day does 2 allocations....and whole string pass through 2 times.
Which is quite bad...

We shall move Tabsize logic into Charset and make the foremost use Builder pattern.
So we will set what changes we need to do them all at once.
Specifically a tabsize setting (currently I have 1 in mind) but likely we can came up with more convenient things.

impl<R, D, C> TableOption<R, C, D> for TabSize
where
R: Records + ExactRecords + RecordsMut<String> + PeekableRecords,
{
fn change(self, records: &mut R, _: &mut C, _: &mut D) {
let tab_size = self.0;
for row in 0..records.count_rows() {
for col in 0..records.count_columns() {
let pos = pos(row, col);
let text = records.get_text(pos);
let text = text.replace('\t', &" ".repeat(tab_size));
records.set(pos, text);
}
}
}
}

text.replace(|c| c != '\n' && c < ' ', "")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions