AuroraRuntime/Include/Aurora/Parse/LineParser.hpp

31 lines
717 B
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LineParser.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
namespace Aurora::Parse
{
static void SplitNewlines(const AuString &in, std::function<void(const AuString &)> lineCallback)
{
AuMach index = 0, startIdx = 0;
while ((index = in.find("\n", startIdx)) != AuString::npos)
{
auto line = in.substr(startIdx, index - startIdx);
startIdx = index + 1;
if (line[line.size() - 1] == '\r')
{
line.pop_back();
}
lineCallback(line);
}
lineCallback(in.substr(startIdx));
}
}