14 #ifndef THRILL_COMMON_STRING_HEADER 15 #define THRILL_COMMON_STRING_HEADER 34 template <
typename Type>
37 std::ostringstream oss;
47 template <
typename Type>
50 std::istringstream is(str);
59 T from_cstr(
const char* nptr,
char** endptr =
nullptr,
int base = 10);
68 return std::strtof(nptr, endptr);
75 return std::strtod(nptr, endptr);
82 return std::strtold(nptr, endptr);
92 return std::strtol(nptr, endptr, base);
98 const char* nptr,
char** endptr,
int base) {
99 return std::strtoul(nptr, endptr, base);
106 return std::strtoll(nptr, endptr, base);
112 const char* nptr,
char** endptr,
int base) {
113 return std::strtoull(nptr, endptr, base);
120 template <
typename T,
size_t N>
122 std::ostringstream oss;
124 for (
typename std::array<T, N>::const_iterator it = data.begin();
125 it != data.end(); ++it)
127 if (it != data.begin()) oss <<
',';
135 template <
typename T>
137 std::ostringstream oss;
139 for (
typename std::vector<T>::const_iterator it = data.begin();
140 it != data.end(); ++it)
142 if (it != data.begin()) oss <<
',';
160 template <
typename RandomEngine = std::default_random_engine>
164 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") {
168 std::uniform_int_distribution<size_t> distribution(0, letters.size() - 1);
170 for (
size_t i = 0; i < size; ++i)
171 out[i] = letters[distribution(rng)];
179 #endif // !THRILL_COMMON_STRING_HEADER
float from_cstr< float >(const char *nptr, char **endptr, int)
unsigned long long from_cstr< unsigned long long >(const char *nptr, char **endptr, int base)
long long from_cstr< long long >(const char *nptr, char **endptr, int base)
T from_cstr(const char *nptr, char **endptr=nullptr, int base=10)
Number parsing helpers, wraps strto{f,d,ld,l,ul,ll,ull}() via type switch.
long from_cstr< long >(const char *nptr, char **endptr, int base)
static std::string VecToStr(const std::array< T, N > &data)
Logging helper to print arrays as [a1,a2,a3,...].
double from_cstr< double >(const char *nptr, char **endptr, int)
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
unsigned long from_cstr< unsigned long >(const char *nptr, char **endptr, int base)
static std::string to_str(const Type &t)
static std::string RandomString(std::string::size_type size, RandomEngine rng, const std::string &letters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
Generate a random string of given length.
static bool from_str(const std::string &str, Type &outval)
Template transformation function which uses std::istringstream to parse any istreamable type from a s...
long double from_cstr< long double >(const char *nptr, char **endptr, int)