AuroraRuntime/Include/Aurora/Parse/LineParser.hpp

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