Struct file_scanner::Scanner
[−]
[src]
pub struct Scanner<R: Read + Sized> { /* fields omitted */ }
Rust implementation of java.util.Scanner
Methods
impl<R: Read + Sized> Scanner<R>
[src]
Implements the meta-methods of Scanner that affect how the data stream is processed, e.g., delimiter, parsing radix, etc.
pub fn set_delim(&mut self, delim: Regex) -> &Regex
[src]
Sets the delimiter to be some pre-compiled regex and return it for behavioral consistency.
pub fn set_delim_str(&mut self, delim: &str) -> &Regex
[src]
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.
pub fn get_delim(&self) -> &Regex
[src]
Return the delimiter for Scanner.next()
and methods that depend on it.
pub fn set_radix(&mut self, radix: u32) -> u32
[src]
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.
pub fn get_radix(&self) -> u32
[src]
Retrieve the radix on which we perform numeric parsing.
impl<R: Read + Sized> Scanner<R>
[src]
Implements the methods of Scanner that affect the underlying data stream
pub fn new(stream: R) -> Scanner<R>
[src]
Creates a new instance of Scanner on some object implementing Read
pub fn with_capacity(size: usize, stream: R) -> Scanner<R>
[src]
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
pub fn next(&mut self) -> Option<String>
[src]
Returns Some(String)
containing the next string if there is one.
Otherwise returns None
.
We first consume all leading delim
s 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.
pub fn next_line(&mut self) -> Option<String>
[src]
Read up to (but excluding) the next \n
character.
If there are any leading delim
s, they will be included in the
returned string.
NOTE: unlike next()
we do consume the trailing \n
, if it exists.
pub fn next_int<T: Integer>(&mut self) -> Option<T>
[src]
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)
.
pub fn next_int_radix<T: Integer>(&mut self, radix: u32) -> Option<T>
[src]
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.
pub fn next_float<T: Float>(&mut self) -> Option<T>
[src]
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.
pub fn next_float_radix<T: Float>(&mut self, radix: u32) -> Option<T>
[src]
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.