106#include <tclap/CmdLine.h>
112using namespace Aleph;
120 cout <<
"\n" << string(60,
'=') <<
"\n";
121 cout <<
" " << title <<
"\n";
122 cout << string(60,
'=') <<
"\n\n";
127 cout <<
"\n--- " << title <<
" ---\n";
132 cout << label <<
": \"" << s <<
"\"" << endl;
143 string s1 =
" hello world ";
144 string s2 =
"\t\n whitespace everywhere \r\n";
175 string text =
"Hola Mundo desde COLOMBIA";
205 string csv =
"Bogota,Medellin,Cali,Barranquilla,Cartagena";
210 auto cities =
split(csv,
',');
211 cout <<
"Split by ',':" << endl;
212 for (
size_t i = 0; i < cities.size(); i++)
213 cout <<
" [" << i <<
"]: " << cities[i] << endl;
217 string path =
"/home/user/documents/file.txt";
218 auto parts =
split(path,
'/');
219 cout <<
"Path: \"" << path <<
"\"" << endl;
220 cout <<
"Split by '/':" << endl;
221 for (
const auto& p : parts)
222 cout <<
" \"" << p <<
"\"" << endl;
226 string text =
"Hello World";
228 cout <<
"Text: \"" << text <<
"\"" << endl;
229 cout <<
"Split at position 5:" << endl;
230 cout <<
" Left: \"" << left <<
"\"" << endl;
231 cout <<
" Right: \"" << right <<
"\"" << endl;
244 for (
auto it = words.
get_it(); it.has_curr(); it.next())
245 cout <<
"\"" << it.get_curr() <<
"\" ";
256 string result =
concat(
"Nombre: ",
"Juan",
", Edad: ", 25,
", Ciudad: ",
"Bogota");
270 vector<string> test_doubles = {
"3.14",
"-2.5",
"1e10",
"abc",
"12.3.4"};
271 for (
const auto& s : test_doubles)
272 cout <<
" is_double(\"" << s <<
"\"): " << (
is_double(s) ?
"yes" :
"no") << endl;
276 vector<string> test_longs = {
"42",
"-100",
"9999999",
"3.14",
"12abc"};
277 for (
const auto& s : test_longs)
278 cout <<
" is_long(\"" << s <<
"\"): " << (
is_long(s) ?
"yes" :
"no") << endl;
282 vector<string> test_sizes = {
"100",
"0",
"-5",
"abc"};
283 for (
const auto& s : test_sizes)
284 cout <<
" is_size_t(\"" << s <<
"\"): " << (
is_size_t(s) ?
"yes" :
"no") << endl;
288 string text =
"Hello from Colombia";
289 cout <<
"Text: \"" << text <<
"\"" << endl;
290 cout <<
" contains(\"Colombia\"): " << (
contains(text,
"Colombia") ?
"yes" :
"no") << endl;
291 cout <<
" contains(\"Venezuela\"): " << (
contains(text,
"Venezuela") ?
"yes" :
"no") << endl;
295 cout <<
" is_prefix(\"Hello world\", \"Hello\"): "
296 << (
is_prefix(
"Hello world",
"Hello") ?
"yes" :
"no") << endl;
297 cout <<
" is_prefix(\"Hello world\", \"World\"): "
298 << (
is_prefix(
"Hello world",
"World") ?
"yes" :
"no") << endl;
309 string dirty =
" Hello123 World!@# ";
322 string with_symbols =
"user@email.com";
328 string to_fill =
"***secret***";
342 string lorem =
"Este es un texto de ejemplo que sera formateado de diferentes maneras para demostrar las capacidades de formateo de texto de Aleph-w.";
344 cout <<
"Original text:" << endl;
345 cout <<
" " << lorem << endl;
350 cout <<
"Justified:" << endl;
351 auto lines =
split(justified,
'\n');
352 for (
const auto& line : lines)
353 cout <<
" |" << line <<
"|" << endl;
358 lines =
split(left_aligned,
'\n');
359 cout <<
"Left aligned:" << endl;
360 for (
const auto& line : lines)
361 cout <<
" |" << line <<
"|" << endl;
374 vector<int> nums = {1, 2, 3, 4, 5};
377 vector<double> prices = {19.99, 29.99, 39.99};
382 double pi = 3.14159265358979;
400 string csv_data = R
"(
401 Nombre, Ciudad, Edad, Salario
402 Juan Perez, Bogota, 35, 5000000
403 Maria Garcia, Medellin, 28, 4500000
404 Carlos Lopez, Cali, 42, 6000000
407 cout << "Raw CSV data:" << endl;
408 cout << csv_data << endl;
412 auto lines =
split(
trim(csv_data),
'\n');
414 bool is_header =
true;
415 vector<string> headers;
417 for (
const auto& raw_line : lines)
419 string line =
trim(raw_line);
420 if (line.empty())
continue;
422 auto fields =
split(line,
',');
426 cout <<
"Headers:" << endl;
427 for (
const auto& f : fields)
430 headers.push_back(
h);
431 cout <<
" - " <<
h << endl;
434 cout <<
"\nRecords:" << endl;
438 cout <<
" Record:" << endl;
439 for (
size_t i = 0; i < fields.size()
and i < headers.size(); i++)
442 cout <<
" " << headers[i] <<
": " <<
value << endl;
449 string salary =
"5000000";
450 cout <<
"Salary \"" << salary <<
"\" is valid number? "
451 << (
is_size_t(salary) ?
"yes" :
"no") << endl;
453 string invalid =
"abc123";
454 cout <<
"Salary \"" << invalid <<
"\" is valid number? "
455 << (
is_size_t(invalid) ?
"yes" :
"no") << endl;
462int main(
int argc,
char* argv[])
467 "String utilities example for Aleph-w.\n"
468 "Demonstrates trim, split, join, case conversion, and more.",
472 TCLAP::ValueArg<string> sectionArg(
474 "Run only specific section: trim, case, split, join, validate, "
475 "filter, format, convert, practical, or 'all'",
476 false,
"all",
"section",
cmd
479 cmd.parse(argc, argv);
481 string section = sectionArg.getValue();
484 cout <<
"============================================================\n";
485 cout <<
" ALEPH-W STRING UTILITIES EXAMPLE\n";
486 cout <<
"============================================================\n";
515 cout <<
"\n" << string(60,
'=') <<
"\n";
516 cout <<
"String utilities demo completed!\n";
517 cout << string(60,
'=') <<
"\n\n";
521 catch (TCLAP::ArgException& e)
523 cerr <<
"Error: " << e.error() <<
" for argument " << e.argId() << endl;
528 cerr <<
"Error: " << e.what() << endl;
String manipulation utilities.
size_t size_t int32_t value
Doubly-linked list (defined in tpl_dynList.H).
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Singly linked list implementations with head-tail access.
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::pair< std::string, std::string > split_pos(const std::string &str, const size_t pos)
Split a std::string at a fixed position.
void ltrim(std::string &s)
Remove leading whitespace from a std::string in-place.
std::string concat(const Args &...args)
Concatenate multiple arguments into a single std::string.
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.
bool is_long(const std::string &str)
Check whether a std::string fully parses as a long.
and
Check uniqueness with explicit hash + equality functors.
std::string to_name(const std::string &str)
Uppercase the first character of str and return the resulting copy.
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).
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 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.
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.
void rtrim(std::string &s)
Remove trailing whitespace from a std::string in-place.
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.
void fill_string(std::string &str, char sym)
Fill all the content of std::string with a defined char.
std::string only_alpha(const std::string &str)
Extract alphanumeric ASCII characters and normalize letters to lower-case.
static void section(const string &title)
void print_subsection(const string &title)
void print_section(const string &title)
void demo_case_conversion()
void show_string(const string &label, const string &s)