Struct TextReader

Source
pub struct TextReader { /* private fields */ }

Implementations§

Source§

impl TextReader

Text character reader.

§Examples

use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
while reader.has_next() {
  let ch = reader.next();
  println!("{:?}", ch);
  if let Some('\n') = ch {
    println!("{:?}", reader.this_line());
  }
}
println!("{:?}", reader.this_line());
Source

pub fn new<S: AsRef<OsStr>>(text: S) -> TextReader

Source

pub fn detector(&mut self) -> Detector<'_>

Detect possible strings

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
let mut detector = reader.detector();
Source

pub fn reset(&mut self) -> &mut TextReader

Reset to first character

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
let reader = reader.reset();
Source

pub fn peek(&self) -> Option<char>

Peek current character

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
let ch = reader.peek();
Source

pub fn next(&mut self) -> Option<char>

Next character

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
let ch = reader.next();
Source

pub fn position(&self) -> usize

Position of text

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
let position = reader.position();
Source

pub fn line(&self) -> usize

Current text line number

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
let line = reader.line();
Source

pub fn cursor(&self) -> usize

Current line position

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
reader.next();
reader.next();
reader.next();
reader.next();
let cursor = reader.cursor();
println!("CURSOR: {}", cursor); // 2
Source

pub fn len(&self) -> usize

Text length

§Examples
use text_reader::TextReader;
let reader = TextReader::new("abc\ndef");
let len = reader.len();
Source

pub fn back(&mut self) -> &mut TextReader

Back to previous character

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
reader.back();
Source

pub fn this_line(&mut self) -> Option<String>

Current line string

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
let line_text = reader.this_line();
Source

pub fn has_next(&self) -> bool

Has next character

§Examples
use text_reader::TextReader;
let mut reader = TextReader::new("abc\ndef");
while  reader.has_next(){
   let ch = reader.next();
}

Trait Implementations§

Source§

impl Debug for TextReader

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, 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.