diff --git a/core/logic/smn_textparse.cpp b/core/logic/smn_textparse.cpp index 0ba919c2..09b919fb 100644 --- a/core/logic/smn_textparse.cpp +++ b/core/logic/smn_textparse.cpp @@ -29,6 +29,8 @@ * Version: $Id$ */ +#include + #include "common_logic.h" #include #include @@ -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 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}, diff --git a/plugins/include/textparse.inc b/plugins/include/textparse.inc index cad74a6f..1d8cc634 100644 --- a/plugins/include/textparse.inc +++ b/plugins/include/textparse.inc @@ -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);