Scanner

Struct Scanner 

Source
pub struct Scanner<R: Read + Sized> { /* private fields */ }
Expand description

Rust implementation of java.util.Scanner

Implementations§

Source§

impl<R: Read + Sized> Scanner<R>

Implements the meta-methods of Scanner that affect how the data stream is processed, e.g., delimiter, parsing radix, etc.

Source

pub fn set_delim(&mut self, delim: Regex) -> &Regex

Sets the delimiter to be some pre-compiled regex and return it for behavioral consistency.

Source

pub fn set_delim_str(&mut self, delim: &str) -> &Regex

Sets the delimiter to be a string literal. The resulting delimiting expression is guaranteed to only interpret the literal passed in, i.e., this method cannot be used to simultaneously compile and set an arbitrary regular expression.

We return the compiled delimiting expression.

Source

pub fn get_delim(&self) -> &Regex

Return the delimiter for Scanner.next() and methods that depend on it.

Source

pub fn set_radix(&mut self, radix: u32) -> u32

Sets the radix in which numbers are parsed. This value must be on the closed range [2, 36], such that alphabet characters represent values greater than 9 in bases exceeding 10.

We return the postcondition value of the radix, which is the input if the input is within the valid range or the precondition value otherwise.

Source

pub fn get_radix(&self) -> u32

Retrieve the radix on which we perform numeric parsing.

Source§

impl<R: Read + Sized> Scanner<R>

Implements the methods of Scanner that affect the underlying data stream

Source

pub fn new(stream: R) -> Scanner<R>

Creates a new instance of Scanner on some object implementing Read

Source

pub fn with_capacity(size: usize, stream: R) -> Scanner<R>

Creates a new instance of Scanner using a BufReader with a specified buffer size.

This instantiator allows the user to specify the capacity of the buffer. Its primary use-case is unit testing this module, i.e., it would be cumbersome to write 64KB test strings so one might specify a capacity of only a few bytes in order to test what happens at the

Source

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

Returns Some(String) containing the next string if there is one. Otherwise returns None.

We first consume all leading delims that fit within the buffer of the underlying BufRead, then attempt to read everything until (but excluding) the next delim which is entirely contained within a single buffer. We guarantee this will behave as expected if the longest single precendent delimiter is no larger than the size of the buffer.

Otherwise it will fail.

Source

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

Read up to (but excluding) the next \n character. If there are any leading delims, they will be included in the returned string.

NOTE: unlike next() we do consume the trailing \n, if it exists.

Source

pub fn next_int<T: Integer>(&mut self) -> Option<T>

Attempts to retrieve the next integer of the specified (or inferred) type. Even if this fails, we still consume next.

The default radix for this parsing is 10, but users may specify a one-time arbitrary radix using Scanner.next_int_radix(u32) or persistently using Scanner.set_radix(u32).

Source

pub fn next_int_radix<T: Integer>(&mut self, radix: u32) -> Option<T>

Returns the next integer in some arbitrary base on [2, 36].

If the radix provided is outside of this range, we do nothing. Otherwise, we will consume next() even if it is not a valid integer.

NOTE: If one means to repeatedly parse in a fixed, arbitrary base, it is more efficient to use Scanner.set_radix(u32) followed by Scanner.next_int with no radix argument.

Source

pub fn next_float<T: Float>(&mut self) -> Option<T>

Attempts to retrieve the next floating-point number of the specified (or inferred) type. Even if this fails, we still consume next.

Note that this method is based on Scanner.next(), so the delimiter is still the same.

Source

pub fn next_float_radix<T: Float>(&mut self, radix: u32) -> Option<T>

Returns the next float in some arbitrary base on [2, 36].

If the radix provided is outside of this range, we do nothing. Otherwise, we will consume next() even if it is not a valid integer.

NOTE: If one means to repeatedly parse in a fixed, arbitrary base, it is more efficient to use Scanner.set_radix(u32) followed by Scanner.next_float with no radix argument.

Auto Trait Implementations§

§

impl<R> !Freeze for Scanner<R>

§

impl<R> !RefUnwindSafe for Scanner<R>

§

impl<R> Send for Scanner<R>
where R: Send,

§

impl<R> Sync for Scanner<R>
where R: Sync,

§

impl<R> Unpin for Scanner<R>
where R: Unpin,

§

impl<R> UnwindSafe for Scanner<R>
where R: UnwindSafe,

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.