1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-16 07:07:13 +02:00

Move line retrieval into the script wrapper.

Might be used elsewhere.
This commit is contained in:
Sandu Liviu Catalin
2019-06-16 02:20:18 +03:00
parent d6a3937107
commit acea3db378
3 changed files with 27 additions and 6 deletions

View File

@ -174,4 +174,25 @@ ScriptSrc::ScriptSrc(HSQUIRRELVM vm, String && path, bool delay, bool info)
}
}
// ------------------------------------------------------------------------------------------------
String ScriptSrc::FetchLine(size_t line, bool trim) const
{
// Do we have such line?
if (line > mLine.size())
{
return String(); // Nope!
}
// Grab it's range in the file
Line::const_reference l = mLine.at(line);
// Grab the code from that line
String code = mData.substr(l.first, l.second - l.first);
// Trim whitespace from the beginning of the code code
if (trim)
{
code.erase(0, code.find_first_not_of(" \t\n\r\f\v"));
}
// Return the resulting string
return code;
}
} // Namespace:: SqMod

View File

@ -71,6 +71,10 @@ public:
*/
ScriptSrc & operator = (ScriptSrc && o) = default;
/* --------------------------------------------------------------------------------------------
* Fetches a line from the code. Can also triim whitespace at the beginning.
*/
String FetchLine(size_t line, bool trim = true) const;
};