mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Detect shebang more precisely and simplify erase code
This commit is contained in:
parent
b37e6b7db8
commit
488a588aea
1 changed files with 3 additions and 10 deletions
|
@ -67,16 +67,9 @@ std::optional<std::string> readFile(const std::string& name)
|
||||||
if (read != size_t(length))
|
if (read != size_t(length))
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
// Skip first line if it's a comment
|
// Skip first line if it's a shebang
|
||||||
if (length != 0 && result[0] == '#')
|
if (length > 2 && result[0] == '#' && result[1] == '!')
|
||||||
{
|
result.erase(0, result.find('\n'));
|
||||||
auto newLine = result.find('\n');
|
|
||||||
|
|
||||||
if (newLine != std::string::npos)
|
|
||||||
result.erase(0, newLine);
|
|
||||||
else
|
|
||||||
result.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue