core/CTextParsers.h
author David Anderson <dvander@alliedmods.net>
Wed Jan 17 06:49:59 2007 +0000 (2007-01-17)
changeset 308 f0e65f92cb34
parent 272 f8481df956a7
child 324 e23aca731e37
permissions -rw-r--r--
Redesigned how server commands work. The "plugins" command will be back soon.
     1 #ifndef _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
     2 #define _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
     3 
     4 #include "interfaces/ITextParsers.h"
     5 
     6 using namespace SourceMod;
     7 
     8 inline unsigned int _GetUTF8CharBytes(const char *stream)
     9 {
    10 	unsigned char c = *(unsigned char *)stream;
    11 	if (c & (1<<7))
    12 	{
    13 		if (c & (1<<5))
    14 		{
    15 			if (c & (1<<4))
    16 			{
    17 				return 4;
    18 			}
    19 			return 3;
    20 		}
    21 		return 2;
    22 	}
    23 	return 1;
    24 }
    25 
    26 /**
    27  * @param void *			IN: Stream pointer
    28  * @param char *			IN/OUT: Stream buffer
    29  * @param size_t			IN: Maximum size of buffer
    30  * @param unsigned int *	OUT: Number of bytes read (0 = end of stream)
    31  * @return					True on success, false on failure
    32  */
    33 typedef bool (*STREAMREADER)(void *, char *, size_t, unsigned int *);
    34 
    35 class CTextParsers : public ITextParsers
    36 {
    37 public:
    38 	CTextParsers();
    39 public:
    40 	bool ParseFile_INI(const char *file, 
    41 		ITextListener_INI *ini_listener,
    42 		unsigned int *line,
    43 		unsigned int *col);
    44 
    45 	SMCParseError ParseFile_SMC(const char *file, 
    46 		ITextListener_SMC *smc_listener, 
    47 		unsigned int *line, 
    48 		unsigned int *col);
    49 
    50 	unsigned int GetUTF8CharBytes(const char *stream);
    51 
    52 	const char *GetSMCErrorString(SMCParseError err);
    53 private:
    54 	SMCParseError ParseString_SMC(const char *stream, 
    55 		ITextListener_SMC *smc,
    56 		unsigned int *line,
    57 		unsigned int *col);
    58 	SMCParseError ParseStream_SMC(void *stream, 
    59 		STREAMREADER srdr,
    60 		ITextListener_SMC *smc,
    61 		unsigned int *line, 
    62 		unsigned int *col);
    63 
    64 };
    65 
    66 extern CTextParsers g_TextParser;
    67 
    68 #endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_H_