diff options
author | madmaxoft <github@xoft.cz> | 2013-10-04 09:20:15 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-10-04 13:10:30 +0200 |
commit | 58f5ac84aba8f1f95a1c39721bd18080fb3c455a (patch) | |
tree | a1a477468cb9706c8dcd446297ce764268434bf7 /source/HTTPServer/NameValueParser.h | |
parent | Added StrToLower(), URLDecode() and ReplaceAllCharOccurrences(). (diff) | |
download | cuberite-58f5ac84aba8f1f95a1c39721bd18080fb3c455a.tar cuberite-58f5ac84aba8f1f95a1c39721bd18080fb3c455a.tar.gz cuberite-58f5ac84aba8f1f95a1c39721bd18080fb3c455a.tar.bz2 cuberite-58f5ac84aba8f1f95a1c39721bd18080fb3c455a.tar.lz cuberite-58f5ac84aba8f1f95a1c39721bd18080fb3c455a.tar.xz cuberite-58f5ac84aba8f1f95a1c39721bd18080fb3c455a.tar.zst cuberite-58f5ac84aba8f1f95a1c39721bd18080fb3c455a.zip |
Diffstat (limited to 'source/HTTPServer/NameValueParser.h')
-rw-r--r-- | source/HTTPServer/NameValueParser.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/source/HTTPServer/NameValueParser.h b/source/HTTPServer/NameValueParser.h new file mode 100644 index 000000000..111cb6052 --- /dev/null +++ b/source/HTTPServer/NameValueParser.h @@ -0,0 +1,70 @@ + +// NameValueParser.h + +// Declares the cNameValueParser class that parses strings in the "name=value;name2=value2" format into a stringmap + + + + + +#pragma once + + + + + +class cNameValueParser : + public std::map<AString, AString> +{ +public: + /// Creates an empty parser + cNameValueParser(bool a_AllowsKeyOnly = true); + + /// Creates an empty parser, then parses the data given + cNameValueParser(const char * a_Data, int a_Size, bool a_AllowsKeyOnly = true); + + /// Parses the data given + void Parse(const char * a_Data, int a_Size); + + /// Notifies the parser that no more data will be coming. Returns true if the parser state is valid + bool Finish(void); + + /// Returns true if the data parsed so far was valid + bool IsValid(void) const { return (m_State != psInvalid); } + + /// Returns true if the parser expects no more data + bool IsFinished(void) const { return ((m_State == psInvalid) || (m_State == psFinished)); } + +protected: + enum eState + { + psKeySpace, ///< Parsing the space in front of the next key + psKey, ///< Currently adding more chars to the key in m_CurrentKey + psEqualSpace, ///< Space after m_CurrentKey + psEqual, ///< Just parsed the = sign after a name + psValueInSQuotes, ///< Just parsed a Single-quote sign after the Equal sign + psValueInDQuotes, ///< Just parsed a Double-quote sign after the Equal sign + psValueRaw, ///< Just parsed a raw value without a quote + psAfterValue, ///< Just finished parsing the value, waiting for semicolon or data end + psInvalid, ///< The parser has encountered an invalid input; further parsing is skipped + psFinished, ///< The parser has already been instructed to finish and doesn't expect any more data + } ; + + /// The current state of the parser + eState m_State; + + /// If true, the parser will accept keys without an equal sign and the value + bool m_AllowsKeyOnly; + + /// Buffer for the current Key + AString m_CurrentKey; + + /// Buffer for the current Value; + AString m_CurrentValue; + + +} ; + + + + |