summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-27 21:50:16 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-27 21:50:16 -0500
commitc3cf6df863828798ed8230b0f0966bcf3b2d08dd (patch)
treec03f94128e4892d503532f7fb886dcd86fafdf72 /source
parent7174a2741a6f7aa93c9d077dee384f8aa76d7a02 (diff)
Excise std::optional.
Diffstat (limited to 'source')
-rw-r--r--source/fud_assert.cpp1
-rw-r--r--source/fud_directory.cpp8
-rw-r--r--source/fud_string.cpp12
-rw-r--r--source/fud_utf8.cpp4
-rw-r--r--source/fud_utf8_iterator.cpp12
5 files changed, 19 insertions, 18 deletions
diff --git a/source/fud_assert.cpp b/source/fud_assert.cpp
index a7c9d76..e16f65e 100644
--- a/source/fud_assert.cpp
+++ b/source/fud_assert.cpp
@@ -22,6 +22,7 @@
#include "fud_string_view.hpp"
#include <cstdio>
+#include <exception>
namespace fud {
diff --git a/source/fud_directory.cpp b/source/fud_directory.cpp
index f46d530..1a1223c 100644
--- a/source/fud_directory.cpp
+++ b/source/fud_directory.cpp
@@ -152,9 +152,9 @@ Result<DirectoryEntry, FudStatus> Directory::info()
return retValue;
}
-Result<std::optional<DirectoryEntry>, FudStatus> Directory::getNextEntry()
+Result<Option<DirectoryEntry>, FudStatus> Directory::getNextEntry()
{
- using RetType = Result<std::optional<DirectoryEntry>, FudStatus>;
+ using RetType = Result<Option<DirectoryEntry>, FudStatus>;
errno = 0;
auto* dirEntry = readdir(m_directory);
@@ -163,7 +163,7 @@ Result<std::optional<DirectoryEntry>, FudStatus> Directory::getNextEntry()
m_errorCode = errno;
return RetType::error(FudStatus::Failure);
}
- return RetType::okay(std::nullopt);
+ return RetType::okay(NullOpt);
}
const char* entryNameCString = dirEntry->d_name;
@@ -190,7 +190,7 @@ Result<std::optional<DirectoryEntry>, FudStatus> Directory::getNextEntry()
if (retValue.isOkay()) {
m_errorCode = 0;
- return RetType::okay(retValue.takeOkay());
+ return RetType::okay(Option<DirectoryEntry>::take(retValue.takeOkay()));
}
return RetType::error(retValue.getError());
diff --git a/source/fud_string.cpp b/source/fud_string.cpp
index 3ba6603..caa35e9 100644
--- a/source/fud_string.cpp
+++ b/source/fud_string.cpp
@@ -276,10 +276,10 @@ FudStatus String::reserve(size_t newCapacity)
return resize(newCapacity);
}
-[[nodiscard]] std::optional<utf8> String::back()
+[[nodiscard]] Option<utf8> String::back()
{
if (!valid()) {
- return std::nullopt;
+ return NullOpt;
}
utf8 backChar = data()[m_length - 1];
@@ -287,17 +287,17 @@ FudStatus String::reserve(size_t newCapacity)
return backChar;
}
- return std::nullopt;
+ return NullOpt;
}
-std::optional<utf8> String::pop()
+Option<utf8> String::pop()
{
if (!valid()) {
- return std::nullopt;
+ return NullOpt;
}
if (m_length < 1) {
- return std::nullopt;
+ return NullOpt;
}
m_length--;
diff --git a/source/fud_utf8.cpp b/source/fud_utf8.cpp
index bffb5c1..bc12c15 100644
--- a/source/fud_utf8.cpp
+++ b/source/fud_utf8.cpp
@@ -90,11 +90,11 @@ namespace impl {
bool isAsciiPredicate(FudUtf8 character, bool (*predicate)(char))
{
auto maybeAscii = character.getAscii();
- if (!maybeAscii.has_value()) {
+ if (!maybeAscii.hasValue()) {
return false;
}
- auto asciiChar = *maybeAscii;
+ auto asciiChar = maybeAscii.value();
return predicate(asciiChar.asChar());
}
diff --git a/source/fud_utf8_iterator.cpp b/source/fud_utf8_iterator.cpp
index a815c64..00ce146 100644
--- a/source/fud_utf8_iterator.cpp
+++ b/source/fud_utf8_iterator.cpp
@@ -19,33 +19,33 @@
namespace fud {
-std::optional<FudUtf8> Utf8Iterator::peek() const
+Option<FudUtf8> Utf8Iterator::peek() const
{
if (m_index >= m_view.length()) {
- return std::nullopt;
+ return NullOpt;
}
auto character = FudUtf8::from(m_view, m_index);
if (!character.valid()) {
- return std::nullopt;
+ return NullOpt;
}
return character;
}
-std::optional<FudUtf8> Utf8Iterator::next()
+Option<FudUtf8> Utf8Iterator::next()
{
if (m_index >= m_view.length()) {
m_index = m_view.length();
- return std::nullopt;
+ return NullOpt;
}
auto character = FudUtf8::from(m_view, m_index);
if (!character.valid()) {
m_index = m_view.length();
- return std::nullopt;
+ return NullOpt;
}
m_index += character.size();