Compare commits
6 Commits
69bd968f98
...
fbf49ba511
| Author | SHA1 | Date | |
|---|---|---|---|
| fbf49ba511 | |||
| 92f74b27d1 | |||
| 934f0c9232 | |||
| ee9a3e1152 | |||
| 16886cdf1c | |||
| 08b9508d83 |
2
deps/ox/src/ox/std/ignore.hpp
vendored
2
deps/ox/src/ox/std/ignore.hpp
vendored
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace std {
|
||||
|
||||
inline constexpr struct {
|
||||
inline constexpr struct ignore_t {
|
||||
constexpr void operator=(auto&&) const noexcept {}
|
||||
} ignore;
|
||||
|
||||
|
||||
18
deps/ox/src/ox/std/span.hpp
vendored
18
deps/ox/src/ox/std/span.hpp
vendored
@@ -163,6 +163,24 @@ class Span {
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Span operator++(int) noexcept {
|
||||
++m_items;
|
||||
--m_size;
|
||||
if (!m_size) [[unlikely]] {
|
||||
m_items = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Span operator++() noexcept {
|
||||
++m_items;
|
||||
--m_size;
|
||||
if (!m_size) [[unlikely]] {
|
||||
m_items = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto data() const noexcept {
|
||||
return m_items;
|
||||
|
||||
18
deps/ox/src/ox/std/string.hpp
vendored
18
deps/ox/src/ox/std/string.hpp
vendored
@@ -139,7 +139,7 @@ class BasicString {
|
||||
|
||||
constexpr BasicString &operator+=(Integer_c auto i) noexcept;
|
||||
|
||||
constexpr BasicString &operator+=(StringView src) noexcept;
|
||||
constexpr BasicString &operator+=(StringViewCR src) noexcept;
|
||||
|
||||
constexpr BasicString &operator+=(BasicString const&src) noexcept;
|
||||
|
||||
@@ -185,7 +185,7 @@ class BasicString {
|
||||
return {};
|
||||
}
|
||||
|
||||
constexpr Error append(ox::StringView sv) noexcept {
|
||||
constexpr Error append(StringViewCR sv) noexcept {
|
||||
return append(sv.data(), sv.size());
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(StringView s) noexcept {
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(StringViewCR s) noexcept {
|
||||
std::size_t strLen = s.bytes();
|
||||
std::ignore = append(s.data(), strLen);
|
||||
return *this;
|
||||
@@ -456,7 +456,7 @@ constexpr bool BasicString<SmallStringSize_v>::operator==(const char *other) con
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator==(OxString_c auto const&other) const noexcept {
|
||||
return ox::StringView(*this) == ox::StringView(other);
|
||||
return StringView(*this) == StringView(other);
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
@@ -548,28 +548,28 @@ using StringCR = String const&;
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::String toString(ox::StringViewCR sv) noexcept {
|
||||
constexpr String toString(StringViewCR sv) noexcept {
|
||||
return ox::String(sv);
|
||||
}
|
||||
|
||||
|
||||
template<typename PlatSpec, std::size_t SmallStringSize_v>
|
||||
[[nodiscard]]
|
||||
constexpr auto sizeOf(const ox::BasicString<SmallStringSize_v>*) noexcept {
|
||||
constexpr auto sizeOf(BasicString<SmallStringSize_v> const*) noexcept {
|
||||
VectorMemMap<PlatSpec> v{.smallVecSize = SmallStringSize_v};
|
||||
return sizeOf<PlatSpec>(&v);
|
||||
}
|
||||
|
||||
template<typename PlatSpec, std::size_t SmallStringSize_v>
|
||||
[[nodiscard]]
|
||||
constexpr auto alignOf(const ox::BasicString<SmallStringSize_v>&) noexcept {
|
||||
constexpr auto alignOf(BasicString<SmallStringSize_v> const&) noexcept {
|
||||
VectorMemMap<PlatSpec> v{.smallVecSize = SmallStringSize_v};
|
||||
return alignOf<PlatSpec>(&v);
|
||||
}
|
||||
|
||||
template<size_t sz>
|
||||
struct MaybeView<ox::BasicString<sz>> {
|
||||
using type = ox::StringView;
|
||||
struct MaybeView<BasicString<sz>> {
|
||||
using type = StringView;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
20
deps/ox/src/ox/std/strops.hpp
vendored
20
deps/ox/src/ox/std/strops.hpp
vendored
@@ -21,7 +21,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
namespace ox {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::StringView substr(ox::StringView const&str, std::size_t pos) noexcept {
|
||||
constexpr StringView substr(StringViewCR str, std::size_t const pos) noexcept {
|
||||
if (str.size() >= pos) {
|
||||
return {&str[pos], str.size() - pos};
|
||||
}
|
||||
@@ -29,13 +29,23 @@ constexpr ox::StringView substr(ox::StringView const&str, std::size_t pos) noexc
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::StringView substr(ox::StringView const&str, std::size_t start, std::size_t end) noexcept {
|
||||
constexpr StringView substr(StringViewCR str, std::size_t const start, std::size_t const end) noexcept {
|
||||
if (str.size() >= start && end >= start) {
|
||||
return {&str[start], end - start};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool beginsWith(StringViewCR base, char const beginning) noexcept {
|
||||
return base.size() && base[0] == beginning;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool endsWith(StringViewCR base, char const ending) noexcept {
|
||||
return base.size() && base[base.size() - 1] == ending;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool beginsWith(StringViewCR base, StringViewCR beginning) noexcept {
|
||||
const auto beginningLen = ox::min(beginning.size(), base.size());
|
||||
@@ -49,7 +59,7 @@ constexpr bool endsWith(StringViewCR base, StringViewCR ending) noexcept {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t find(StringViewCR str, char search) noexcept {
|
||||
constexpr std::size_t find(StringViewCR str, char const search) noexcept {
|
||||
std::size_t i = 0;
|
||||
for (; i < str.size(); ++i) {
|
||||
if (str[i] == search) {
|
||||
@@ -72,7 +82,7 @@ constexpr std::size_t find(StringViewCR str, StringViewCR search) noexcept {
|
||||
|
||||
template<std::size_t smallSz = 0>
|
||||
[[nodiscard]]
|
||||
constexpr ox::Vector<ox::StringView, smallSz> split(StringViewCR str, char del) noexcept {
|
||||
constexpr ox::Vector<ox::StringView, smallSz> split(StringViewCR str, char const del) noexcept {
|
||||
ox::Vector<ox::StringView, smallSz> out;
|
||||
constexpr auto nextSeg = [](StringViewCR current, char del) {
|
||||
return substr(current, find(current, del) + 1);
|
||||
@@ -105,7 +115,7 @@ constexpr ox::Vector<ox::StringView, smallSz> split(StringViewCR str, StringView
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<std::size_t> lastIndexOf(ox::StringViewCR str, int character) noexcept {
|
||||
constexpr ox::Result<std::size_t> lastIndexOf(ox::StringViewCR str, int const character) noexcept {
|
||||
ox::Result<std::size_t> retval = ox::Error(1, "Character not found");
|
||||
for (auto i = static_cast<int>(str.bytes() - 1); i >= 0; --i) {
|
||||
if (str[static_cast<std::size_t>(i)] == character) {
|
||||
|
||||
2
deps/ox/src/ox/std/vector.hpp
vendored
2
deps/ox/src/ox/std/vector.hpp
vendored
@@ -87,7 +87,9 @@ struct VectorAllocator {
|
||||
constexpr void deallocate(T *items, std::size_t cap) noexcept {
|
||||
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
|
||||
if (std::is_constant_evaluated()) {
|
||||
if (items) {
|
||||
Allocator{}.deallocate(items, cap);
|
||||
}
|
||||
} else {
|
||||
if (items && static_cast<void*>(items) != static_cast<void*>(m_data.data())) {
|
||||
Allocator{}.deallocate(items, cap);
|
||||
|
||||
@@ -19,6 +19,9 @@ else()
|
||||
endif()
|
||||
|
||||
add_subdirectory(applib)
|
||||
if(NOT APPLE)
|
||||
add_subdirectory(hull)
|
||||
endif()
|
||||
add_subdirectory(keel)
|
||||
add_subdirectory(turbine)
|
||||
if(${OLYMPIC_BUILD_STUDIO})
|
||||
|
||||
12
src/olympic/hull/CMakeLists.txt
Normal file
12
src/olympic/hull/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
add_library(Hull)
|
||||
target_sources(
|
||||
Hull PUBLIC
|
||||
FILE_SET CXX_MODULES FILES
|
||||
hull.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
Hull PUBLIC
|
||||
OxStd
|
||||
)
|
||||
98
src/olympic/hull/hull.cpp
Normal file
98
src/olympic/hull/hull.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
module;
|
||||
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
export module hull;
|
||||
|
||||
namespace hull {
|
||||
|
||||
export
|
||||
template<typename Str = ox::String, size_t SmallVecSz = 0>
|
||||
constexpr ox::Result<ox::Vector<Str, SmallVecSz>> parseCmd(ox::StringViewCR cmd) noexcept
|
||||
requires(ox::is_same_v<Str, ox::String> || ox::is_same_v<Str, ox::StringView>) {
|
||||
auto const tokens = split(cmd, ' ');
|
||||
ox::Vector<Str, SmallVecSz> args;
|
||||
char waitingFor{};
|
||||
auto const handleString = [&waitingFor, &args](
|
||||
ox::StringViewCR token,
|
||||
char const delimiter) {
|
||||
if (endsWith(token, delimiter)) {
|
||||
args.emplace_back(substr(token, 1, token.size() - 1));
|
||||
} else {
|
||||
waitingFor = delimiter;
|
||||
args.emplace_back(substr(token, 1));
|
||||
}
|
||||
};
|
||||
for (auto const &token : tokens) {
|
||||
if (waitingFor) {
|
||||
if (endsWith(token, waitingFor)) {
|
||||
waitingFor = 0;
|
||||
}
|
||||
auto &tgt = *args.back().value;
|
||||
if constexpr (ox::is_same_v<Str, ox::String>) {
|
||||
tgt += substr(token, 0, token.size() - 1);
|
||||
} else {
|
||||
tgt = {tgt.data(), tgt.size() + token.size() - 1};
|
||||
}
|
||||
} else if (beginsWith(token, '"')) {
|
||||
handleString(token, '"');
|
||||
} else if (beginsWith(token, '\'')) {
|
||||
handleString(token, '\'');
|
||||
} else {
|
||||
args.emplace_back(token);
|
||||
}
|
||||
}
|
||||
if (waitingFor) {
|
||||
return ox::Error{1, "unterminated string"};
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
template<typename Str = ox::String>
|
||||
[[nodiscard]]
|
||||
static constexpr bool testParse(ox::StringViewCR cmd, std::initializer_list<ox::StringView> const &expected) noexcept {
|
||||
auto const [args, err] = parseCmd<Str>(cmd);
|
||||
static constexpr auto equals = [](auto const &a, auto const &b) {
|
||||
if (a.size() != b.size()) {
|
||||
return false;
|
||||
}
|
||||
for (auto i = 0u; i < a.size(); ++i) {
|
||||
if (a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
return !err && equals(args, ox::Vector(expected));
|
||||
}
|
||||
|
||||
static_assert(testParse("echo asdf", {"echo", "asdf"}));
|
||||
static_assert(testParse<ox::String>("echo asdf", {"echo", "asdf"}));
|
||||
|
||||
static_assert(testParse("echo \"asdf\"", {"echo", "asdf"}));
|
||||
static_assert(testParse<ox::String>("echo \"asdf\"", {"echo", "asdf"}));
|
||||
|
||||
static_assert(testParse("echo 'asdf'", {"echo", "asdf"}));
|
||||
static_assert(testParse<ox::String>("echo 'asdf'", {"echo", "asdf"}));
|
||||
|
||||
static_assert(testParse("echo 'asdf' aoue", {"echo", "asdf", "aoue"}));
|
||||
static_assert(testParse<ox::String>("echo 'asdf' aoue", {"echo", "asdf", "aoue"}));
|
||||
|
||||
export class Prompt {
|
||||
|
||||
private:
|
||||
ox::String m_cmd;
|
||||
ox::String m_workingDir{"/"};
|
||||
ox::Vector<ox::String> m_prevCmds;
|
||||
|
||||
public:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user