libcppwrap
A collection of C++ wrappers for native APIs
Loading...
Searching...
No Matches
Namespaces | Functions
wx Namespace Reference

Namespaces

namespace  ipv6
 

Functions

std::string read_file_as_string (const char *path)
 Reads the contents of a file as a string. More...
 
std::string read_file_as_string (const std::string &path)
 Reads the contents of a file as a string. More...
 
std::string slurp (const char *path)
 Reads the contents of a file as a string with trailing whitespace removed. More...
 
std::string slurp (const std::string &path)
 Reads the contents of a file as a string with trailing whitespace removed. More...
 
std::string slurp (const std::filesystem::path &path)
 Reads the contents of a file as a string with trailing whitespace removed. More...
 
void spew (const char *path, std::string_view str)
 Writes a string to a file. More...
 
void spew (const std::string &path, std::string_view str)
 Writes a string to a file. More...
 
void spew (const std::filesystem::path &path, std::string_view str)
 Writes a string to a file. More...
 
template<typename T >
std::enable_if< std::is_integral_v< T > &&std::is_unsigned_v< T >, T >::type number (const char *str, int base=10)
 Parses a string as a numeric value with strict formatting and range checks. More...
 
template<typename T >
std::enable_if< std::is_integral_v< T > &&std::is_signed_v< T >, T >::type number (const char *str, int base=10)
 Parses a string as a numeric value with strict formatting and range checks. More...
 
template<typename T >
std::enable_if< std::is_floating_point_v< T >, T >::type number (const char *str)
 Parses a string as a numeric value with strict formatting and range checks. More...
 
template<typename T >
std::enable_if< std::is_integral_v< T >, T >::type number (const std::string &str, int base=10)
 Parses a string as a numeric value with strict formatting and range checks. More...
 
template<typename T >
std::enable_if< std::is_floating_point_v< T >, T >::type number (const std::string &str)
 Parses a string as a numeric value with strict formatting and range checks. More...
 
static std::stringrtrim (std::string &str) noexcept
 Removes trailing whitespace from a string in-place. More...
 

Function Documentation

◆ number() [1/5]

template<typename T >
std::enable_if< std::is_floating_point_v< T >, T >::type wx::number ( const char *  str)

Parses a string as a numeric value with strict formatting and range checks.

Template Parameters
TThe numeric type to convert to.
Parameters
strThe string to convert.
Returns
The parsed value.
Exceptions
std::range_errorThe string is valid but the number is out of range.
std::runtime_errorThe string is invalid.

◆ number() [2/5]

template<typename T >
std::enable_if< std::is_integral_v< T > &&std::is_unsigned_v< T >, T >::type wx::number ( const char *  str,
int  base = 10 
)

Parses a string as a numeric value with strict formatting and range checks.

Template Parameters
TThe numeric type to convert to.
Parameters
strThe string to convert.
baseThe numeric base.
Returns
The parsed value.
Exceptions
std::range_errorThe string is valid but the number is out of range.
std::runtime_errorThe string is invalid.

◆ number() [3/5]

template<typename T >
std::enable_if< std::is_integral_v< T > &&std::is_signed_v< T >, T >::type wx::number ( const char *  str,
int  base = 10 
)

Parses a string as a numeric value with strict formatting and range checks.

Template Parameters
TThe numeric type to convert to.
Parameters
strThe string to convert.
baseThe numeric base.
Returns
The parsed value.
Exceptions
std::range_errorThe string is valid but the number is out of range.
std::runtime_errorThe string is invalid.

◆ number() [4/5]

template<typename T >
std::enable_if< std::is_floating_point_v< T >, T >::type wx::number ( const std::string str)

Parses a string as a numeric value with strict formatting and range checks.

Template Parameters
TThe numeric type to convert to.
Parameters
strThe string to convert.
Returns
The parsed value.
Exceptions
std::range_errorThe string is valid but the number is out of range.
std::runtime_errorThe string is invalid.

◆ number() [5/5]

template<typename T >
std::enable_if< std::is_integral_v< T >, T >::type wx::number ( const std::string str,
int  base = 10 
)

Parses a string as a numeric value with strict formatting and range checks.

Template Parameters
TThe numeric type to convert to.
Parameters
strThe string to convert.
baseThe numeric base.
Returns
The parsed value.
Exceptions
std::range_errorThe string is valid but the number is out of range.
std::runtime_errorThe string is invalid.

◆ read_file_as_string() [1/2]

std::string wx::read_file_as_string ( const char *  path)

Reads the contents of a file as a string.

Remarks
This function attempts to minimize allocations and copies. It reads directly into a std::string buffer which is dynamically resized as needed. The size of the file need not be known in advance, so this function supports streamed files such as sysfs entries and pipes.
Parameters
pathThe path of the file to read.
Returns
The contents of the file as a string.
Exceptions
std::ios_base::failureThe file cannot be opened or a read error occurred.
See also
slurp()

◆ read_file_as_string() [2/2]

std::string wx::read_file_as_string ( const std::string path)
inline

Reads the contents of a file as a string.

Remarks
This function attempts to minimize allocations and copies. It reads directly into a std::string buffer which is dynamically resized as needed. The size of the file need not be known in advance, so this function supports streamed files such as sysfs entries and pipes.
Parameters
pathThe path of the file to read.
Returns
The contents of the file as a string.
Exceptions
std::ios_base::failureThe file cannot be opened or a read error occurred.
See also
slurp()

◆ rtrim()

static std::string & wx::rtrim ( std::string str)
inlinestaticnoexcept

Removes trailing whitespace from a string in-place.

Parameters
strThe string from which to remove trailing whitespace.
Returns
A reference to str.

◆ slurp() [1/3]

std::string wx::slurp ( const char *  path)

Reads the contents of a file as a string with trailing whitespace removed.

Parameters
pathThe path of the file to read.
Returns
The contents of the file as a string.
Exceptions
std::ios_base::failureThe file cannot be opened or a read error occurred.
See also
read_file_as_string()

◆ slurp() [2/3]

std::string wx::slurp ( const std::filesystem::path path)
inline

Reads the contents of a file as a string with trailing whitespace removed.

Parameters
pathThe path of the file to read.
Returns
The contents of the file as a string.
Exceptions
std::ios_base::failureThe file cannot be opened or a read error occurred.
See also
read_file_as_string()

◆ slurp() [3/3]

std::string wx::slurp ( const std::string path)
inline

Reads the contents of a file as a string with trailing whitespace removed.

Parameters
pathThe path of the file to read.
Returns
The contents of the file as a string.
Exceptions
std::ios_base::failureThe file cannot be opened or a read error occurred.
See also
read_file_as_string()

◆ spew() [1/3]

void wx::spew ( const char *  path,
std::string_view  str 
)

Writes a string to a file.

Parameters
pathThe path of the file to write.
strThe string to write.
Exceptions
std::ios_base::failureThe file cannot be opened or a write error occurred.

◆ spew() [2/3]

void wx::spew ( const std::filesystem::path path,
std::string_view  str 
)
inline

Writes a string to a file.

Parameters
pathThe path of the file to write.
strThe string to write.
Exceptions
std::ios_base::failureThe file cannot be opened or a write error occurred.

◆ spew() [3/3]

void wx::spew ( const std::string path,
std::string_view  str 
)
inline

Writes a string to a file.

Parameters
pathThe path of the file to write.
strThe string to write.
Exceptions
std::ios_base::failureThe file cannot be opened or a write error occurred.