| Copyright | (c) Alec Theriault 2017-2018 |
|---|---|
| License | BSD-style |
| Maintainer | alec.theriault@gmail.com |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Language.Rust.Data.InputStream
Description
These are the only functions that need to be implemented in order to use the parser. Whether this
wraps ByteString or String depends on whether the useByteStrings option is on or not (it is
by default). Using ByteString means better handling of weird characters (takeByte for plain
String fails badly if you try to take a byte that doesn't fall on a character boundary), but it
means incurring a dependency on the utf8-string
package.
- data InputStream
- countLines :: InputStream -> Int
- inputStreamEmpty :: InputStream -> Bool
- readInputStream :: FilePath -> IO InputStream
- hReadInputStream :: Handle -> IO InputStream
- inputStreamFromString :: String -> InputStream
- inputStreamToString :: InputStream -> String
- takeByte :: InputStream -> (Word8, InputStream)
- takeChar :: InputStream -> (Char, InputStream)
- peekChars :: Int -> InputStream -> String
InputStream type
countLines :: InputStream -> Int Source #
Returns the number of text lines in the given InputStream
>>>countLines ""0
>>>countLines "foo"1
>>>countLines "foo\n\nbar"3
>>>countLines "foo\n\nbar\n"3
inputStreamEmpty :: InputStream -> Bool Source #
Return True if the given input stream is empty.
>>>inputStreamEmpty ""True
>>>inputStreamEmpty "foo"False
Introduction forms
readInputStream :: FilePath -> IO InputStream Source #
Read an encoded file into an InputStream
hReadInputStream :: Handle -> IO InputStream Source #
Read an InputStream from a Handle
inputStreamFromString :: String -> InputStream Source #
Convert a String to an InputStream.
Elimination forms
inputStreamToString :: InputStream -> String Source #
Convert InputStream to String.
takeByte :: InputStream -> (Word8, InputStream) Source #
Read the first byte from an InputStream and return that byte with what remains of the
InputStream. Behaviour is undefined when inputStreamEmpty returns True.
>>>takeByte "foo bar"(102, "oo bar")
>>>takeByte "Ĥăƨĸëļļ"(196, "\ETX\168\&8\235<<")
takeChar :: InputStream -> (Char, InputStream) Source #
Read the first character from an InputStream and return that Char with what remains of the
InputStream. Behaviour is undefined when inputStreamEmpty returns True.
>>>takeChar "foo bar"('f', "oo bar")
>>>takeChar "Ĥăƨĸëļļ"('Ĥ', "ăƨĸëļļ")