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:
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user