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