Make some methods public for ZString.

This commit is contained in:
Brad Arant 2024-02-16 11:28:44 -08:00
parent ab14fb3fcd
commit ce71aefaac

768
ZString.h
View File

@ -1,391 +1,391 @@
#ifndef __ZString_h__ #ifndef __ZString_h__
#define __ZString_h__ # define __ZString_h__
#include <ostream> # include <ostream>
#include <stack> # include <stack>
#include <string.h> # include <string.h>
#include <string> # include <string>
#include <vector> # include <vector>
namespace coreutils { namespace coreutils {
/// ///
/// Use the ZString object when advanced parsing algorithms are required to simplify /// Use the ZString object when advanced parsing algorithms are required to simplify
/// parsing. ZString is not a backing store and requires that any referenced buffer /// parsing. ZString is not a backing store and requires that any referenced buffer
/// or objects are retained throughout the life of the object. Additionally, ZString /// or objects are retained throughout the life of the object. Additionally, ZString
/// is non-destructive to its underlying references. /// is non-destructive to its underlying references.
/// ///
/// ZString provides several methods to reference and parse the content. First method /// ZString provides several methods to reference and parse the content. First method
/// is split(ZString delimiter) which will return a vector of ZString which contains /// is split(ZString delimiter) which will return a vector of ZString which contains
/// references to the parts of the string split by the provided delimiter. The delimiter /// references to the parts of the string split by the provided delimiter. The delimiter
/// portion is omitted from the results. /// portion is omitted from the results.
/// ///
/// Second method involves a cursor which is a pointer to data contained within the /// Second method involves a cursor which is a pointer to data contained within the
/// ZString and is used to point to the current parsing point. Several methods are /// ZString and is used to point to the current parsing point. Several methods are
/// provided to advance through the parsing based upon content and rule checks. /// provided to advance through the parsing based upon content and rule checks.
/// ///
/// During the parsing process you can retrieve the parsed and unparsed sections of /// During the parsing process you can retrieve the parsed and unparsed sections of
/// the ZString as ZStrings. /// the ZString as ZStrings.
/// ///
/// You can stream the ZString to an output stream using the << operator and the entire /// You can stream the ZString to an output stream using the << operator and the entire
/// contents of the ZString will be output regardless of parsing activity. /// contents of the ZString will be output regardless of parsing activity.
/// ///
class ZString { class ZString {
public: public:
/// ///
/// Consructor providing an empty ZString. /// Consructor providing an empty ZString.
/// ///
ZString(); ZString();
/// ///
/// Constructor wrapping a null terminated buffer to a ZString. /// Constructor wrapping a null terminated buffer to a ZString.
/// ///
ZString(const char *data); ZString(const char *data);
/// ///
/// Consructor providing the initial setup of the ZString object. /// Consructor providing the initial setup of the ZString object.
/// ///
ZString(char *data, size_t length); ZString(char *data, size_t length);
/// ///
/// ///
/// ///
ZString(const char *data, size_t length); ZString(const char *data, size_t length);
ZString(unsigned char *data, size_t length); ZString(unsigned char *data, size_t length);
/// ///
/// ///
/// ///
ZString(const ZString &zstring); ZString(const ZString &zstring);
ZString(const unsigned char *data, size_t length); ZString(const unsigned char *data, size_t length);
/// ///
/// Consructor providing a copy of a ZString. /// Consructor providing a copy of a ZString.
/// ///
ZString(std::string &string); ZString(std::string &string);
/// ///
/// Consructor from a string. /// Consructor from a string.
/// ///
// ZString(std::string string); // ZString(std::string string);
/// ///
/// Destructor for the ZString. /// Destructor for the ZString.
/// ///
~ZString(); ~ZString();
/// ///
/// A friend method used to write the value of the ZString /// A friend method used to write the value of the ZString
/// to an ostream using the << syntax. /// to an ostream using the << syntax.
/// ///
friend std::ostream &operator<<(std::ostream &os, const ZString &zstring); friend std::ostream &operator<<(std::ostream &os, const ZString &zstring);
friend std::ostream &operator<<(std::ostream &os, const std::string &string); friend std::ostream &operator<<(std::ostream &os, const std::string &string);
friend std::ostream &operator+(std::ostream &os, const ZString &zstring); friend std::ostream &operator+(std::ostream &os, const ZString &zstring);
friend std::ostream &operator+(std::ostream &os, const char *value); friend std::ostream &operator+(std::ostream &os, const char *value);
/// ///
/// A friend method used to write the value of the ZString /// A friend method used to write the value of the ZString
/// to an ostream using the << syntax. /// to an ostream using the << syntax.
/// ///
bool operator<(const ZString &valuex) const; bool operator<(const ZString &valuex) const;
/// ///
/// ///
/// ///
bool operator>(const ZString &valuex) const; bool operator>(const ZString &valuex) const;
bool operator==(const ZString &valuex); bool operator==(const ZString &valuex);
// bool operator==(std::string value); // bool operator==(std::string value);
// bool operator==(const char *valuex) const; // bool operator==(const char *valuex) const;
bool operator!=(const ZString &valuex) const; bool operator!=(const ZString &valuex) const;
bool operator!=(const char *valuex) const; bool operator!=(const char *valuex) const;
/// ///
/// Return a vector of ZString objects which contain the parts established /// Return a vector of ZString objects which contain the parts established
/// by using the split method and passing a delimiter value. /// by using the split method and passing a delimiter value.
/// ///
std::vector<ZString> &getList(); std::vector<ZString> &getList();
/// ///
/// Return the integer value of the ZString from the cursor to the first /// Return the integer value of the ZString from the cursor to the first
/// non-numeric character. /// non-numeric character.
/// ///
int asInteger(); int asInteger();
/// ///
/// ///
/// ///
int incrementCursor(int length); int incrementCursor(int length);
/// ///
/// Use the push method to push the current cursor pointer to a stack. /// Use the push method to push the current cursor pointer to a stack.
/// ///
void push(); void push();
/// ///
/// Use the pop method to pop a previously pushed cursor pointer from the /// Use the pop method to pop a previously pushed cursor pointer from the
/// cursor stack. The cursor will point to the same location in the /// cursor stack. The cursor will point to the same location in the
/// ZString where the cursor was pushed. /// ZString where the cursor was pushed.
/// ///
void pop(); void pop();
/// ///
/// Return the value of the ZString from the cursor to the end. /// Return the value of the ZString from the cursor to the end.
/// ///
std::string str(); std::string str();
/// ///
/// Return the current value of the ZString as a string of /// Return the current value of the ZString as a string of
/// specified length. /// specified length.
/// ///
std::string str(int len); std::string str(int len);
/// ///
/// ///
/// ///
char *c_str(); char *c_str();
/// ///
/// ///
/// ///
ZString substring(int start); ZString substring(int start);
/// ///
/// ///
/// ///
ZString substring(int start, int len); ZString substring(int start, int len);
/// ///
/// ///
/// ///
std::vector<ZString> &split(ZString &delimiter, size_t maxSize = 0); std::vector<ZString> &split(ZString &delimiter, size_t maxSize = 0);
/// ///
/// ///
/// ///
std::vector<ZString> &split(std::string delimiter, size_t maxSize = 0); std::vector<ZString> &split(std::string delimiter, size_t maxSize = 0);
/// ///
/// Use getTokenInclude with a list of character to allow the forwarding /// Use getTokenInclude with a list of character to allow the forwarding
/// of the cursor through the data until a character that is not in the /// of the cursor through the data until a character that is not in the
/// include string is not encountered in the ZString data. /// include string is not encountered in the ZString data.
/// ///
ZString getTokenInclude(const char *include); ZString getTokenInclude(const char *include);
/// ///
/// ///
/// ///
ZString getTokenExclude(const char *exclude); ZString getTokenExclude(const char *exclude);
/// ///
/// ///
/// ///
ZString getTokenExclude(std::string exclude); ZString getTokenExclude(std::string exclude);
/// ///
/// If the cursor is over a container character then a call to this method /// If the cursor is over a container character then a call to this method
/// will return the contents of the container. The cursor will remain at /// will return the contents of the container. The cursor will remain at
/// the position following the container. /// the position following the container.
/// ///
ZString getContainer(); ZString getContainer();
/// ///
/// Use the [] operator to retrieve values delimited by the split method. /// Use the [] operator to retrieve values delimited by the split method.
/// ///
ZString &operator[](int index); ZString &operator[](int index);
/// ///
/// Return true if the ZString cursor is at the end of the data. /// Return true if the ZString cursor is at the end of the data.
/// ///
bool eod(); bool eod();
/// ///
/// ///
/// ///
bool startsWith(const char *value); bool startsWith(const char *value);
/// ///
/// ///
/// ///
bool equals(const char *value); bool equals(const char *value);
/// ///
/// ///
/// ///
bool equals(char *value); bool equals(char *value);
/// ///
/// ///
/// ///
bool equals(ZString &zstring); bool equals(ZString &zstring);
/// ///
/// ///
/// ///
bool equals(std::string &string); bool equals(std::string &string);
/// ///
/// Advance the cursor the length of the provided value if the value at /// Advance the cursor the length of the provided value if the value at
/// the cursor position is equal to the value provided. /// the cursor position is equal to the value provided.
/// ///
bool ifNext(const char *value); bool ifNext(const char *value);
/// ///
/// ///
/// ///
bool ifNext(ZString &value); bool ifNext(ZString &value);
/// ///
/// ///
/// ///
int ifEqualsCount(ZString &comparator); int ifEqualsCount(ZString &comparator);
/// ///
/// Advance the cursor through the ZString for each whitespace character /// Advance the cursor through the ZString for each whitespace character
/// encountered. /// encountered.
/// ///
int skipWhitespace(); int skipWhitespace();
/// ///
/// ///
/// ///
ZString goeol(); ZString goeol();
/// ///
/// Return a block of data as a ZString from the cursor location for /// Return a block of data as a ZString from the cursor location for
/// the number of bytes specified by size. /// the number of bytes specified by size.
/// ///
ZString readBlock(size_t size); ZString readBlock(size_t size);
/// ///
/// ///
/// ///
int find(ZString comparator); int find(ZString comparator);
/// ///
/// Return a block of data as a ZString from the cursor location for /// Return a block of data as a ZString from the cursor location for
/// the number of bytes specified by size. /// the number of bytes specified by size.
/// ///
char *getData(); char *getData();
/// ///
/// ///
/// ///
char *getCursor(); char *getCursor();
/// ///
/// ///
/// ///
void setCursor(char *cursor); void setCursor(char *cursor);
/// ///
/// Return the length of the ZString. /// Return the length of the ZString.
/// ///
size_t getLength(); size_t getLength();
/// ///
/// Set this ZString to have the same data space as the ZString pointer /// Set this ZString to have the same data space as the ZString pointer
/// passed into the method. /// passed into the method.
/// ///
void setZString(ZString zstring); void setZString(ZString zstring);
/// ///
/// Use the parsed method to return a ZString that represents the portion /// Use the parsed method to return a ZString that represents the portion
/// ZString that has been parsed. The returned ZString represents the /// ZString that has been parsed. The returned ZString represents the
/// portion of the ZString from the data pointer to the cursor. /// portion of the ZString from the data pointer to the cursor.
/// ///
ZString parsed(); ZString parsed();
/// ///
/// ///
/// ///
ZString unparsed(); ZString unparsed();
/// ///
/// ///
/// ///
void reset(); void reset();
/// ///
/// ///
/// ///
char charAt(int index); char charAt(int index);
/// ///
/// ///
/// ///
bool ifCRLF(); bool ifCRLF();
// void nextChar(); void nextChar();
protected: bool boolValue();
char *data;
char *cursor; protected:
size_t length; char *data;
char *cdata = NULL; char *cursor;
std::vector<ZString> list; size_t length;
bool boolValue(); char *cdata = NULL;
void nextChar(); std::vector<ZString> list;
private: private:
std::stack<char *> stack; std::stack<char *> stack;
bool isCharacter(char ch, const char *string); bool isCharacter(char ch, const char *string);
}; };
} }
#endif #endif