core/TextParsers.h
author David Anderson <dvander@alliedmods.net>
Fri Mar 16 20:10:13 2007 +0000 (2007-03-16)
changeset 631 76dc2aa558e5
parent 616 d5b1dcf38c07
child 653 ef60870067ff
permissions -rw-r--r--
added StrBreak from AMX Mod X, with various improvements
     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 bool IsWhitespace(const char *stream);
    41 
    42 /**
    43  * @param void *			IN: Stream pointer
    44  * @param char *			IN/OUT: Stream buffer
    45  * @param size_t			IN: Maximum size of buffer
    46  * @param unsigned int *	OUT: Number of bytes read (0 = end of stream)
    47  * @return					True on success, false on failure
    48  */
    49 typedef bool (*STREAMREADER)(void *, char *, size_t, unsigned int *);
    50 
    51 class TextParsers : 
    52 	public ITextParsers,
    53 	public SMGlobalClass
    54 {
    55 public:
    56 	TextParsers();
    57 public: //SMGlobalClass
    58 	void OnSourceModAllInitialized();
    59 public:
    60 	bool ParseFile_INI(const char *file, 
    61 		ITextListener_INI *ini_listener,
    62 		unsigned int *line,
    63 		unsigned int *col);
    64 
    65 	SMCParseError ParseFile_SMC(const char *file, 
    66 		ITextListener_SMC *smc_listener, 
    67 		unsigned int *line, 
    68 		unsigned int *col);
    69 
    70 	unsigned int GetUTF8CharBytes(const char *stream);
    71 
    72 	const char *GetSMCErrorString(SMCParseError err);
    73 private:
    74 	SMCParseError ParseString_SMC(const char *stream, 
    75 		ITextListener_SMC *smc,
    76 		unsigned int *line,
    77 		unsigned int *col);
    78 	SMCParseError ParseStream_SMC(void *stream, 
    79 		STREAMREADER srdr,
    80 		ITextListener_SMC *smc,
    81 		unsigned int *line, 
    82 		unsigned int *col);
    83 
    84 };
    85 
    86 extern TextParsers g_TextParser;
    87 
    88 #endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_H_