SourceMod SDK  1.7
ITextParsers.h
Go to the documentation of this file.
1 
32 #ifndef _INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_
33 #define _INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_
34 
40 #include <IShareSys.h>
41 
42 namespace SourceMod
43 {
44 
45  #define SMINTERFACE_TEXTPARSERS_NAME "ITextParsers"
46  #define SMINTERFACE_TEXTPARSERS_VERSION 4
47 
91  {
92  public:
96  virtual unsigned int GetTextParserVersion1()
97  {
98  return SMINTERFACE_TEXTPARSERS_VERSION;
99  }
100  public:
112  virtual bool ReadINI_NewSection(const char *section,
113  bool invalid_tokens,
114  bool close_bracket,
115  bool extra_tokens,
116  unsigned int *curtok)
117  {
118  return true;
119  }
120 
133  virtual bool ReadINI_KeyValue(const char *key,
134  const char *value,
135  bool invalid_tokens,
136  bool equal_token,
137  bool quotes,
138  unsigned int *curtok)
139  {
140  return true;
141  }
142 
150  virtual bool ReadINI_RawLine(const char *line, unsigned int *curtok)
151  {
152  return true;
153  }
154  };
155 
198  enum SMCResult
199  {
200  SMCResult_Continue,
201  SMCResult_Halt,
202  SMCResult_HaltFail
203  };
204 
208  enum SMCError
209  {
210  SMCError_Okay = 0,
211  SMCError_StreamOpen,
212  SMCError_StreamError,
213  SMCError_Custom,
214  SMCError_InvalidSection1,
215  SMCError_InvalidSection2,
216  SMCError_InvalidSection3,
217  SMCError_InvalidSection4,
218  SMCError_InvalidSection5,
219  SMCError_InvalidTokens,
220  SMCError_TokenOverflow,
221  SMCError_InvalidProperty1,
222  };
223 
227  struct SMCStates
228  {
229  unsigned int line;
230  unsigned int col;
231  };
232 
237  {
238  public:
242  virtual unsigned int GetTextParserVersion2()
243  {
244  return SMINTERFACE_TEXTPARSERS_VERSION;
245  }
246  public:
250  virtual void ReadSMC_ParseStart()
251  {
252  };
253 
260  virtual void ReadSMC_ParseEnd(bool halted, bool failed)
261  {
262  }
263 
271  virtual SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name)
272  {
273  return SMCResult_Continue;
274  }
275 
285  virtual SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
286  {
287  return SMCResult_Continue;
288  }
289 
296  virtual SMCResult ReadSMC_LeavingSection(const SMCStates *states)
297  {
298  return SMCResult_Continue;
299  }
300 
309  virtual SMCResult ReadSMC_RawLine(const SMCStates *states, const char *line)
310  {
311  return SMCResult_Continue;
312  }
313  };
314 
318  class ITextParsers : public SMInterface
319  {
320  public:
321  virtual const char *GetInterfaceName()
322  {
323  return SMINTERFACE_TEXTPARSERS_NAME;
324  }
325  virtual unsigned int GetInterfaceVersion()
326  {
327  return SMINTERFACE_TEXTPARSERS_VERSION;
328  }
329  virtual bool IsVersionCompatible(unsigned int version)
330  {
331  if (version < 2)
332  {
333  return false;
334  }
335  return SMInterface::IsVersionCompatible(version);
336  }
337  public:
347  virtual bool ParseFile_INI(const char *file,
348  ITextListener_INI *ini_listener,
349  unsigned int *line,
350  unsigned int *col) =0;
351 
363  virtual SMCError ParseFile_SMC(const char *file,
364  ITextListener_SMC *smc_listener,
365  SMCStates *states) =0;
366 
373  virtual const char *GetSMCErrorString(SMCError err) =0;
374 
375  public:
383  virtual unsigned int GetUTF8CharBytes(const char *stream) =0;
384 
392  virtual bool IsWhitespace(const char *stream) =0;
393 
404  virtual SMCError ParseSMCFile(const char *file,
405  ITextListener_SMC *smc_listener,
406  SMCStates *states,
407  char *buffer,
408  size_t maxsize) =0;
409 
421  virtual SMCError ParseSMCStream(const char *stream,
422  size_t length,
423  ITextListener_SMC *smc_listener,
424  SMCStates *states,
425  char *buffer,
426  size_t maxsize) =0;
427  };
428 
429  inline unsigned int _GetUTF8CharBytes(const char *stream)
430  {
431  unsigned char c = *(unsigned char *)stream;
432  if (c & (1<<7))
433  {
434  if (c & (1<<5))
435  {
436  if (c & (1<<4))
437  {
438  return 4;
439  }
440  return 3;
441  }
442  return 2;
443  }
444  return 1;
445  }
446 }
447 
448 extern SourceMod::ITextParsers *textparsers;
449 
450 #endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_
451 
States for line/column.
Definition: ITextParsers.h:227
Describes the events available for reading an SMC stream.
Definition: ITextParsers.h:236
virtual bool IsWhitespace(const char *stream)=0
Returns whether the first multi-byte character in the given stream is a whitespace character...
virtual SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
Called when encountering a key/value pair in a section.
Definition: ITextParsers.h:285
virtual void ReadSMC_ParseStart()
Called when starting parsing.
Definition: ITextParsers.h:250
virtual bool IsVersionCompatible(unsigned int version)
Must return whether the requested version number is backwards compatible. Note: This can be overridde...
Definition: ITextParsers.h:329
virtual bool ReadINI_NewSection(const char *section, bool invalid_tokens, bool close_bracket, bool extra_tokens, unsigned int *curtok)
Called when a new section is encountered in an INI file.
Definition: ITextParsers.h:112
Defines the Share System, responsible for shared resources and dependencies.
virtual SMCResult ReadSMC_RawLine(const SMCStates *states, const char *line)
Called after an input line has been preprocessed.
Definition: ITextParsers.h:309
unsigned int line
Definition: ITextParsers.h:229
Defines the base functionality required by a shared interface.
Definition: IShareSys.h:92
Contains parse events for INI files.
Definition: ITextParsers.h:90
virtual SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name)
Called when entering a new section.
Definition: ITextParsers.h:271
virtual bool ReadINI_RawLine(const char *line, unsigned int *curtok)
Called after a line has been preprocessed, if it has text.
Definition: ITextParsers.h:150
virtual const char * GetInterfaceName()
Must return a string defining the interface's unique name.
Definition: ITextParsers.h:321
virtual SMCError ParseFile_SMC(const char *file, ITextListener_SMC *smc_listener, SMCStates *states)=0
Parses an SMC-format text file. Note that the parser makes every effort to obey broken syntax...
virtual bool ReadINI_KeyValue(const char *key, const char *value, bool invalid_tokens, bool equal_token, bool quotes, unsigned int *curtok)
Called when encountering a key/value pair in an INI file.
Definition: ITextParsers.h:133
virtual unsigned int GetTextParserVersion2()
Returns version number.
Definition: ITextParsers.h:242
Contains various text stream parsing functions.
Definition: ITextParsers.h:318
virtual bool IsVersionCompatible(unsigned int version)
Must return whether the requested version number is backwards compatible. Note: This can be overridde...
Definition: IShareSys.h:112
Definition: IAdminSystem.h:63
virtual bool ParseFile_INI(const char *file, ITextListener_INI *ini_listener, unsigned int *line, unsigned int *col)=0
Parses an INI-format file.
virtual void ReadSMC_ParseEnd(bool halted, bool failed)
Called when ending parsing.
Definition: ITextParsers.h:260
virtual const char * GetSMCErrorString(SMCError err)=0
Converts an SMCError to a string.
unsigned int col
Definition: ITextParsers.h:230
virtual unsigned int GetInterfaceVersion()
Must return an integer defining the interface's version.
Definition: ITextParsers.h:325
virtual SMCError ParseSMCFile(const char *file, ITextListener_SMC *smc_listener, SMCStates *states, char *buffer, size_t maxsize)=0
Same as ParseFile_SMC, but with an extended error buffer.
virtual unsigned int GetUTF8CharBytes(const char *stream)=0
Returns the number of bytes that a multi-byte character contains in a UTF-8 stream. If the current character is not multi-byte, the function returns 1.
virtual SMCResult ReadSMC_LeavingSection(const SMCStates *states)
Called when leaving the current section.
Definition: ITextParsers.h:296
virtual unsigned int GetTextParserVersion1()
Returns version number.
Definition: ITextParsers.h:96
virtual SMCError ParseSMCStream(const char *stream, size_t length, ITextListener_SMC *smc_listener, SMCStates *states, char *buffer, size_t maxsize)=0
Parses a raw UTF8 stream as an SMC file.