nlib
nn::nlib::NativePathMapper Class Reference

The class for getting the native path string from the URI path notation that is not machine-dependent. More...

#include "nn/nlib/NativePathMapper.h"

Public Member Functions

errno_t AddMap (const char *native_prefix, const char *uri_prefix) noexcept
 Registers the prefix of the native path string and the prefix of the corresponding URI path string. More...
 
errno_t ResolvePath (size_t *count, char *native, size_t n, const char *uri_path) const noexcept
 Converts a URI path string into a native path string. More...
 
template<size_t N>
errno_t ResolvePath (size_t *count, char(&native)[N], const char *uri_path) const noexcept
 Returns ResolvePath(count, native, N, uri_path).
 
Basic Member Functions
 NativePathMapper () noexcept
 Instantiates the object.
 
 ~NativePathMapper () noexcept
 Destructor.
 

Detailed Description

The class for getting the native path string from the URI path notation that is not machine-dependent.

Description
The path strings passed to nlib functions should be formatted in the native format of the operating system that you are running. This simplifies use of nlib on a single platform but may cause issues when writing programs for multiple platforms. Use the NativePathMapper class to convert URIs to native path strings. This allows you to avoid having to write separate code for addressing path strings on each platform.

Definition at line 24 of file NativePathMapper.h.

Member Function Documentation

◆ AddMap()

nn::nlib::NativePathMapper::AddMap ( const char *  native_prefix,
const char *  uri_prefix 
)
noexcept

Registers the prefix of the native path string and the prefix of the corresponding URI path string.

Parameters
[in]native_prefixThe native path string prefix.
[in]uri_prefixThe path string prefix of the URI corresponding to nativePrefix.
Return values
0Success.
EINVALIndicates that nativePrefix or uriPrefix is NULL, an empty string, or an invalid UTF-8 string.
EINVALIndicates that uriPrefix is not a URI string.
EINVALIndicates that the URI scheme of uriPrefix is not nlibpath.
EINVALIndicates that uriPrefix is not an absolute path.
ENOMEMIndicates that internal memory allocation failed.
Description
The hostname, query, and fragment parts of uriPrefix are ignored.

◆ ResolvePath()

nn::nlib::NativePathMapper::ResolvePath ( size_t *  count,
char *  native,
size_t  n,
const char *  uri_path 
) const
noexcept

Converts a URI path string into a native path string.

Parameters
[out]countThe number of bytes in the written string (not including the terminating null character).
[out]nativeThe buffer to which the native path string is written.
[in]nThe size of the buffer.
[in]uri_pathA URI path string.
Return values
0Success.
EINVALIndicates that native is NULL and n is not 0.
EINVALIndicates that uriPath is NULL or an empty string or an invalid UTF-8 string.
EINVALIndicates that uriPrefix is not a URI string.
EINVALIndicates that the URI scheme of uriPath is not nlibpath.
ESRCHIndicates that the native path string corresponding to the URI is not registered.
ERANGEIndicates that the buffer for native is not large enough.
ENOMEMIndicates that internal memory allocation failed.
Description
The hostname, query, and fragment parts of uriPath are ignored. You can get the number of bytes in the path string after it has been converted by calling this function with native set to NULL and n set to 0.
Be careful about storing UTF-8 strings even with the Windows version.

The documentation for this class was generated from the following files: