Add SMCParser.ParseString (#1817)

This commit is contained in:
Corey D 2022-12-03 02:55:08 +11:00 committed by GitHub
parent 8538233985
commit 5d391fda07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -29,6 +29,8 @@
* Version: $Id$
*/
#include <string.h>
#include "common_logic.h"
#include <ITextParsers.h>
#include <ISourceMod.h>
@ -264,6 +266,32 @@ static cell_t SMC_ParseFile(IPluginContext *pContext, const cell_t *params)
return (cell_t)p_err;
}
static cell_t SMC_ParseString(IPluginContext *pContext, const cell_t *params)
{
OpenHandle<ParseInfo> parse(pContext, params[1], g_TypeSMC);
if (!parse.Ok())
return 0;
char *str;
pContext->LocalToString(params[2], &str);
SMCStates states;
SMCError p_err = textparsers->ParseSMCStream(str,
strlen(str),
parse,
&states,
NULL,
0);
cell_t *c_line, *c_col;
pContext->LocalToPhysAddr(params[3], &c_line);
pContext->LocalToPhysAddr(params[4], &c_col);
*c_line = states.line;
*c_col = states.col;
return (cell_t)p_err;
}
static cell_t SMC_GetErrorString(IPluginContext *pContext, const cell_t *params)
{
const char *str = textparsers->GetSMCErrorString((SMCError)params[1]);
@ -334,6 +362,7 @@ REGISTER_NATIVES(textNatives)
// Transitional syntax support.
{"SMCParser.SMCParser", SMC_CreateParser},
{"SMCParser.ParseFile", SMC_ParseFile},
{"SMCParser.ParseString", SMC_ParseString},
{"SMCParser.OnStart.set", SMC_SetParseStart},
{"SMCParser.OnEnd.set", SMC_SetParseEnd},
{"SMCParser.OnEnterSection.set", SMCParser_OnEnterSection_set},

View File

@ -147,6 +147,14 @@ methodmap SMCParser < Handle
// @return An SMCParseError result.
public native SMCError ParseFile(const char[] file, int &line = 0, int &col = 0);
// Parses raw UTF-8 text as an SMC file.
//
// @param string A string containing an SMC file.
// @param line An optional variable to store the last line number read.
// @param col An optional variable to store the last column number read.
// @return An SMCParseError result.
public native SMCError ParseString(const char[] string, int &line = 0, int &col = 0);
// Sets the callback for receiving SMC_ParseStart events.
property SMC_ParseStart OnStart {
public native set(SMC_ParseStart func);