TxtProcessor

Struct TxtProcessor 

Source
pub struct TxtProcessor { /* private fields */ }
Expand description

TxtProcessor struct

Implementations§

Source§

impl TxtProcessor

Source

pub fn from_file(file_path: &str) -> Result<Self, Error>

Reads text from file

Source

pub fn from_str(str: String) -> Self

Reads text from string

Source

pub fn count_word_occurences(&self, word: &str) -> usize

Reads text from file

Source

pub fn contains(&self, word: &str) -> bool

Counts how many times a word occurs in a text

Source

pub fn find_unique(&self) -> Vec<String>

Finds unique words in a text

Source

pub fn filter(&self, condition: &dyn Fn(&str) -> bool) -> Vec<String>

Finds all words matching the condition

Source

pub fn find_first_occurence(&self, word: &str) -> Result<usize, Error>

Finds the first ocuurence of a word in a text

Source

pub fn search_occurences(&self, word: &str) -> Vec<usize>

Finds all occurrences of a word in a text

Source

pub fn search_with_index(&self, index: usize) -> Result<String, Error>

Finds word on that position in a text

Source

pub fn replace_word(&mut self, from: &str, to: &str)

Replaces all words ‘from’ on word ‘to’

Source

pub fn replace_char(&mut self, from: char, to: char)

Replaces all characters ‘from’ on character ‘to’

Source

pub fn rewrite_file(&self, file_path: &str) -> Result<(), Error>

Rewrites file with self.content

Source

pub fn append_file(&self, file_path: &str) -> Result<(), Error>

Appends self.content to file

Source

pub fn fix(&mut self)

Fix spaces in text

Source

pub fn search_with_regex(&self, regex: Regex) -> Vec<String>

Search for all words matching this regular expression

Source

pub fn add_to_content(&mut self, text: String)

Adds text to this TxtProcessor’s content

Source

pub fn get_lines(&self) -> usize

Returns lines amount

Source

pub fn get_words(&self) -> usize

Returns words amount

Source

pub fn get_content(&self) -> String

Returns content

Source

pub fn get_file_path(&self) -> Option<String>

Returns file path

Trait Implementations§

Source§

impl Debug for TxtProcessor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.