Jamie Reece Wilson
83f34b0c47
03:28:55:638 17>2 of 53388 functions (<0.1%) were compiled, the rest were copied from previous compilation. 03:28:55:638 17> 0 functions were new in current compilation 03:28:55:638 17> 65 functions had inline decision re-evaluated but remain unchanged 03:28:56:749 17>Finished generating code the header of const AuString & is the same as std::string_view therefore nothing changes. in fact, we still need to alloc strings a bunch of times for a zero terminated string. worse, <c++20 always allocs each time we want to access a hashmap with o(1) lookup, making small hashmaps kinda pointless when we always have to alloc+copy (thx std) perhaps this will help some language binders
84 lines
2.1 KiB
C++
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 AuROString SplitNewlines(const AuROString &in, AuFunction<void(const AuROString &)> 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.remove_suffix(1);
|
|
}
|
|
|
|
lineCallback(line);
|
|
|
|
if (startIdx >= in.size())
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (returnRemaining)
|
|
{
|
|
return in.substr(startIdx);
|
|
}
|
|
else
|
|
{
|
|
lineCallback(in.substr(startIdx));
|
|
return {};
|
|
}
|
|
}
|
|
|
|
static void SplitNewlines(const AuROString &in, AuFunction<void(const AuROString &)> lineCallback)
|
|
{
|
|
SplitNewlines(in, lineCallback, false);
|
|
}
|
|
|
|
static AuList<AuROString> SplitString(const AuROString &in, AuUInt16 characters)
|
|
{
|
|
AuList<AuROString> ret;
|
|
for (auto i = 0u; i < in.size(); i += characters)
|
|
{
|
|
auto start = i;
|
|
auto end = AuMin(AuUInt32(in.size()), AuUInt32(i + characters));
|
|
auto len = end - start;
|
|
ret.push_back(in.substr(start, len));
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static AuString SplitStringDelm(const AuROString &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 = AuMin(AuUInt32(in.size()), AuUInt32(i + characters));
|
|
len = end - start;
|
|
|
|
ret.insert(ret.size(), in.substr(start, len));
|
|
}
|
|
return ret;
|
|
}
|
|
} |