From c53fd30cc2df55b1c45262af8bbbfccbc2476a16 Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 1 Mar 2023 00:30:37 +0000 Subject: [PATCH] Change coral::path::joined to return coral::expected --- source/coral/files.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/coral/files.cpp b/source/coral/files.cpp index 967456b..09f746e 100755 --- a/source/coral/files.cpp +++ b/source/coral/files.cpp @@ -7,6 +7,15 @@ export namespace coral { * Platform-generalized identifier for a resource in a [fs]. */ struct path { + /** + * Errors that may occur during a path joining operation. + * + * [join_error::overflow] signals that the given path join exceeds the maximum valid length of a path. + */ + enum class join_error { + overflow, + }; + /** * Maximum path length. */ @@ -83,14 +92,11 @@ export namespace coral { } /** - * Returns a new [path] composed of the current path joined with `text`. - * - * *Note:* should the new path exceed [max] bytes in size, an empty [path] is returned instead. - * - * *Note:* should the new path exceed [max] bytes in size, an empty [path] is returned instead. + * Attempts to create a new path composed from the current path joined with `text`, returning it or a + * [join_error] if it failed. */ - constexpr path joined(slice const & text) const { - if (text.length > this->buffer[max]) return path{}; + constexpr expected joined(slice const & text) const { + if (text.length > this->buffer[max]) return join_error::overflow; path joined_path = *this;