core/CTextParsers.h
author David Anderson <dvander@alliedmods.net>
Fri Mar 02 08:34:13 2007 +0000 (2007-03-02)
changeset 558 fc0eec032efb
parent 370 d3a484f98f6d
permissions -rw-r--r--
added state change function
     1 /**
     2  * ===============================================================
     3  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     4  * ===============================================================
     5  *
     6  * This file is not open source and may not be copied without explicit
     7  * written permission of AlliedModders LLC.  This file may not be redistributed 
     8  * in whole or significant part.
     9  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    10  *
    11  * Version: $Id$
    12  */
    13 
    14 #ifndef _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
    15 #define _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
    16 
    17 #include <ITextParsers.h>
    18 #include "sm_globals.h"
    19 
    20 using namespace SourceMod;
    21 
    22 inline unsigned int _GetUTF8CharBytes(const char *stream)
    23 {
    24 	unsigned char c = *(unsigned char *)stream;
    25 	if (c & (1<<7))
    26 	{
    27 		if (c & (1<<5))
    28 		{
    29 			if (c & (1<<4))
    30 			{
    31 				return 4;
    32 			}
    33 			return 3;
    34 		}
    35 		return 2;
    36 	}
    37 	return 1;
    38 }
    39 
    40 /**
    41  * @param void *			IN: Stream pointer
    42  * @param char *			IN/OUT: Stream buffer
    43  * @param size_t			IN: Maximum size of buffer
    44  * @param unsigned int *	OUT: Number of bytes read (0 = end of stream)
    45  * @return					True on success, false on failure
    46  */
    47 typedef bool (*STREAMREADER)(void *, char *, size_t, unsigned int *);
    48 
    49 class CTextParsers : 
    50 	public ITextParsers,
    51 	public SMGlobalClass
    52 {
    53 public:
    54 	CTextParsers();
    55 public: //SMGlobalClass
    56 	void OnSourceModAllInitialized();
    57 public:
    58 	bool ParseFile_INI(const char *file, 
    59 		ITextListener_INI *ini_listener,
    60 		unsigned int *line,
    61 		unsigned int *col);
    62 
    63 	SMCParseError ParseFile_SMC(const char *file, 
    64 		ITextListener_SMC *smc_listener, 
    65 		unsigned int *line, 
    66 		unsigned int *col);
    67 
    68 	unsigned int GetUTF8CharBytes(const char *stream);
    69 
    70 	const char *GetSMCErrorString(SMCParseError err);
    71 private:
    72 	SMCParseError ParseString_SMC(const char *stream, 
    73 		ITextListener_SMC *smc,
    74 		unsigned int *line,
    75 		unsigned int *col);
    76 	SMCParseError ParseStream_SMC(void *stream, 
    77 		STREAMREADER srdr,
    78 		ITextListener_SMC *smc,
    79 		unsigned int *line, 
    80 		unsigned int *col);
    81 
    82 };
    83 
    84 extern CTextParsers g_TextParser;
    85 
    86 #endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_H_