[+] (From Runtime and modified): AuSplitNewlines
[+] (From Runtime and modified): AuTrySplitString(AuListOfHeap<AuROString> &ret, ...) [+] (From Runtime and modified): AuTrySplitString(AuList<AuROString> &ret, ...) [+] (From Runtime and modified): AuSplitString(...) [+] (From Runtime and modified): AuTrySplitStringWithDelimiter(...) [+] (From Runtime and modified): AuSplitStringWithDelimiter(...) [+] AU_STATIC_OR_OPTIMIZE_SPACE
This commit is contained in:
parent
c03a44e8b9
commit
b75ca6fd60
@ -215,6 +215,25 @@
|
|||||||
// yay, more confusion over what "inline" actually means
|
// yay, more confusion over what "inline" actually means
|
||||||
|
|
||||||
#define AU_OPTIMIZED static auline
|
#define AU_OPTIMIZED static auline
|
||||||
|
|
||||||
|
#if defined(AURORA_FORCE_SPACE_OPTIMIZATION)
|
||||||
|
// explicit: use global symbol linkage vs one per language translation unit
|
||||||
|
#define AU_STATIC_OR_OPTIMIZE_SPACE inline
|
||||||
|
#elif defined(AURORA_IS_MODERNNT_DERIVED)
|
||||||
|
// assume desktop with massive instruction caches and execution pipelines
|
||||||
|
#define AU_STATIC_OR_OPTIMIZE_SPACE static
|
||||||
|
#elif defined(AURORA_IS_LINUX_DERIVED) && defined(AURORA_ARCH_X64)
|
||||||
|
// assume desktop with massive instruction caches and execution pipelines
|
||||||
|
#define AU_STATIC_OR_OPTIMIZE_SPACE static
|
||||||
|
#elif defined(AURORA_IS_LINUX_DERIVED)
|
||||||
|
// assume embedded with limited ROM
|
||||||
|
#define AU_STATIC_OR_OPTIMIZE_SPACE inline
|
||||||
|
#else
|
||||||
|
// dont know, dont care
|
||||||
|
#define AU_STATIC_OR_OPTIMIZE_SPACE static
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// ps:
|
// ps:
|
||||||
// we wont add __attribute__((optimize(...)) macros
|
// we wont add __attribute__((optimize(...)) macros
|
||||||
// most compilers treat them as file level options; no per function attributes override this.
|
// most compilers treat them as file level options; no per function attributes override this.
|
||||||
|
66
Include/auROXTL/Strings/auLinerParserAndSplitter.hpp
Normal file
66
Include/auROXTL/Strings/auLinerParserAndSplitter.hpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/***
|
||||||
|
Copyright (C) 2021-2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||||
|
|
||||||
|
File: auLinerParserAndSplitter.hpp
|
||||||
|
Date: 2024-12-26
|
||||||
|
File: LineParser.hpp
|
||||||
|
Date: 2021-6-9
|
||||||
|
Author: Reece
|
||||||
|
Note: one of the original APIs from Aurora::Parse
|
||||||
|
***/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits lines from @param in
|
||||||
|
* @param in Buffer to parse
|
||||||
|
* @param lineCallback a tempated callable () operator (AuFunction, traditional callback function, binding, etc)
|
||||||
|
* @param bReturnRemaining Assuming POSIX-like boomer logic, every text command sequence must be terminated with a line return.
|
||||||
|
* The lack of \n implies incomplete data. bReturnRemaining = true will return this incomplete data, otherwise,
|
||||||
|
* lineCallback(...) is called for each line on the assumed fully buffered blob - including the final line.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
template <typename Callable>
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
AuROString AuSplitNewlines(const AuROString &in,
|
||||||
|
const Callable &lineCallback,
|
||||||
|
bool bReturnRemaining = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
bool AuTrySplitString(AuListOfHeap<AuROString> &ret,
|
||||||
|
const AuROString &in,
|
||||||
|
AuUInt16 uCharacters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
bool AuTrySplitString(AuList<AuROString> &ret,
|
||||||
|
const AuROString &in,
|
||||||
|
AuUInt16 uCharacters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
AuList<AuROString> AuSplitString(const AuROString &in,
|
||||||
|
AuUInt16 uCharacters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints while joining the components using the specified @param delimiter into a reserved string buffer
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
bool AuTrySplitStringWithDelimiter(AuString &ret,
|
||||||
|
const AuROString &in,
|
||||||
|
const AuROString &delimiter,
|
||||||
|
AuUInt16 uCharacters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints while joining the components using the specified @param delimiter into a reserved string buffer
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
AuString AuSplitStringWithDelimiter(const AuROString &in,
|
||||||
|
const AuROString &delimiter,
|
||||||
|
AuUInt16 uCharacters);
|
200
Include/auROXTL/Strings/auLinerParserAndSplitter.ipp
Normal file
200
Include/auROXTL/Strings/auLinerParserAndSplitter.ipp
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
/***
|
||||||
|
Copyright (C) 2021-2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||||
|
|
||||||
|
File: auLinerParserAndSplitter.ipp
|
||||||
|
Date: 2024-12-26
|
||||||
|
File: LineParser.hpp
|
||||||
|
Date: 2021-6-9
|
||||||
|
Author: Reece
|
||||||
|
Note: one of the original APIs from Aurora::Parse
|
||||||
|
***/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits lines from @param in
|
||||||
|
* @param in Buffer to parse
|
||||||
|
* @param lineCallback a tempated callable () operator (AuFunction, traditional callback function, binding, etc)
|
||||||
|
* @param bReturnRemaining Assuming POSIX-like boomer logic, every text command sequence must be terminated with a line return.
|
||||||
|
* The lack of \n implies incomplete data. bReturnRemaining = true will return this incomplete data, otherwise,
|
||||||
|
* lineCallback(...) is called for each line on the assumed fully buffered blob - including the final line.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
template <typename Callable>
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
AuROString AuSplitNewlines(const AuROString &in,
|
||||||
|
const Callable &lineCallback,
|
||||||
|
bool bReturnRemaining)
|
||||||
|
{
|
||||||
|
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 = line.RemoveSuffix(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lineCallback(line);
|
||||||
|
|
||||||
|
if (startIdx >= in.Size())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bReturnRemaining)
|
||||||
|
{
|
||||||
|
return in.Substr(startIdx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lineCallback(in.Substr(startIdx));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
bool AuTrySplitString(AuListOfHeap<AuROString> &ret,
|
||||||
|
const AuROString &in,
|
||||||
|
AuUInt16 uCharacters)
|
||||||
|
{
|
||||||
|
for (AuUInt i = 0u; i < in.Size(); )
|
||||||
|
{
|
||||||
|
AuUInt start, end, len;
|
||||||
|
|
||||||
|
start = i;
|
||||||
|
end = AuMin(AuUInt(in.size()), AuUInt(i + uCharacters));
|
||||||
|
if (end - 1)
|
||||||
|
{
|
||||||
|
auto uLastCodepointIndex = AuCodepointsFindPreviousValidByteOffsetFromByteOffset(in, end);
|
||||||
|
auto uLastByteOffset = AuCodepointsNextLength(in.Substr(uLastCodepointIndex));
|
||||||
|
end = uLastCodepointIndex + uLastByteOffset;
|
||||||
|
}
|
||||||
|
len = end - start;
|
||||||
|
i += len;
|
||||||
|
|
||||||
|
if (!AuTryInsert(ret, in.Substr(start, len)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
bool AuTrySplitString(AuList<AuROString> &ret,
|
||||||
|
const AuROString &in,
|
||||||
|
AuUInt16 uCharacters)
|
||||||
|
{
|
||||||
|
for (AuUInt i = 0u; i < in.Size(); )
|
||||||
|
{
|
||||||
|
AuUInt start, end, len;
|
||||||
|
|
||||||
|
start = i;
|
||||||
|
end = AuMin(AuUInt(in.size()), AuUInt(i + uCharacters));
|
||||||
|
if (end - 1)
|
||||||
|
{
|
||||||
|
auto uLastCodepointIndex = AuCodepointsFindPreviousValidByteOffsetFromByteOffset(in, end);
|
||||||
|
auto uLastByteOffset = AuCodepointsNextLength(in.Substr(uLastCodepointIndex));
|
||||||
|
end = uLastCodepointIndex + uLastByteOffset;
|
||||||
|
}
|
||||||
|
len = end - start;
|
||||||
|
i += len;
|
||||||
|
|
||||||
|
if (!AuTryInsert(ret, in.Substr(start, len)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
AuList<AuROString> AuSplitString(const AuROString &in,
|
||||||
|
AuUInt16 uCharacters)
|
||||||
|
{
|
||||||
|
AuList<AuROString> ret;
|
||||||
|
|
||||||
|
if (AuTrySplitString(ret, in, uCharacters))
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AU_THROW_CONST_STRING("Couldn't split string. OOM?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints while joining the components using the specified @param delimiter into a reserved string buffer
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
bool AuTrySplitStringWithDelimiter(AuString &ret,
|
||||||
|
const AuROString &in,
|
||||||
|
const AuROString &delimiter,
|
||||||
|
AuUInt16 uCharacters)
|
||||||
|
{
|
||||||
|
if (!AuTryReserve(ret, in.Size() + (in.Size() / uCharacters * delimiter.size())))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (AuUInt i = 0u; i < in.Size(); )
|
||||||
|
{
|
||||||
|
AuUInt start, end, len;
|
||||||
|
|
||||||
|
if (i != 0)
|
||||||
|
{
|
||||||
|
ret.insert(ret.size(), delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
|
start = i;
|
||||||
|
end = AuMin(AuUInt(in.Size()), AuUInt(i + uCharacters));
|
||||||
|
if (end - 1)
|
||||||
|
{
|
||||||
|
auto uLastCodepointIndex = AuCodepointsFindPreviousValidByteOffsetFromByteOffset(in, end);
|
||||||
|
auto uLastByteOffset = AuCodepointsNextLength(in.Substr(uLastCodepointIndex));
|
||||||
|
end = uLastCodepointIndex + uLastByteOffset;
|
||||||
|
}
|
||||||
|
len = end - start;
|
||||||
|
i += len;
|
||||||
|
|
||||||
|
ret.insert(ret.size(), in.Substr(start, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Splits @param in after @param uCharacters UTF8 codepoints while joining the components using the specified @param delimiter into a reserved string buffer
|
||||||
|
*/
|
||||||
|
AU_STATIC_OR_OPTIMIZE_SPACE
|
||||||
|
AuString AuSplitStringWithDelimiter(const AuROString &in,
|
||||||
|
const AuROString &delimiter,
|
||||||
|
AuUInt16 uCharacters)
|
||||||
|
{
|
||||||
|
AuString ret;
|
||||||
|
|
||||||
|
if (AuTrySplitStringWithDelimiter(ret, in, delimiter, uCharacters))
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AU_THROW_CONST_STRING("Couldn't split string. OOM?");
|
||||||
|
}
|
||||||
|
}
|
@ -178,6 +178,7 @@ namespace __audetail
|
|||||||
#include <auROXTL/auOptional.hpp>
|
#include <auROXTL/auOptional.hpp>
|
||||||
#include <auROXTL/auOptionalEx.hpp>
|
#include <auROXTL/auOptionalEx.hpp>
|
||||||
#include <auROXTL/Iterators/auUTF8Iterator.hpp>
|
#include <auROXTL/Iterators/auUTF8Iterator.hpp>
|
||||||
|
#include <auROXTL/Strings/auLinerParserAndSplitter.hpp>
|
||||||
|
|
||||||
namespace Aurora
|
namespace Aurora
|
||||||
{
|
{
|
||||||
|
@ -82,6 +82,8 @@ namespace __audetail
|
|||||||
#include <auROXTL/MemoryModel/auMemoryView.ipp>
|
#include <auROXTL/MemoryModel/auMemoryView.ipp>
|
||||||
#include <auROXTL/MemoryModel/auDummyHeap.ipp>
|
#include <auROXTL/MemoryModel/auDummyHeap.ipp>
|
||||||
|
|
||||||
|
#include <auROXTL/Strings/auLinerParserAndSplitter.ipp>
|
||||||
|
|
||||||
struct IAuNullDelegate
|
struct IAuNullDelegate
|
||||||
{
|
{
|
||||||
virtual void OnCall() = 0;
|
virtual void OnCall() = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user