AuroraRuntime/Include/Aurora/Parse/LineParser.hpp
Reece a626fbea24 [+] HWInfo::GetPageSize()
[+] Parse::SplitNewlines(..., ..., true) where the return value is the remaining unbuffered line
[*] Gross hack we should remove to drop std string parse exception abuse logs
[*] Update AuroraForEach and AuroraInterfaces
[*] Experiment with using alternative os address space reserve + commit mechanics for Memory::Heaps
[*] global fast rand device should be seeded with at least 64 bits of secure rng data. ideally, we should max out entropy with secure bits, but we dont
2021-10-14 12:35:05 +01:00

84 lines
2.1 KiB
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 AuString SplitNewlines(const AuString &in, std::function<void(const AuString &)> lineCallback, bool returnRemaining)
{
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);
if (startIdx >= in.size())
{
break;
}
}
if (returnRemaining)
{
return in.substr(startIdx);
}
else
{
lineCallback(in.substr(startIdx));
return {};
}
}
static void SplitNewlines(const AuString &in, std::function<void(const AuString &)> lineCallback)
{
SplitNewlines(in, lineCallback, false);
}
static AuList<AuString> SplitString(const AuString &in, AuUInt16 characters)
{
AuList<AuString> ret;
for (auto i = 0u; i < in.size(); i += characters)
{
auto start = i;
auto end = std::min(AuUInt32(in.size()), AuUInt32(i + characters));
auto len = end - start;
ret.push_back(in.substr(start, len));
}
return ret;
}
static AuString SplitStringDelm(const AuString &in, const AuString &delm, AuUInt16 characters)
{
AuString ret;
ret.reserve(in.size());
for (auto i = 0u; i < in.size(); i += characters)
{
AuUInt32 start, end, len;
if (i != 0)
{
ret.insert(ret.size(), delm);
}
start = i;
end = std::min(AuUInt32(in.size()), AuUInt32(i + characters));
len = end - start;
ret.insert(ret.size(), in.substr(start, len));
}
return ret;
}
}