added API for getting error messages

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40277
This commit is contained in:
David Anderson 2007-01-06 07:53:56 +00:00
parent 814007df49
commit 43005abc2f
3 changed files with 42 additions and 6 deletions

View File

@ -6,7 +6,7 @@
#include <assert.h>
#include "CTextParsers.h"
CTextParsers g_TextParse;
CTextParsers g_TextParser;
static int g_ini_chartable1[255] = {0};
static int g_ws_chartable[255] = {0};
@ -898,3 +898,28 @@ event_failed:
return false;
}
const char *CTextParsers::GetSMCErrorString(SMCParseError err)
{
static const char *s_errors[] =
{
NULL,
"Stream failed to open",
"Stream returned read error",
NULL,
"Un-quoted section has invalid tokens",
"Section declared without header",
"Section declared with unknown tokens",
"Section ending without a matching section beginning",
"Line contained too many invalid tokens",
"Token buffer overflowed",
"A property was declared outside of a section",
};
if (err < SMCParse_Okay || err > SMCParse_InvalidProperty1)
{
return NULL;
}
return s_errors[err];
}

View File

@ -37,17 +37,19 @@ class CTextParsers : public ITextParsers
public:
CTextParsers();
public:
virtual bool ParseFile_INI(const char *file,
bool ParseFile_INI(const char *file,
ITextListener_INI *ini_listener,
unsigned int *line,
unsigned int *col);
virtual SMCParseError ParseFile_SMC(const char *file,
SMCParseError ParseFile_SMC(const char *file,
ITextListener_SMC *smc_listener,
unsigned int *line,
unsigned int *col);
virtual unsigned int GetUTF8CharBytes(const char *stream);
unsigned int GetUTF8CharBytes(const char *stream);
const char *GetSMCErrorString(SMCParseError err);
private:
SMCParseError ParseString_SMC(const char *stream,
ITextListener_SMC *smc,
@ -61,6 +63,6 @@ private:
};
extern CTextParsers g_TextParse;
extern CTextParsers g_TextParser;
#endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_H_

View File

@ -149,7 +149,7 @@ namespace SourceMod
enum SMCParseError
{
SMCParse_Okay, //no error
SMCParse_Okay = 0, //no error
SMCParse_StreamOpen, //stream failed to open
SMCParse_StreamError, //the stream died... somehow
SMCParse_Custom, //a custom handler threw an error
@ -292,6 +292,15 @@ namespace SourceMod
ITextListener_SMC *smc_listener,
unsigned int *line,
unsigned int *col) =0;
/**
* @brief Converts an SMCParseError to a stirng.
*
* @param err SMCParseError.
* @return String error message, or NULL if none.
*/
virtual const char *GetSMCErrorString(SMCParseError err) =0;
public:
/**
* @brief Returns the number of bytes that a multi-byte character contains in a UTF-8 stream.