diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-04-13 00:04:42 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-04-13 00:04:48 +0200 |
commit | 00143afc01dbca797471181105738042e89f15ae (patch) | |
tree | d2b3fa92ed5d17ae5a145758bed637f996cbd501 | |
parent | 8db26a7350aad53ed73a127f9b8eb6ef15bf0be1 (diff) |
Use string view everywhere
-rw-r--r-- | deimos/core/base.h | 5 | ||||
-rw-r--r-- | deimos/core/format.cpp | 2 | ||||
-rw-r--r-- | deimos/core/format.h | 11 | ||||
-rw-r--r-- | deimos/core/log.cpp | 3 | ||||
-rw-r--r-- | deimos/core/log.h | 3 |
5 files changed, 10 insertions, 14 deletions
diff --git a/deimos/core/base.h b/deimos/core/base.h index 1022ae8..1e9b4a9 100644 --- a/deimos/core/base.h +++ b/deimos/core/base.h @@ -128,6 +128,11 @@ public: constexpr int64_t size() const { return m_size; }
};
+inline Span<const std::byte> AsBytes(StringView span)
+{
+ return { reinterpret_cast<const std::byte*>(span.data()), span.size() };
+}
+
deimos_StaticAssert(std::is_trivially_destructible_v<StringView>);
deimos_StaticAssert(std::is_trivially_copyable_v<StringView>);
diff --git a/deimos/core/format.cpp b/deimos/core/format.cpp index b9a0ca3..af0a851 100644 --- a/deimos/core/format.cpp +++ b/deimos/core/format.cpp @@ -19,7 +19,7 @@ public: m_writer->Write(AsBytes(Span<char>(&c, 1)));
}
- void PushString(Span<const char> str)
+ void PushString(StringView str)
{
m_writer->Write(AsBytes(str));
}
diff --git a/deimos/core/format.h b/deimos/core/format.h index be2e4bf..3424dc2 100644 --- a/deimos/core/format.h +++ b/deimos/core/format.h @@ -22,9 +22,7 @@ struct FormatArg {
int64_t integer;
uint64_t unsigned_integer;
-
- // @Todo Use string views
- Span<const char> string;
+ StringView string;
};
explicit FormatArg(std::signed_integral auto value) :
@@ -37,15 +35,10 @@ struct FormatArg unsigned_integer{value}
{}
- explicit FormatArg(Span<const char> value) :
+ explicit FormatArg(StringView value) :
type{kString},
string{value}
{}
-
- explicit FormatArg(gsl::czstring value) :
- type{kString},
- string{value, (int64_t)__builtin_strlen(value)}
- {}
};
template<typename T>
diff --git a/deimos/core/log.cpp b/deimos/core/log.cpp index 3ba4fbc..e05c360 100644 --- a/deimos/core/log.cpp +++ b/deimos/core/log.cpp @@ -35,8 +35,7 @@ public: m_writer(os_console_api, OsConsoleType::kStdOut)
{}
- // @Todo Use string views
- void Log(LogSeverity severity, const SourceLocation& location, Span<const char> msg) override
+ void Log(LogSeverity severity, const SourceLocation& location, StringView msg) override
{
Format(&m_writer, "$[ $ ] $:$: $\033[0m\n", SeverityToColor(severity),
SeverityToStr(severity), location.file, location.line, msg);
diff --git a/deimos/core/log.h b/deimos/core/log.h index 323d246..9bb4dbb 100644 --- a/deimos/core/log.h +++ b/deimos/core/log.h @@ -21,8 +21,7 @@ public: deimos_NO_COPY_MOVE(ILogger);
virtual ~ILogger() = default;
- // @Todo Use string view
- virtual void Log(LogSeverity, const SourceLocation&, Span<const char>) = 0;
+ virtual void Log(LogSeverity, const SourceLocation&, StringView) = 0;
};
// Just a helper to pass a SourceLocation without having to write {} to logging functions.
|