flatten 20260225

This commit is contained in:
Timothy Prepscius
2026-02-25 12:39:24 -05:00
commit fa54be052a
315 changed files with 49791 additions and 0 deletions

75
tjp/core/internet/Data.hpp Executable file
View File

@@ -0,0 +1,75 @@
// TJP COPYRIGHT HEADER
#pragma once
#include <tjp/core/string/StringView.h>
#include <tjp/core/containers/Vector.h>
#include <tjp/core/containers/Optional.hpp>
namespace tjp::core::internet {
using DataBlock = Vector<char>;
using DataView = StringView;
struct Data {
mutable Optional<DataBlock> block;
mutable Optional<String> string;
Data()
{}
Data(DataBlock &&block_) :
block(std::move(block_))
{}
Data(String &&string_) :
string(std::move(string_))
{}
operator String &() const
{
if (!string.has_value())
{
if (block.has_value())
string = String(block->data(), block->size());
else
string = String();
}
return *string;
}
operator DataView () const
{
if (block.has_value())
return StringView(block->data(), block->size());
if (string.has_value())
return *string;
return {};
} ;
const char *data() const
{
DataView view = *this;
return view.data();
}
const char *c_str() const
{
String &view = *this;
return view.c_str();
}
const auto size() const
{
DataView view = *this;
return view.size();
}
};
} // namespace