23 #ifndef GUL14_STRING_UTIL_H_
24 #define GUL14_STRING_UTIL_H_
46 template <
typename T,
typename =
int>
47 struct HasEmplaceBack : std::false_type { };
49 struct HasEmplaceBack<T, typename std::enable_if_t<true,
50 decltype(std::declval<T>().emplace_back(), 0)>> : std::true_type { };
54 template <
typename Container,
typename Element>
55 auto emplace_back(Container& c, Element e)
56 -> std::enable_if_t<HasEmplaceBack<Container>::value>
58 c.emplace_back(std::move(e));
61 template <
typename Container,
typename Element>
62 auto emplace_back(Container& c, Element e)
63 -> std::enable_if_t<!HasEmplaceBack<Container>::value>
65 c.emplace(std::move(e));
111 template <
typename Integer,
112 std::enable_if_t<std::is_integral<Integer>::value,
bool> =
true>
115 auto u =
static_cast<typename std::make_unsigned<Integer>::type
>(v);
118 for (
int idx =
static_cast<int>(
sizeof(Integer)) - 1; idx >= 0; --idx)
120 auto byte = u >> (8 * idx);
121 unsigned int upper_nibble = (
byte >> 4) & 0xf;
122 unsigned int lower_nibble =
byte & 0xf;
150 template <
typename Iterator>
154 const std::size_t n = std::distance(begin, end);
160 result.reserve(2 *
sizeof(*begin) * n + separator.size() * (n - 1));
164 for (
auto it = std::next(begin); it != end; ++it)
193 template <
typename Integer,
size_t num_elements,
194 std::enable_if_t<std::is_integral<Integer>::value,
bool> =
true>
198 return hex_string(std::begin(array), std::end(array), separator);
218 template <
typename Container,
219 std::enable_if_t<IsContainerLike<Container>::value,
bool> =
true>
223 return hex_string(std::cbegin(container), std::cend(container), separator);
264 std::string
safe_string(
const char* char_ptr, std::size_t length);
GUL_EXPORT const string_view default_whitespace_characters
The default characters that are treated as whitespace by GUL.
Definition: string_util.cc:29
GUL_EXPORT const std::array< char, 16 > hex_digits
The 16 digits for hexadecimal numbers ("0123456789abcdef").
Definition: string_util.cc:30
GUL_EXPORT std::string repeat(gul14::string_view str, std::size_t n)
Repeat a string N times.
Definition: string_util.cc:33
std::string hex_string(Integer v)
Return the hexadecimal ASCII representation of an integer value.
Definition: string_util.h:113
GUL_EXPORT std::string safe_string(const char *char_ptr, std::size_t length)
Safely construct a std::string from a char pointer and a length.
Definition: string_util.cc:44
basic_string_view< char > string_view
A view to a contiguous sequence of chars.
Definition: string_view.h:624
Definition of macros used internally by GUL.
Namespace gul14 contains all functions and classes of the General Utility Library.
Definition: doxygen.h:26
Provides a gul14::string_view that is fully compatible with C++17's std::string_view.
Some metaprogramming traits for the General Utility Library.