core/TextParsers.h
changeset 591 86e97f3eda1f
child 616 d5b1dcf38c07
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/TextParsers.h	Sat Mar 10 21:18:07 2007 +0000
     1.3 @@ -0,0 +1,86 @@
     1.4 +/**
     1.5 + * ===============================================================
     1.6 + * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     1.7 + * ===============================================================
     1.8 + *
     1.9 + * This file is not open source and may not be copied without explicit
    1.10 + * written permission of AlliedModders LLC.  This file may not be redistributed 
    1.11 + * in whole or significant part.
    1.12 + * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    1.13 + *
    1.14 + * Version: $Id$
    1.15 + */
    1.16 +
    1.17 +#ifndef _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
    1.18 +#define _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
    1.19 +
    1.20 +#include <ITextParsers.h>
    1.21 +#include "sm_globals.h"
    1.22 +
    1.23 +using namespace SourceMod;
    1.24 +
    1.25 +inline unsigned int _GetUTF8CharBytes(const char *stream)
    1.26 +{
    1.27 +	unsigned char c = *(unsigned char *)stream;
    1.28 +	if (c & (1<<7))
    1.29 +	{
    1.30 +		if (c & (1<<5))
    1.31 +		{
    1.32 +			if (c & (1<<4))
    1.33 +			{
    1.34 +				return 4;
    1.35 +			}
    1.36 +			return 3;
    1.37 +		}
    1.38 +		return 2;
    1.39 +	}
    1.40 +	return 1;
    1.41 +}
    1.42 +
    1.43 +/**
    1.44 + * @param void *			IN: Stream pointer
    1.45 + * @param char *			IN/OUT: Stream buffer
    1.46 + * @param size_t			IN: Maximum size of buffer
    1.47 + * @param unsigned int *	OUT: Number of bytes read (0 = end of stream)
    1.48 + * @return					True on success, false on failure
    1.49 + */
    1.50 +typedef bool (*STREAMREADER)(void *, char *, size_t, unsigned int *);
    1.51 +
    1.52 +class CTextParsers : 
    1.53 +	public ITextParsers,
    1.54 +	public SMGlobalClass
    1.55 +{
    1.56 +public:
    1.57 +	CTextParsers();
    1.58 +public: //SMGlobalClass
    1.59 +	void OnSourceModAllInitialized();
    1.60 +public:
    1.61 +	bool ParseFile_INI(const char *file, 
    1.62 +		ITextListener_INI *ini_listener,
    1.63 +		unsigned int *line,
    1.64 +		unsigned int *col);
    1.65 +
    1.66 +	SMCParseError ParseFile_SMC(const char *file, 
    1.67 +		ITextListener_SMC *smc_listener, 
    1.68 +		unsigned int *line, 
    1.69 +		unsigned int *col);
    1.70 +
    1.71 +	unsigned int GetUTF8CharBytes(const char *stream);
    1.72 +
    1.73 +	const char *GetSMCErrorString(SMCParseError err);
    1.74 +private:
    1.75 +	SMCParseError ParseString_SMC(const char *stream, 
    1.76 +		ITextListener_SMC *smc,
    1.77 +		unsigned int *line,
    1.78 +		unsigned int *col);
    1.79 +	SMCParseError ParseStream_SMC(void *stream, 
    1.80 +		STREAMREADER srdr,
    1.81 +		ITextListener_SMC *smc,
    1.82 +		unsigned int *line, 
    1.83 +		unsigned int *col);
    1.84 +
    1.85 +};
    1.86 +
    1.87 +extern CTextParsers g_TextParser;
    1.88 +
    1.89 +#endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_H_