25 #ifndef JAU_STRING_UTIL_HPP_
26 #define JAU_STRING_UTIL_HPP_
32 #include <type_traits>
59 std::string
trimCopy(
const std::string &s) noexcept;
83 const bool lsbFirst,
const bool lowerCase=
true) noexcept;
92 std::
string&
byteHexString(std::
string& dest, const uint8_t value, const
bool lowerCase) noexcept;
101 template< class value_type,
102 std::enable_if_t<std::is_pointer_v<value_type>,
106 const uint64_t v2 =
reinterpret_cast<uint64_t
>(v);
107 return bytesHexString(pointer_cast<const uint8_t*>(&v2), 0,
sizeof(v),
false );
117 template<
class value_type,
118 std::enable_if_t<!std::is_pointer_v<value_type> &&
119 std::is_standard_layout_v<value_type>,
123 return bytesHexString(pointer_cast<const uint8_t*>(&v), 0,
sizeof(v),
false );
140 template<
class value_type,
141 std::enable_if_t< std::is_integral_v<value_type>,
144 const snsize_t v_sign = jau::sign<value_type>(v);
145 const nsize_t digit10_count1 = jau::digits10<value_type>(v, v_sign,
true );
146 const nsize_t digit10_count2 = v_sign < 0 ? digit10_count1 - 1 : digit10_count1;
148 const nsize_t comma_count = 0 == separator ? 0 : ( digit10_count1 - 1 ) / 3;
149 const nsize_t net_chars = digit10_count1 + comma_count;
150 const nsize_t total_chars = std::max<nsize_t>(width, net_chars);
151 std::string res(total_chars,
' ');
156 for(
nsize_t digit10_iter = 0; digit10_iter < digit10_count2 ; digit10_iter++ ) {
157 const int digit = v_sign < 0 ?
invert_sign( n % 10 ) : n % 10;
159 if( 0 < digit10_iter && 0 == digit10_iter % 3 ) {
160 res[total_chars-1-(char_iter++)] = separator;
162 res[total_chars-1-(char_iter++)] =
'0' + digit;
165 res[total_chars-1-(char_iter++)] =
'-';
176 template<
class value_type,
177 std::enable_if_t< std::is_integral_v<value_type> ||
178 std::is_floating_point_v<value_type>,
184 template<
class value_type,
185 std::enable_if_t<!std::is_integral_v<value_type> &&
186 !std::is_floating_point_v<value_type> &&
187 std::is_pointer_v<value_type>,
189 std::string
to_string(
const value_type & ref)
194 template<
class value_type,
195 std::enable_if_t<!std::is_integral_v<value_type> &&
196 !std::is_floating_point_v<value_type> &&
197 !std::is_pointer_v<value_type> &&
198 jau::has_toString_v<value_type>,
200 std::string
to_string(
const value_type & ref) {
201 return ref.toString();
204 template<
class value_type,
205 std::enable_if_t<!std::is_integral_v<value_type> &&
206 !std::is_floating_point_v<value_type> &&
207 !std::is_pointer_v<value_type> &&
208 !jau::has_toString_v<value_type> &&
209 jau::has_to_string_v<value_type>,
211 std::string
to_string(
const value_type & ref) {
212 return ref.to_string();
215 template<
class value_type,
216 std::enable_if_t<!std::is_integral_v<value_type> &&
217 !std::is_floating_point_v<value_type> &&
218 !std::is_pointer_v<value_type> &&
219 !jau::has_toString_v<value_type> &&
220 !jau::has_to_string_v<value_type> &&
221 jau::has_member_of_pointer_v<value_type>,
223 std::string
to_string(
const value_type & ref) {
227 template<
class value_type,
228 std::enable_if_t<!std::is_integral_v<value_type> &&
229 !std::is_floating_point_v<value_type> &&
230 !std::is_pointer_v<value_type> &&
231 !jau::has_toString_v<value_type> &&
232 !jau::has_to_string_v<value_type> &&
233 !jau::has_member_of_pointer_v<value_type>,
235 std::string
to_string(
const value_type & ref) {