<commit_before>//! This module contains definition of table rows stuff
use std::io::{Write, Error};
use std::iter::FromIterator;
use std::slice::{Iter, IterMut};
use std::ops::{Index, IndexMut};

use term::Terminal;

use super::utils::NEWLINE;
use super::cell::Cell;
use super::format::{TableFormat, ColumnPosition};

/// Represent a table row made of cells
#[derive(Clone, Debug)]
pub struct Row {
	cells: Vec<Cell>
}

impl Row {
	/// Create a new `Row` backed with `cells` vector
	pub fn new(cells: Vec<Cell>) -> Row {
		Row {
			cells: cells
		}
	}

	/// Create an row of length `size`, with empty strings stored
	pub fn empty() -> Row {
		Self::new(vec![Cell::default(); 0])
	}

	/// Get the number of cells in this row
	pub fn len(&self) -> usize {
		self.cells.len()
	}

	/// Get the height of this row
	pub fn get_height(&self) -> usize {
		let mut height = 1; // Minimum height must be 1 to print empty rows
		for cell in &self.cells {
			let h = cell.get_height();
			if h > height {
				height = h;
			}
		}
		height
	}

	/// Get the minimum width required by the cell in the column `column`.
	/// Return 0 if the cell does not exist in this row
	pub fn get_cell_width(&self, column: usize) -> usize {
		match self.cells.get(column) {
			Some(cell) => cell.get_width(),
			None => 0
		}
	}

	/// Get the cell at index `idx`
	pub fn get_cell(&self, idx: usize) -> Option<&Cell> {
		self.cells.get(idx)
	}

	/// Get the mutable cell at index `idx`
	pub fn get_mut_cell(&mut self, idx: usize) -> Option<&mut Cell> {
		self.cells.get_mut(idx)
	}

	/// Set the `cell` in the row at the given `column`
	pub fn set_cell(&mut self, cell: Cell, column: usize) -> Result<(), &str> {
		if column >= self.len() {
			return Err("Cannot find cell");
		}<commit_msg>Replace match with mapping<commit_after>//! This module contains definition of table rows stuff
use std::io::{Write, Error};
use std::iter::FromIterator;
use std::slice::{Iter, IterMut};
use std::ops::{Index, IndexMut};

use term::Terminal;

use super::utils::NEWLINE;
use super::cell::Cell;
use super::format::{TableFormat, ColumnPosition};

/// Represent a table row made of cells
#[derive(Clone, Debug)]
pub struct Row {
	cells: Vec<Cell>
}

impl Row {
	/// Create a new `Row` backed with `cells` vector
	pub fn new(cells: Vec<Cell>) -> Row {
		Row {
			cells: cells
		}
	}

	/// Create an row of length `size`, with empty strings stored
	pub fn empty() -> Row {
		Self::new(vec![Cell::default(); 0])
	}

	/// Get the number of cells in this row
	pub fn len(&self) -> usize {
		self.cells.len()
	}

	/// Get the height of this row
	pub fn get_height(&self) -> usize {
		let mut height = 1; // Minimum height must be 1 to print empty rows
		for cell in &self.cells {
			let h = cell.get_height();
			if h > height {
				height = h;
			}
		}
		height
	}

	/// Get the minimum width required by the cell in the column `column`.
	/// Return 0 if the cell does not exist in this row
	pub fn get_cell_width(&self, column: usize) -> usize {
		self.cells.get(column).map(|cell| cell.get_width()).unwrap_or(0)
	}

	/// Get the cell at index `idx`
	pub fn get_cell(&self, idx: usize) -> Option<&Cell> {
		self.cells.get(idx)
	}

	/// Get the mutable cell at index `idx`
	pub fn get_mut_cell(&mut self, idx: usize) -> Option<&mut Cell> {
		self.cells.get_mut(idx)
	}

	/// Set the `cell` in the row at the given `column`
	pub fn set_cell(&mut self, cell: Cell, column: usize) -> Result<(), &str> {
		if column >= self.len() {
			return Err("Cannot find cell");
		}
{'fraction_non_alphanumeric': 0.15154961615012796, 'fraction_numerical': 0.0028433323855558716, 'mean_word_length': 3.3007334963325183, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1393572', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1202, 'n_words': 433}