ModErn Text Analysis
META Enumerates Textual Applications
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
meta::io::parser Class Reference

Parses a text file by reading it completely into memory, delimiting tokens by user request. More...

#include <parser.h>

Public Types

enum  input_type { File, String }
 Determines whether the parser parses a std::string or the contents of a file.
 

Public Member Functions

 parser (const std::string &input, const std::string &delims, input_type in_type=input_type::File)
 
 ~parser ()
 Destructor.
 
 parser (parser &&)
 May be move-constructed.
 
parseroperator= (parser &&)
 May be move-assigned.
 
std::string filename () const
 
std::string peek () const
 
std::string next ()
 
bool has_next () const
 

Private Member Functions

void get_next ()
 Advances to the next token in the file or string, saving the result.
 

Private Attributes

size_t idx_
 The current position of the "cursor" into the file or string.
 
std::array< bool, 256 > invalid_
 Array of booleans indicating whether or not a character is a delimiter.
 
std::string filename_
 Saves the name of the file if the parser is parsing a file.
 
std::unique_ptr< io::mmap_filemmap_file_
 Memory-mapped file pointer if the parser is parsing a file.
 
uint64_t size_
 The number of characters that will be read.
 
const char * data_
 Pointer into a string or memory-mapped file.
 
util::optional< std::string > next_
 The next token to be returned; "" if none.
 

Detailed Description

Parses a text file by reading it completely into memory, delimiting tokens by user request.

Constructor & Destructor Documentation

meta::io::parser::parser ( const std::string &  input,
const std::string &  delims,
input_type  in_type = input_type::File 
)
Parameters
pathThe path to the file to parse
delimsDelimiters to be used for separating tokens
in_typeDetermines whether the input is a file or a string

Member Function Documentation

std::string meta::io::parser::filename ( ) const
Returns
the filename of the file that is being parsed
std::string meta::io::parser::peek ( ) const
Returns
the next token in the parser without advancing the current position
std::string meta::io::parser::next ( )
Returns
the next token in the parser, advancing to the next one if it exists
bool meta::io::parser::has_next ( ) const
Returns
whether the parser contains another token

The documentation for this class was generated from the following files: