Software and Services, Portable Libraries  2019.Mar.01
A library for managing digital certificates
SoftwareAndServices::Library::Common::Parse Class Reference

Generic text parsing routines. More...

#include "<SaS/Common/Parse.hpp>"

+ Inheritance diagram for SoftwareAndServices::Library::Common::Parse:
+ Collaboration diagram for SoftwareAndServices::Library::Common::Parse:

Public Types

enum  charWidth_t { UnknownCharWidth_t = 0, MultibyteCharWidth_t = 1, WideCharWidth_t = 2, BinaryData_t = 3 }
 The difference between UnknownCharWidth_t and BinaryData_t is that BinaryData_t will always process in one (1) octet lengths and UnknownCharWidth_t will assume multibyte until the first multibyte operation fails. More...
 

Public Member Functions

 Parse (charWidth_t mode)
 Parse Constructor. More...
 
 Parse (const int fd, const char *filename, charWidth_t mode, const char *iCharset=nullptr, const char *oCharset=nullptr)
 Parse Constructor. More...
 
 Parse (const char *buffer, charWidth_t mode, const char *iCharset=nullptr, const char *oCharset=nullptr)
 Parse Constructor. More...
 
 Parse (const wchar_t *buffer, charWidth_t mode, const char *iCharset=nullptr, const char *oCharset=nullptr)
 Parse Constructor. More...
 
 Parse (File *file, charWidth_t mode, const char *iCharset=nullptr, const char *oCharset=nullptr)
 Parse Constructor. More...
 
virtual ~Parse ()
 Parse Destructor. More...
 
size_t CheckAccept (const String &accept) const
 Find out how may 'accept' characters are in the buffer including dot. More...
 
size_t CheckAccept (const wchar_t *accept) const
 Find out how may 'accept' characters are in the buffer including dot. More...
 
size_t CheckAccept (const char *accept) const
 Find out how may 'accept' characters are in the buffer including dot. More...
 
size_t CheckDouble () const
 Find out if the next characters are a double value (numeric). More...
 
size_t CheckInt () const
 
size_t CheckReject (const String &reject) const
 Find out how may acceptable characters are in the buffer including dot - stop at 'reject'. More...
 
size_t CheckReject (const wchar_t *reject) const
 Find out how may acceptable characters are in the buffer including dot - stop at 'reject'. More...
 
size_t CheckReject (const char *reject) const
 Find out how may acceptable characters are in the buffer including dot - stop at 'reject'. More...
 
virtual InstanceCount_t decInstance () const
 Decrement the instance. More...
 
StringGetCount (size_t count) const
 
bool GetDouble (double &results) const
 Get the double value at dot. More...
 
StringGetEntireBuffer () const
 Get a pointer to the entire buffer. More...
 
const char * GetInputCharset () const
 
virtual InstanceCount_t getInstance () const
 
bool GetInt (int &results) const
 Get the integer value at dot. More...
 
charWidth_t GetMode () const
 
const char * GetOutputCharset () const
 
StringGetUntil (const String &term) const
 Get characters up and not including the terminating string term. More...
 
StringGetUntil (const wchar_t *term) const
 Get characters up and not including the terminating string term. More...
 
StringGetUntil (const char *term) const
 Get characters up and not including the terminating string term. More...
 
StringGetUntilRegex (const String &term) const
 Get characters up and not including the terminating string POSIX regex term. More...
 
StringGetUntilRegex (const wchar_t *term) const
 Get characters up and not including the terminating string POSIX regex term. More...
 
StringGetUntilRegex (const char *term) const
 Get characters up and not including the terminating string POSIX regex term. More...
 
virtual InstanceCount_t incInstance () const
 Increment the instance. More...
 
bool IsEof () const
 
StringLookCount (size_t count) const
 
StringLookUntil (const char *term) const
 Look at characters up and not including the terminating string term. More...
 
StringLookUntil (const String &term) const
 Look at characters up and not including the terminating string term. More...
 
bool Ncasecmp (const char *CompareTo, unsigned int HowManyCharacters) const
 Compare to a string - case insensitive. More...
 
bool Ncmp (const char *CompareTo, unsigned int HowManyCharacters) const
 Compare to a string - case sensitive. More...
 
bool Open (const char *file, int rwMode, charWidth_t charMode, const char *iCharset=nullptr, const char *oCharset=nullptr)
 This uses File::open(). More...
 
 operator char () const
 
void operator delete (void *ToFree)
 
 operator wchar_t () const
 
bool operator!= (const char c) const
 Parse compare != operator (single character). More...
 
