mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-15 06:37:17 +02:00
![John Ericson](/assets/img/avatar_default.png)
This ended up motivating a good deal of other infra improvements in order to get Windows right: - `OsString` to complement `std::filesystem::path` - env var code for working with the underlying `OsString`s - Rename `PATHNG_LITERAL` to `OS_STR` - `NativePathTrait` renamed to `OsPathTrait`, given a character template parameter until #9205 is complete. Split `tests.cc` matching split of `util.{cc,hh}` last year. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
43 lines
837 B
C++
43 lines
837 B
C++
#pragma once
|
|
///@file
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace nix {
|
|
|
|
/**
|
|
* Named because it is similar to the Rust type, except it is in the
|
|
* native encoding not WTF-8.
|
|
*
|
|
* Same as `std::filesystem::path::string_type`, but manually defined to
|
|
* avoid including a much more complex header.
|
|
*/
|
|
using OsString = std::basic_string<
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
wchar_t
|
|
#else
|
|
char
|
|
#endif
|
|
>;
|
|
|
|
/**
|
|
* `std::string_view` counterpart for `OsString`.
|
|
*/
|
|
using OsStringView = std::basic_string_view<OsString::value_type>;
|
|
|
|
std::string os_string_to_string(OsStringView path);
|
|
|
|
OsString string_to_os_string(std::string_view s);
|
|
|
|
/**
|
|
* Create string literals with the native character width of paths
|
|
*/
|
|
#ifndef _WIN32
|
|
# define OS_STR(s) s
|
|
#else
|
|
# define OS_STR(s) L##s
|
|
#endif
|
|
|
|
}
|