41# include <gtest/gtest.h>
52using namespace testing;
67 vector<int> v = {1, 2, 3};
87 string s =
"\t abc \n";
93 string s =
"\t abc \n";
116 auto s =
to_str(1.0 / 3.0);
135 s.push_back(
static_cast<char>(0xFF));
192 string s =
"prefix_value";
223 auto v =
split(
"a,b,,c",
',');
327 const string text =
"one two three four five";
423 const string text =
"one two three four five";
435 const auto max_st = std::numeric_limits<size_t>::max();
439 const auto max_l = std::numeric_limits<long>::max();
440 const auto min_l = std::numeric_limits<long>::min();
448 const char *v = std::getenv(
"ALEPH_STRESS");
449 if (v ==
nullptr or *v ==
'\0')
453 const long m = std::strtol(v, &end, 10);
454 if (end == v
or *end !=
'\0')
468 std::uniform_int_distribution<int>
byte_dist(0, 255);
471 for (
size_t i = 0; i < len; ++i)
479 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
480 std::uniform_int_distribution<int> pick(0,
int(
sizeof(
alphabet) - 2));
483 for (
size_t i = 0; i < len; ++i)
490 std::mt19937
rng(12345);
494 for (
size_t pos = 0; pos <= s.size(); ++pos)
505 std::mt19937
rng(54321);
509 const size_t n = 1 + (
size_t(
iter) % std::min<size_t>(16, s.size()));
516 const size_t base = s.size() / n;
517 for (
size_t i = 0; i + 1 < n; ++i)
524 std::mt19937
rng(999);
525 static const string delims =
" _-";
530 for (
size_t i = 0; i <
tokens; ++i)
550 std::mt19937
rng(2024);
563 std::mt19937
rng(77);
564 std::uniform_int_distribution<int> dist(-100000, 100000);
568 const int a = dist(
rng);
569 const int b = dist(
rng);
570 const int c = dist(
rng);
573 const auto expected = ::std::to_string(a) +
", " + ::std::to_string(b) +
", " + ::std::to_string(c);
String manipulation utilities.
static string random_ascii_token(std::mt19937 &rng, size_t len)
static string random_string(std::mt19937 &rng, size_t len)
static int stress_multiplier()
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Type & nth(const size_t n)
Return the n-th item of container.
Main namespace for Aleph-w library functions.
std::string tolower(const char *str)
Convert a C std::string to lower-case.
bool is_prefix(const std::string &str, const std::string &prefix)
Check whether prefix is a prefix of str.
std::string remove_symbols(const std::string &str, const std::string &symbols)
Remove any character appearing in symbols.
std::string to_upper(const std::string &str)
Convert a std::string to upper-case (byte-wise).
DynList< std::string > split_text_into_lines(const std::string &text)
Split a text into lines by "\n".
std::string justify_line_except_first(const std::string &text, const size_t width, const size_t left_margin=0)
Justify all lines except the first one.
DynList< std::string > split_text_into_words(const std::string &text)
Split a text into whitespace-separated words.
Array< std::string > split_to_array(const std::string &s, const std::string &delim)
Split a std::string into an Aleph::Array<std::string>.
std::pair< std::string, std::string > split_pos(const std::string &str, const size_t pos)
Split a std::string at a fixed position.
std::string remove_prefix(std::string &str, const std::string &prefix)
Remove prefix from str if present.
std::string & trim_in_place(std::string &s)
Trim a std::string in-place (leading + trailing whitespace removed).
std::string align_text_to_left(const std::string &text, const size_t page_width, const size_t left_margin=0)
Align text to the left by wrapping lines at page_width.
bool contains(const std::string_view &str, const std::string_view &substr)
Check if substr appears inside str.
std::string to_Pascalcase(const std::string &str)
Convert an identifier-like std::string to PascalCase.
DynList< DynList< std::string > > format_string_csv(const DynList< DynList< std::string > > &mat)
Produce a CSV-like matrix (commas added to all but last element in each row).
bool is_long(const std::string &str)
Check whether a std::string fully parses as a long.
DynList< std::string > split_n(const std::string &str, const size_t n)
Split a std::string into n parts.
std::string to_name(const std::string &str)
Uppercase the first character of str and return the resulting copy.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
bool is_float(const std::string &str)
Check whether a std::string fully parses as a finite float.
bool is_size_t(const std::string &str)
Check whether a std::string fully parses as a non-negative size_t.
std::string trim(const std::string &s)
Return a trimmed copy of a std::string (leading + trailing whitespace removed).
DynList< std::string > split_camel_case(const char *const str)
Split a camelCase / PascalCase std::string into tokens.
void build_pars_list(std::string &unused)
Base case for build_pars_list(std::string&, ...).
std::string remove_spaces(const std::string &str)
Remove all whitespace characters from a std::string.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
std::string to_str(const double d)
Convert double to a std::string with maximum round-trip precision.
std::string justify_text(const std::string &text, const size_t width, const size_t left_margin=0)
Justify a text to a target width.
bool is_double(const std::string &str)
Check whether a std::string fully parses as a finite double.
DynList< std::string > split_to_list(const std::string &s, const std::string &delim)
Split a std::string into an Aleph::DynList<std::string>.
std::string shift_lines_to_left(const std::string &str, const size_t n)
Indent every line in a multi-line std::string by n spaces.
std::string concat(const Args &... args)
Concatenate multiple streamable arguments into a single std::string.
DynList< DynList< T > > complete_rows(DynList< DynList< T > > &m)
Pad all rows of a matrix to the maximum row length.
std::string align_text_to_left_except_first(const std::string &text, const size_t width, const size_t left_margin=0)
Align all lines except the first one.
std::string toupper(const char *str)
Convert a C std::string to upper-case.
std::ostream & join(const C &c, const std::string &sep, std::ostream &out)
Join elements of an Aleph-style container into a stream.
std::vector< std::string > & split(const std::string &s, const char delim, std::vector< std::string > &elems)
Split a std::string by a single delimiter character.
DynList< DynList< std::string > > format_string(const DynList< size_t > &lens, const DynList< DynList< std::string > > &mat)
std::string to_lower(const std::string &str)
Convert a std::string to lower-case (byte-wise).
void fill_string(std::string &str, char sym)
Fill all the content of std::string with a defined char.
std::string & mutable_tolower(std::string &str)
Convert a std::string to lower-case in-place.
std::string & mutable_toupper(std::string &str)
Convert a std::string to upper-case in-place.
DynList< T > maps(const C &c, Op op)
Classic map operation.
std::string only_alpha(const std::string &str)
Extract alphanumeric ASCII characters and normalize letters to lower-case.