gz-cpp-util 1.3
A c++20 library containing various utilities
|
Contains utilities for type conversions to and from string. More...
#include "to_string.hpp"
#include "from_string.hpp"
#include <string>
#include <bitset>
#include <sstream>
#include <iomanip>
Go to the source code of this file.
Concepts | |
concept | gz::StringConvertible |
gz::toString and gz::fromString overloads exist | |
Functions | |
Functions that determine if s is a string representation of a certain type, using regex. | |
bool | gz::isInt (const std::string &s) |
bool | gz::isInt (const std::string_view &s) |
bool | gz::isUInt (const std::string &s) |
bool | gz::isUInt (const std::string_view &s) |
bool | gz::isFloat (const std::string &s) |
bool | gz::isFloat (const std::string_view &s) |
Convert to type or return fallback | |
| |
int | gz::getIntOr (const std::string &s, int fallback) noexcept |
int | gz::getIntOr (const std::string_view &s, int fallback=0) noexcept |
unsigned int | gz::getUnsignedIntOr (const std::string &s, unsigned int fallback) noexcept |
unsigned int | gz::getUnsignedIntOr (const std::string_view &s, unsigned int fallback=0) noexcept |
double | gz::getDoubleOr (const std::string &s, double fallback) noexcept |
double | gz::getDoubleOr (const std::string_view &s, double fallback=0) noexcept |
float | gz::getFloatOr (const std::string &s, float fallback) noexcept |
float | gz::getFloatOr (const std::string_view &s, float fallback=0) noexcept |
bool | gz::getBoolOr (const std::string &s, bool fallback) noexcept |
bool | gz::getBoolOr (const std::string_view &s, bool fallback=false) noexcept |
std::string | gz::getStringOr (const std::string &s, const std::string &fallback="none") noexcept |
Returns the string or fallback if string is empty. | |
Converting an integer to/from a hex/oct/bin string | |
| |
template<std::integral T> | |
std::string | gz::toHexString (const T &t, char digits=sizeof(T) *2) |
Convert an integer to hexdecimal string (prefixed with 0x) More... | |
template<std::integral T> | |
T | gz::fromHexString (const std::string &s) |
Convert a hexadecimal string (may be prefixed with 0x) to integer. | |
template<std::integral T> | |
std::string | gz::toOctString (const T &t, char digits=sizeof(T) *4) |
Convert an integer to octal string (prefixed with 0) More... | |
template<std::integral T> | |
T | gz::fromOctString (const std::string &s) |
Convert an octal string (may be prefixed with 0) to integer. | |
template<std::integral T> | |
std::string | gz::toBinString (const T &t) |
Convert an integer to binary string (prefixed with 0b) More... | |
template<std::integral T> | |
T | gz::fromBinString (const std::string &s) |
Convert binary string (may be prefixed with 0b) to integer. | |
template<util::IntegralForwardRange T> | |
std::string | gz::toHexString (const T &t) |
Construct a string where the elements from a forward range are in hexadecimal format. More... | |
template<util::IntegralForwardRange T> | |
std::string | gz::toOctString (const T &t) |
Construct a string where the elements from a forward range are in octal format. More... | |
Contains utilities for type conversions to and from string.
std::string gz::toBinString | ( | const T & | t | ) |
Convert an integer to binary string (prefixed with 0b)
Construct a string where the elements from a forward range are in octal format.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string gz::toHexString | ( | const T & | t | ) |
Construct a string where the elements from a forward range are in hexadecimal format.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string gz::toHexString | ( | const T & | t, |
char | digits = sizeof(T)*2 |
||
) |
Convert an integer to hexdecimal string (prefixed with 0x)
digits | Minimum number of digits. Defaults to the amount of digits required to represent the largest possible number of type T. If digits is smaller than the needed amount to represent t, the needed amount is used. |
std::string gz::toOctString | ( | const T & | t | ) |
Construct a string where the elements from a forward range are in octal format.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string gz::toOctString | ( | const T & | t, |
char | digits = sizeof(T)*4 |
||
) |
Convert an integer to octal string (prefixed with 0)
digits | Minimum number of digits. Defaults to the amount of digits required to represent the largest possible number of type T. If digits is smaller than the needed amount to represent t, the needed amount is used. |