bool operator!= (const wchar_t c) const
 Parse compare != operator (single character). More...
 
bool operator== (const char c) const
 Parse compare == operator (single character). More...
 
bool operator== (const wchar_t c) const
 Parse compare == operator (single character). More...
 
bool SetInputCharset (const char *charset)
 Set the input character set. More...
 
bool SetMode (charWidth_t Width)
 Set the character width mode. More...
 
bool SetOutputCharset (const char *charset)
 Set the output character set. More...
 
size_t Skip (size_t count) const
 Skip count characters (not octets). More...
 
size_t SkipUntil (const String &term) const
 Skip until the terminating string term is found. More...
 
size_t SkipUntil (const wchar_t *term) const
 Skip until the terminating string term is found. More...
 
size_t SkipUntil (const char *term) const
 Skip until the terminating string term is found. More...
 
StringSkipWhile (const char *ToSkip)
 Move dot forward until the first character character in ToSkip is found. More...
 
StringSkipWhileNot (const char *ToSkip)
 Move dot forward until the first character character not in ToSkip is found. More...
 

Static Public Attributes

static const char * utf8
 The default INPUT and OUTPUT parser charset. More...
 

Detailed Description

Generic text parsing routines.

Definition at line 102 of file Parse.hpp.

Member Enumeration Documentation

◆ charWidth_t

The difference between UnknownCharWidth_t and BinaryData_t is that BinaryData_t will always process in one (1) octet lengths and UnknownCharWidth_t will assume multibyte until the first multibyte operation fails.

Enumerator
UnknownCharWidth_t 

Will be treated like BinaryData_t.

MultibyteCharWidth_t 

(char*) + mbs<functions>

WideCharWidth_t 

(wchar_t) + wcs<functions>

BinaryData_t 

(char*) one octet at a time.

Definition at line 119 of file Parse.hpp.

Constructor & Destructor Documentation

◆ Parse() [1/5]

SoftwareAndServices::Library::Common::Parse::Parse ( charWidth_t  mode)

Parse Constructor.

Parameters
modeThe character width mode to use.

◆ Parse() [2/5]

SoftwareAndServices::Library::Common::Parse::Parse ( const int  fd,
const char *  filename,
charWidth_t  mode,
const char *  iCharset = nullptr,
const char *  oCharset = nullptr 
)

Parse Constructor.

If both iCharset and oCharst are nullptr - use UTF-8 for both. If iCharset != nullptr && oCharset == NULL , use iCharset for both. if iCharset == nullptr && oCharset != NULL, use UTF-8 for input. if iCharset != nullptr && oCharset != NULL, use supplied value.

Parameters
fdAn open file descriptor to read from.
filenameThe file name associated with the open descriptor (fd).
modeThe character width mode to use.
iCharsetThe input character set being read.
oCharsetThe output character set to write.

◆ Parse() [3/5]

SoftwareAndServices::Library::Common::Parse::Parse ( const char *  buffer,
charWidth_t  mode,
const char *  iCharset = nullptr,
const char *  oCharset = nullptr 
)

Parse Constructor.

If both iCharset and oCharst are nullptr - use UTF-8 for both. If iCharset != nullptr && oCharset == NULL , use iCharset for both. if iCharset == nullptr && oCharset != NULL, use UTF-8 for input. if iCharset != nullptr && oCharset != NULL, use supplied value.

Parameters
bufferA buffer containing the data to parse.
modeThe character width mode to use.
iCharsetThe input character set being read.
oCharsetThe output character set to write.

◆ Parse() [4/5]

SoftwareAndServices::Library::Common::Parse::Parse ( const wchar_t *  buffer,
charWidth_t  mode,
const char *  iCharset = nullptr,
const char *  oCharset = nullptr 
)

Parse Constructor.

If both iCharset and oCharst are nullptr - use UTF-8 for both. If iCharset != nullptr && oCharset == NULL , use iCharset for both. if iCharset == nullptr && oCharset != NULL, use UTF-8 for input. if iCharset != nullptr && oCharset != NULL, use supplied value.

Parameters
bufferA buffer containing the data to parse.
modeThe character width mode to use.
iCharsetThe input character set being read.
oCharsetThe output character set to write.

◆ Parse() [5/5]

SoftwareAndServices::Library::Common::Parse::Parse ( File file,
charWidth_t  mode,
const char *  iCharset = nullptr,
const char *  oCharset = nullptr 
)

Parse Constructor.

If both iCharset and oCharst are nullptr - use UTF-8 for both. If iCharset != nullptr && oCharset == NULL , use iCharset for both. if iCharset == nullptr && oCharset != NULL, use UTF-8 for input. if iCharset != nullptr && oCharset != NULL, use supplied value.

Parameters
fileA File object to read from.
modeThe character width mode to use.
iCharsetThe input character set being read.
oCharsetThe output character set to write.

◆ ~Parse()

virtual SoftwareAndServices::Library::Common::Parse::~Parse ( )
virtual

Parse Destructor.

Member Function Documentation

◆ CheckAccept() [1/3]

size_t SoftwareAndServices::Library::Common::Parse::CheckAccept ( const String accept) const

Find out how may 'accept' characters are in the buffer including dot.

Stops of match to any character not in 'accept'. Does not increment dot.

Parameters
acceptThe allowed characters to accept.
Returns
The number of characters that follow dot that are in the accept string.

◆ CheckAccept() [2/3]

size_t SoftwareAndServices::Library::Common::Parse::CheckAccept ( const wchar_t *  accept) const

Find out how may 'accept' characters are in the buffer including dot.

Stops of match to any character not in 'accept'. Does not increment dot.

Parameters
acceptThe allowed characters to accept.
Returns
The number of characters that follow dot that are in the accept string.

◆ CheckAccept() [3/3]

size_t SoftwareAndServices::Library::Common::Parse::CheckAccept ( const char *  accept) const

Find out how may 'accept' characters are in the buffer including dot.

Stops of match to any character not in 'accept'. Does not increment dot.

Parameters
acceptThe allowed characters to accept.
Returns
The number of characters that follow dot that are in the accept string.

◆ CheckDouble()

size_t SoftwareAndServices::Library::Common::Parse::CheckDouble ( ) const

Find out if the next characters are a double value (numeric).

Returns
The number of characters allowed in a double value (1 1.2 1.3e45 ...)

◆ CheckReject() [1/3]

size_t SoftwareAndServices::Library::Common::Parse::CheckReject ( const String reject) const

Find out how may acceptable characters are in the buffer including dot - stop at 'reject'.

Stops of match to any character in 'reject'. Does not increment dot.

Parameters
rejectCharacters not wanted.
Returns
The number of characters that are acceptable.

◆ CheckReject() [2/3]

size_t SoftwareAndServices::Library::Common::Parse::CheckReject ( const wchar_t *  reject) const

Find out how may acceptable characters are in the buffer including dot - stop at 'reject'.

Stops of match to any character in 'reject'. Does not increment dot.

Parameters
rejectCharacters not wanted.
Returns
The number of characters that are acceptable.

◆ CheckReject() [3/3]

size_t SoftwareAndServices::Library::Common::Parse::CheckReject ( const char *  reject) const

Find out how may acceptable characters are in the buffer including dot - stop at 'reject'.

Stops of match to any character in 'reject'. Does not increment dot.

Parameters
rejectCharacters not wanted.
Returns
The number of characters that are acceptable.

◆ decInstance()

virtual InstanceCount_t SoftwareAndServices::Library::Common::instance< Parse >::decInstance ( ) const
inlinevirtualinherited

Decrement the instance.

Returns
The instance count, after decrementing it.

Definition at line 129 of file instance.hpp.

◆ GetCount()

String* SoftwareAndServices::Library::Common::Parse::GetCount ( size_t  count) const
Parameters
countGet this many characters.
Returns
The characters returned. If there are less than count, everything up to EOF is returned.

◆ GetDouble()

bool SoftwareAndServices::Library::Common::Parse::GetDouble ( double &  results) const

Get the double value at dot.

Parameters
resultsWhere the results are stored.
Returns
TRUE on success. Else FALSE if dot does not contain a double - then results are not touched.

◆ GetEntireBuffer()

String* SoftwareAndServices::Library::Common::Parse::GetEntireBuffer ( ) const

Get a pointer to the entire buffer.

Returns
A String containing the entire buffer.

◆ GetInputCharset()

const char* SoftwareAndServices::Library::Common::Parse::GetInputCharset ( ) const
Returns
The current character set in use on the input side.

◆ getInstance()

virtual InstanceCount_t SoftwareAndServices::Library::Common::instance< Parse >::getInstance ( ) const
inlinevirtualinherited
Returns
The current instance count.

Definition at line 118 of file instance.hpp.

◆ GetInt()

bool SoftwareAndServices::Library::Common::Parse::GetInt ( int &  results) const

Get the integer value at dot.

Parameters
resultsWhere the results are stored.
Returns
TRUE on success. Else FALSE if dot does not contain an integer - then results are not touched.

◆ GetMode()

charWidth_t SoftwareAndServices::Library::Common::Parse::GetMode ( ) const
Returns
The current character width mode being used.

◆ GetOutputCharset()

const char* SoftwareAndServices::Library::Common::Parse::GetOutputCharset ( ) const
Returns
The current character set in use on the output side.

◆ GetUntil() [1/3]

String* SoftwareAndServices::Library::Common::Parse::GetUntil ( const String term) const

Get characters up and not including the terminating string term.

Stops at first character in term.

Parameters
termStop getting characters when term is found in the string.
Returns
The characters from dot to term. If term is not found, then everything up to EOF is returned.

◆ GetUntil() [2/3]

String* SoftwareAndServices::Library::Common::Parse::GetUntil ( const wchar_t *  term) const

Get characters up and not including the terminating string term.

Stops at first character in term.

Parameters
termStop getting characters when term is found in the string.
Returns
The characters from dot to term. If term is not found, then everything up to EOF is returned.

◆ GetUntil() [3/3]

String* SoftwareAndServices::Library::Common::Parse::GetUntil ( const char *  term) const

Get characters up and not including the terminating string term.

Stops at first character in term.

Parameters
termStop getting characters when term is found in the string.
Returns
The characters from dot to term. If term is not found, then everything up to EOF is returned.

◆ GetUntilRegex() [1/3]

String* SoftwareAndServices::Library::Common::Parse::GetUntilRegex ( const String term) const

Get characters up and not including the terminating string POSIX regex term.

Stops at first character in term.

Parameters
termStop getting characters when term is found in the string.
Returns
The characters from dot to term. If term is not found, then everything up to EOF is returned.

◆ GetUntilRegex() [2/3]

String* SoftwareAndServices::Library::Common::Parse::GetUntilRegex ( const wchar_t *  term) const

Get characters up and not including the terminating string POSIX regex term.

Stops at first character in term.

Parameters
termStop getting characters when term is found in the string.
Returns
The characters from dot to term. If term is not found, then everything up to EOF is returned.

◆ GetUntilRegex() [3/3]

String* SoftwareAndServices::Library::Common::Parse::GetUntilRegex ( const char *  term) const

Get characters up and not including the terminating string POSIX regex term.

Stops at first character in term.

Parameters
termStop getting characters when term is found in the string.
Returns
The characters from dot to term. If term is not found, then everything up to EOF is returned.

◆ incInstance()

virtual InstanceCount_t SoftwareAndServices::Library::Common::instance< Parse >::incInstance ( ) const
inlinevirtualinherited

Increment the instance.

Returns
The instance value, after incrementing it.

Definition at line 109 of file instance.hpp.

◆ IsEof()

bool SoftwareAndServices::Library::Common::Parse::IsEof ( ) const
Returns
TRUE if input is at EOF.

◆ LookCount()

String* SoftwareAndServices::Library::Common::Parse::LookCount ( size_t  count) const
Parameters
countLook at this many characters.
Returns
The characters returned. If there are less than count, everything up to EOF is returned. Dot is NOT moved.

◆ LookUntil() [1/2]

String* SoftwareAndServices::Library::Common::Parse::LookUntil ( const char *  term) const

Look at characters up and not including the terminating string term.

Stops at first character in term.

Parameters
termStop getting characters when term is found in the string.
Returns
The characters from dot to term. If term is not found, then everything up to EOF is returned. Dot is NOT moved.

◆ LookUntil() [2/2]

String* SoftwareAndServices::Library::Common::Parse::LookUntil ( const String term) const

Look at characters up and not including the terminating string term.

Stops at first character in term.

Parameters
termStop getting characters when term is found in the string.
Returns
The characters from dot to term. If term is not found, then everything up to EOF is returned. Dot is NOT moved.

◆ Ncasecmp()

bool SoftwareAndServices::Library::Common::Parse::Ncasecmp ( const char *  CompareTo,
unsigned int  HowManyCharacters 
) const

Compare to a string - case insensitive.

Parameters
CompareToFirst string to compare to.
HowManyCharactersHow many characters to compare.
Returns
TRUE if they are the same, else false.

◆ Ncmp()

bool SoftwareAndServices::Library::Common::Parse::Ncmp ( const char *  CompareTo,
unsigned int  HowManyCharacters 
) const

Compare to a string - case sensitive.

Parameters
CompareToFirst string to compare to.
HowManyCharactersHow many characters to compare.
Returns
TRUE if they are the same, else false.

◆ Open()

bool SoftwareAndServices::Library::Common::Parse::Open ( const char *  file,
int  rwMode,
charWidth_t  charMode,
const char *  iCharset = nullptr,
const char *  oCharset = nullptr 
)

This uses File::open().

Parameters
fileThe file name to open.
rwModeO_RDONLY -or- O_WRONLY.
charModeThe character width mode.
iCharsetThe character set to use.
oCharsetThe character output set to use.
Returns
TRUE if opened and all passed parameters are usable.

SEE the note for the Parse constructor - iCharset and oCharset.

◆ operator char()

SoftwareAndServices::Library::Common::Parse::operator char ( ) const
Returns
The character at dot.

◆ operator wchar_t()

SoftwareAndServices::Library::Common::Parse::operator wchar_t ( ) const
Returns
The character at dot.

◆ operator!=() [1/2]

bool SoftwareAndServices::Library::Common::Parse::operator!= ( const char  c) const

Parse compare != operator (single character).

Returns
TRUE when they DO NOT match the character at dot.

◆ operator!=() [2/2]

bool SoftwareAndServices::Library::Common::Parse::operator!= ( const wchar_t  c) const

Parse compare != operator (single character).

Returns
TRUE when they DO NOT match the character at dot.

◆ operator==() [1/2]

bool SoftwareAndServices::Library::Common::Parse::operator== ( const char  c) const

Parse compare == operator (single character).

Returns
TRUE when they match the character at dot.

◆ operator==() [2/2]

bool SoftwareAndServices::Library::Common::Parse::operator== ( const wchar_t  c) const

Parse compare == operator (single character).

Returns
TRUE when they match the character at dot.

◆ SetInputCharset()

bool SoftwareAndServices::Library::Common::Parse::SetInputCharset ( const char *  charset)

Set the input character set.

Parameters
charsetThe character set to use for input.
Returns
TRUE if known and set.

◆ SetMode()

bool SoftwareAndServices::Library::Common::Parse::SetMode ( charWidth_t  Width)

Set the character width mode.

Parameters
WidthThe character width mode to use.
Returns
TRUE if allowed and set.

◆ SetOutputCharset()

bool SoftwareAndServices::Library::Common::Parse::SetOutputCharset ( const char *  charset)

Set the output character set.

Parameters
charsetThe character set to use for output.
Returns
TRUE if known and set.

◆ Skip()

size_t SoftwareAndServices::Library::Common::Parse::Skip ( size_t  count) const

Skip count characters (not octets).

Parameters
countThe number of characters to skip.
Returns
The number of characters skipped. If less than count, EOF was reached.

◆ SkipUntil() [1/3]

size_t SoftwareAndServices::Library::Common::Parse::SkipUntil ( const String term) const

Skip until the terminating string term is found.

Stops at first character in term.

Parameters
termStop skipping when term is found in the string.
Returns
The number of characters skipped (not octets).

◆ SkipUntil() [2/3]

size_t SoftwareAndServices::Library::Common::Parse::SkipUntil ( const wchar_t *  term) const

Skip until the terminating string term is found.

Stops at first character in term.

Parameters
termStop skipping when term is found in the string.
Returns
The number of characters skipped (not octets).

◆ SkipUntil() [3/3]

size_t SoftwareAndServices::Library::Common::Parse::SkipUntil ( const char *  term) const

Skip until the terminating string term is found.

Stops at first character in term.

Parameters
termStop skipping when term is found in the string.
Returns
The number of characters skipped (not octets).

◆ SkipWhile()

String* SoftwareAndServices::Library::Common::Parse::SkipWhile ( const char *  ToSkip)

Move dot forward until the first character character in ToSkip is found.

Parameters
ToSkipStop getting characters when the first character not in ToSkip is found in the string.
Returns
The characters from dot to ToSkip. If ToSkip is not found, then everything up to EOF is returned. Dot is moved.

◆ SkipWhileNot()

String* SoftwareAndServices::Library::Common::Parse::SkipWhileNot ( const char *  ToSkip)

Move dot forward until the first character character not in ToSkip is found.

Parameters
ToSkipStop getting characters when the first character not in ToSkip is found in the string.
Returns
The characters from dot to ToSkip. If ToSkip is not found, then everything up to EOF is returned. Dot is moved.

Member Data Documentation

◆ utf8

const char* SoftwareAndServices::Library::Common::Parse::utf8
static

The default INPUT and OUTPUT parser charset.

Definition at line 110 of file Parse.hpp.


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