<commit_before>use std::io::Read;
use std::io::Write;
use std::io::Result;
use std::fs::File;

pub struct FileData
{
	path: Option<String>, //the original path of the file, if provided
	content: Vec<Vec<char>>, //the content as a semi 2D-array of chars
	cursor_line: usize, //the line the cursor is in
	cursor_char: usize, //the character the cursor is in the current line
	modified: bool //ind. wether data has been changed since last save
}

impl FileData
{
	pub fn new() -> FileData
	{
		let mut linevec = Vec::new();
		let charvec = Vec::new();
		linevec.push(charvec);
		FileData
		{
			path: None,
			content: linevec,
			cursor_line: 0,
			cursor_char: 0,
			modified: false
		}
	}

	pub fn new_with_name(path: String) -> FileData
	{
		let mut result = FileData::new();
		result.path = Some(path);
		result
	}

	//load data from path
	pub fn from(filepath: String) -> Result<FileData>
	{
		let mut file = try!(File::open(filepath.clone()));
		let mut filecontent = String::new();
		try!(file.read_to_string(&mut filecontent));
		let mut linevec = Vec::new();
		let mut charvec = Vec::new();
		for ch in filecontent.chars()
		{
			if ch == '\n'
			{
				linevec.push(charvec);
				charvec = Vec::new();
			}
			else 
			{
			    charvec.push(ch);
			}
		}
		linevec.push(charvec);
		Ok(FileData
		{
			path: Some(filepath),
			content: linevec,
			cursor_line: 0,
			cursor_char: 0,
			modified: false
		})
	}

	//reset to untitled document
	pub fn clear(&mut self)
	{<commit_msg>fixed appending an empty line on file load<commit_after>use std::io::Read;
use std::io::Write;
use std::io::Result;
use std::fs::File;

pub struct FileData
{
	path: Option<String>, //the original path of the file, if provided
	content: Vec<Vec<char>>, //the content as a semi 2D-array of chars
	cursor_line: usize, //the line the cursor is in
	cursor_char: usize, //the character the cursor is in the current line
	modified: bool //ind. wether data has been changed since last save
}

impl FileData
{
	pub fn new() -> FileData
	{
		let mut linevec = Vec::new();
		let charvec = Vec::new();
		linevec.push(charvec);
		FileData
		{
			path: None,
			content: linevec,
			cursor_line: 0,
			cursor_char: 0,
			modified: false
		}
	}

	pub fn new_with_name(path: String) -> FileData
	{
		let mut result = FileData::new();
		result.path = Some(path);
		result
	}

	//load data from path
	pub fn from(filepath: String) -> Result<FileData>
	{
		let mut file = try!(File::open(filepath.clone()));
		let mut filecontent = String::new();
		try!(file.read_to_string(&mut filecontent));
		let mut linevec = Vec::new();
		let mut charvec = Vec::new();
		for ch in filecontent.chars()
		{
			if ch == '\n'
			{
				linevec.push(charvec);
				charvec = Vec::new();
			}
			else 
			{
			    charvec.push(ch);
			}
		}
		if charvec.len() != 0
		{
			linevec.push(charvec);
		}
		Ok(FileData
		{
			path: Some(filepath),
			content: linevec,
			cursor_line: 0,
			cursor_char: 0,
			modified: false
		})
	}

	//reset to untitled document
	pub fn clear(&mut self)
	{
{'fraction_non_alphanumeric': 0.13876071193144363, 'fraction_numerical': 0.0036255767963085037, 'mean_word_length': 3.250700280112045, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '4284813', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1082, 'n_words': 324}