Skip to content

Commit

Permalink
Fix typos in comments (#3272)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandesign committed Apr 17, 2024
1 parent 453c966 commit 46036e1
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions libmamba/include/mamba/fs/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

#include <fmt/format.h>

//---- RATIONAL: Why do we wrap standard filesystem here? ----
//---- RATIONALE: Why do we wrap standard filesystem here? ----
// 1. This codebase relies on `std::string` and `const char*` to denote UTF-8 encoded text.
// However `std::filesystem::path` constructors cannot assume that `std::string` is in
// another encoding than the default one for the platform. This leads runtime issues on some
// platforms (mostly Windows) where unicode paths either lead to exceptions being thrown
// by standard filesystem functions or invalid unicode characters replacing the paths content.
// platforms (mostly Windows) where Unicode paths either lead to exceptions being thrown
// by standard filesystem functions or invalid Unicode characters replacing the paths' content.
// To work around these issues we need to make sure `std::string` and other characters are
// assumed to be UTF-8 and paths are built with that knowledge (the internal storage is optimal
// for the platform so it is not a concern). In the same way we need paths to be convertible
// assumed to be UTF-8 and paths are built with that knowledge. (The internal storage is optimal
// for the platform so it is not a concern.) In the same way we need paths to be convertible
// to UTF-8 when converting them to string.
// To achieve this we wrap a `std::filesystem::path` into our type `fs::u8path` so that
// converions always happen correctly in it's conversion functions, like an encoding barrier.
// conversions always happen correctly in its conversion functions, like an encoding barrier.
//
// 2. Once using `fs::u8path`, we cannot use the standard library filesystem algorithms even with
// `fs::u8path` implicit conversions without risking ending up with `std::filesystem::path` in
Expand Down Expand Up @@ -51,19 +51,19 @@
// This kind of code seems valid but is silently broken. It is very easy to end up in this kind
// of situation which makes us consider this situation brittle. Therefore, the only way to
// prevent this kind of issue is to make sure every path value passed to and returned by
// filesystem functions is first converted to `fs::u8path`, thus giving use guarantees about
// filesystem functions is first converted to `fs::u8path`, thus giving us guarantees about
// encoding of our paths whatever the platform (as long as strings filtered to be UTF-8).
//
// 3. Previous versions of this header were using another library `ghc::filesystem` which is an
// implementation of the standard filesystem library but with a guarantee that
// `std::filesystem::path::string()` will always return UTF-8 encoding and that constructors
// taking strings will assume that they are UTF-8. Why did we prefer doing our own wrapping? The
// main reason we decided to wrap instead is that we want users of the library to be able to use
// the standard filesystem library in conjonction with this library. As `ghc::filesystem` is a
// the standard filesystem library in conjunction with this library. As `ghc::filesystem` is a
// re-implementation of `std::filesystem`, both cannot really be used together (or at least not
// without a lot of explicit conversions). With our present wrapping we are completely compatible
// with the standard library as we only add a thin encoding conversion layer over it's interface
// (at least until the stnadard library provide better options).
// with the standard library as we only add a thin encoding conversion layer over its interface
// (at least until the standard library provides better options).


namespace mamba::fs
Expand All @@ -76,10 +76,10 @@ namespace mamba::fs
// Maintain `\` on Windows, `/` on other platforms
std::filesystem::path normalized_separators(std::filesystem::path path);

// Returns an utf-8 string given a standard path.
// Returns a UTF-8 string given a standard path.
std::string to_utf8(const std::filesystem::path& path);

// Returns standard path given an utf-8 string.
// Returns standard path given a UTF-8 string.
std::filesystem::path from_utf8(std::string_view u8string);

// Same as std::filesystem::path except we only accept and output UTF-8 paths
Expand Down Expand Up @@ -300,7 +300,7 @@ namespace mamba::fs

//---- Conversions ----

// Returns an utf-8 string.
// Returns a UTF-8 string.
std::string string() const
{
return to_utf8(m_path);
Expand All @@ -312,25 +312,25 @@ namespace mamba::fs
return m_path.native();
}

// Returns an utf-8 string.
// Returns a UTF-8 string.
operator std::string() const
{
return this->string();
}

// Returns the native wstring (UTF-16 on windows).
// Returns the native wstring (UTF-16 on Windows).
std::wstring wstring() const
{
return m_path.wstring();
}

// Implicitly convert to native wstring (UTF-16 on windows).
// Implicitly convert to native wstring (UTF-16 on Windows).
operator std::wstring() const
{
return this->wstring();
}

// Returns an utf-8 string using the ``/`` on all systems.
// Returns a UTF-8 string using the ``/`` on all systems.
std::string generic_string() const
{
return to_utf8(m_path.generic_string());
Expand Down

0 comments on commit 46036e1

Please sign in to comment.