AuroraRuntime/Include/Aurora/Parse/LineParser.hpp

32 lines
694 B
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
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;
AuString cpy = in;
while ((index = cpy.find("\n")) != AuString::npos)
{
auto line = cpy.substr(0, index);
cpy = cpy.substr(index + 1);
if (line[line.size() - 1] == '\r')
{
line.pop_back();
}
lineCallback(line);
}
lineCallback(cpy);
}
}