Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-string-utils.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
31
37//
38// Created by lrleon on 23/04/24.
39//
40# include <gtest/gtest.h>
41
42# include <cmath>
43# include <cstdlib>
44# include <limits>
45# include <random>
46# include <sstream>
47# include <stdexcept>
48# include <vector>
49
50# include <ah-string-utils.H>
51
52using namespace std;
53using namespace testing;
54using namespace Aleph;
55
63static DynList<string> reference_split_string(const string & s, const string & delim)
64{
66 if (s.empty())
67 return ret;
68
69 if (delim.empty())
70 {
71 ret.append(s);
72 return ret;
73 }
74
75 string token;
76 for (char c : s)
77 if (delim.find(c) == string::npos)
78 token.push_back(c);
79 else if (not token.empty())
80 {
81 ret.append(token);
82 token.clear();
83 }
84
85 if (not token.empty())
86 ret.append(token);
87
88 return ret;
89}
90
101 const DynList<string> & got)
102{
103 ASSERT_EQ(got.size(), expected.size());
104 for (size_t i = 0; i < expected.size(); ++i)
105 EXPECT_EQ(got.nth(i), expected.nth(i));
106}
107
118 const Array<string> & got)
119{
120 ASSERT_EQ(got.size(), expected.size());
121 for (size_t i = 0; i < expected.size(); ++i)
122 EXPECT_EQ(got[i], expected.nth(i));
123}
124
126{
127 string s1 = "hello";
128 string s2 = "world";
129 string blank = " ";
130 string s3 = "!";
131 string s = concat(s1, blank, s2, s3);
132 ASSERT_EQ(s, "hello world!");
133}
134
136{
137 vector<int> v = {1, 2, 3};
138 EXPECT_EQ(Aleph::to_string(v), "1, 2, 3");
139 vector<int> e;
141}
142
144{
145 Array<int> a;
147 a.append(1);
149 a.append(2);
150 a.append(3);
151 EXPECT_EQ(Aleph::to_string(a), "1, 2, 3");
152}
153
155{
156 {
157 string s = "\t abc \n";
158 EXPECT_EQ(trim(s), "abc");
159 EXPECT_EQ(s, "\t abc \n");
160 }
161
162 {
163 string s = "\t abc \n";
164 EXPECT_EQ(trim_in_place(s), "abc");
165 EXPECT_EQ(s, "abc");
166 }
167
168 {
169 string s = "";
170 EXPECT_EQ(trim(s), "");
171 EXPECT_EQ(trim_in_place(s), "");
172 }
173}
174
176{
177 EXPECT_TRUE(contains("hello world", "world"));
178 EXPECT_FALSE(contains("hello", "xyz"));
179 EXPECT_TRUE(contains("", ""));
180}
181
183{
184 EXPECT_EQ(Aleph::to_string(1.5, 2), "1.50");
185 EXPECT_EQ(Aleph::to_string(1.0, 0), "1");
186 auto s = to_str(1.0 / 3.0);
187 EXPECT_FALSE(s.empty());
188}
189
191{
192 EXPECT_EQ(Aleph::tolower("HeLLo"), "hello");
193 EXPECT_EQ(Aleph::toupper("HeLLo"), "HELLO");
194
195 string s = "HeLLo";
196 EXPECT_EQ(mutable_tolower(s), "hello");
197 EXPECT_EQ(s, "hello");
198 EXPECT_EQ(mutable_toupper(s), "HELLO");
199 EXPECT_EQ(s, "HELLO");
200}
201
203{
204 string s;
205 s.push_back(static_cast<char>(0xFF));
206 s.push_back('A');
207 auto lower = Aleph::to_lower(s);
208 ASSERT_EQ(lower.size(), 2u);
209 EXPECT_EQ(lower[1], 'a');
210}
211
213{
214 EXPECT_EQ(only_alpha("A-bC_9"), "abc9");
215 EXPECT_EQ(remove_spaces(" a\tb\nc "), "abc");
216 EXPECT_EQ(remove_symbols("a-b_c", "-_"), "abc");
217 EXPECT_EQ(remove_symbols("", "-_"), "");
218}
219
221{
223 EXPECT_EQ(join(l, ","), "");
224 l.append(1);
225 l.append(2);
226 l.append(3);
227 EXPECT_EQ(join(l, ","), "1,2,3");
228 EXPECT_EQ(join(l, " - "), "1 - 2 - 3");
229}
230
232{
233 EXPECT_TRUE(is_long("0"));
234 EXPECT_TRUE(is_long("-10"));
236 EXPECT_FALSE(is_long("10x"));
237
239 EXPECT_TRUE(is_size_t("10"));
240 EXPECT_FALSE(is_size_t("-1"));
242 EXPECT_FALSE(is_size_t("10x"));
243
245 EXPECT_TRUE(is_double("-1.25"));
246 EXPECT_TRUE(is_double("1e3"));
248 EXPECT_FALSE(is_double("1.2x"));
249 EXPECT_FALSE(is_double("1e309"));
250
251 EXPECT_TRUE(is_float("0"));
252 EXPECT_TRUE(is_float("-1.25"));
254 EXPECT_FALSE(is_float("1.2x"));
255}
256
258{
259 EXPECT_TRUE(is_prefix("foobar", "foo"));
260 EXPECT_FALSE(is_prefix("foo", "foobar"));
261
262 string s = "prefix_value";
263 EXPECT_EQ(remove_prefix(s, "prefix_"), "value");
264 EXPECT_EQ(s, "value");
265}
266
268{
269 EXPECT_EQ(to_name(""), "");
270 EXPECT_EQ(to_name("hello"), "Hello");
271 EXPECT_EQ(to_name("Hello"), "Hello");
272}
273
275{
276 {
277 auto parts = split_camel_case("");
278 EXPECT_TRUE(parts.is_empty());
279 }
280
281 {
282 auto parts = split_camel_case("camelCaseString");
283 ASSERT_EQ(parts.size(), 3u);
284 EXPECT_EQ(parts.nth(0), "camel");
285 EXPECT_EQ(parts.nth(1), "Case");
286 EXPECT_EQ(parts.nth(2), "String");
287 }
288}
289
291{
292 {
293 auto v = split("a,b,,c", ',');
294 ASSERT_EQ(v.size(), 4u);
295 EXPECT_EQ(v[0], "a");
296 EXPECT_EQ(v[1], "b");
297 EXPECT_EQ(v[2], "");
298 EXPECT_EQ(v[3], "c");
299 }
300
301 {
302 auto l = split_to_list("a--b---c", "-");
303 ASSERT_EQ(l.size(), 3u);
304 EXPECT_EQ(l.nth(0), "a");
305 EXPECT_EQ(l.nth(1), "b");
306 EXPECT_EQ(l.nth(2), "c");
307 }
308
309 {
310 auto l = split_to_list("a b-c__d", " _-");
311 ASSERT_EQ(l.size(), 4u);
312 EXPECT_EQ(l.nth(0), "a");
313 EXPECT_EQ(l.nth(1), "b");
314 EXPECT_EQ(l.nth(2), "c");
315 EXPECT_EQ(l.nth(3), "d");
316 }
317
318 {
319 auto l = split_to_list("abc", "");
320 ASSERT_EQ(l.size(), 1u);
321 EXPECT_EQ(l.nth(0), "abc");
322 }
323}
324
326{
327 {
328 auto out = split_to_list("", ",");
329 EXPECT_TRUE(out.is_empty());
330 }
331
332 {
333 auto out = split_to_list(",,,,", ",");
334 EXPECT_TRUE(out.is_empty());
335 }
336
337 {
338 auto expected = reference_split_string(",a,,b,,,c,", ",");
339 auto list_out = split_to_list(",a,,b,,,c,", ",");
340 auto array_out = split_to_array(",a,,b,,,c,", ",");
343 }
344
345 {
346 auto expected = reference_split_string("alpha||beta,gamma;;;delta", "|,;");
347 auto list_out = split_to_list("alpha||beta,gamma;;;delta", "|,;");
348 auto array_out = split_to_array("alpha||beta,gamma;;;delta", "|,;");
351 }
352
353 {
354 auto expected = reference_split_string(" keep everything ", "");
355 auto list_out = split_to_list(" keep everything ", "");
356 auto array_out = split_to_array(" keep everything ", "");
359 }
360}
361
363{
364 EXPECT_EQ(to_Pascalcase("hello_world"), "HelloWorld");
365 EXPECT_EQ(to_Pascalcase("alreadyPascal"), "AlreadyPascal");
366}
367
369{
370 string s = "abcd";
371 EXPECT_EQ(split_pos(s, 0), (pair<string, string>("", "abcd")));
372 EXPECT_EQ(split_pos(s, 2), (pair<string, string>("ab", "cd")));
373 EXPECT_EQ(split_pos(s, 4), (pair<string, string>("abcd", "")));
374 EXPECT_THROW(split_pos(s, 5), range_error);
375}
376
378{
379 EXPECT_THROW(split_n("abc", 0), range_error);
380 EXPECT_THROW(split_n("abc", 4), range_error);
381
382 auto l = split_n("abcdef", 4);
383 ASSERT_EQ(l.size(), 4u);
384 EXPECT_EQ(l.nth(0), "a");
385 EXPECT_EQ(l.nth(1), "b");
386 EXPECT_EQ(l.nth(2), "c");
387 EXPECT_EQ(l.nth(3), "def");
388}
389
391{
393 DynList<int> r1; r1.append(1); r1.append(2);
394 DynList<int> r2; r2.append(3);
395 m.append(r1);
396 m.append(r2);
397
398 auto out = complete_rows(m);
399 ASSERT_EQ(out.size(), 2u);
400 ASSERT_EQ(out.nth(0).size(), 2u);
401 ASSERT_EQ(out.nth(1).size(), 2u);
402 EXPECT_EQ(out.nth(1).nth(0), 3);
403 EXPECT_EQ(out.nth(1).nth(1), 0);
404}
405
407{
409 DynList<string> r1; r1.append("abcd"); r1.append("x");
410 DynList<string> r2; r2.append("ab"); r2.append("xyz");
411 mat.append(r1);
412 mat.append(r2);
413
414 DynList<size_t> lens; lens.append(2); lens.append(1);
415 auto formatted = Aleph::format_string(lens, mat);
416 ASSERT_EQ(formatted.size(), 2u);
417 ASSERT_EQ(formatted.nth(0).size(), 2u);
418}
419
421{
423 DynList<string> r1; r1.append("a"); r1.append("b"); r1.append("c");
424 mat.append(r1);
425 auto csv = format_string_csv(mat);
426 ASSERT_EQ(csv.size(), 1u);
427 EXPECT_EQ(csv.nth(0).nth(0), "a,");
428 EXPECT_EQ(csv.nth(0).nth(1), "b,");
429 EXPECT_EQ(csv.nth(0).nth(2), "c");
430}
431
433{
434 const string text = "one two three four five";
435 auto j = justify_text(text, 10, 2);
436 EXPECT_TRUE(contains(j, " "));
437
438 auto a = align_text_to_left(text, 10, 1);
439 EXPECT_TRUE(contains(a, " one"));
440
441 auto shifted = shift_lines_to_left("a\nb", 3);
442 EXPECT_EQ(shifted, " a\n b");
443}
444
450
461
463{
464 string s = "secret";
465 fill_string(s, 'x');
466 EXPECT_EQ(s, "xxxxxx");
467
468 string e;
469 fill_string(e, 'x');
470 EXPECT_TRUE(e.empty());
471}
472
474{
475 auto a = split_to_array("a b-c__d", " _-");
476 ASSERT_EQ(a.size(), 4u);
477 EXPECT_EQ(a[0], "a");
478 EXPECT_EQ(a[1], "b");
479 EXPECT_EQ(a[2], "c");
480 EXPECT_EQ(a[3], "d");
481}
482
484{
486 DynList<string> r1; r1.append("abcd"); r1.append("x");
487 DynList<string> r2; r2.append("ab"); r2.append("xyz");
488 mat.append(r1);
489 mat.append(r2);
490
492 ASSERT_EQ(formatted.size(), 2u);
493 ASSERT_EQ(formatted.nth(0).size(), 2u);
494 ASSERT_EQ(formatted.nth(1).size(), 2u);
495}
496
498{
500 DynList<string> r1; r1.append("id"); r1.append("value");
501 DynList<string> r2; r2.append("7"); r2.append("abc");
502 DynList<string> r3; r3.append("42"); r3.append("x");
503 mat.append(r1);
504 mat.append(r2);
505 mat.append(r3);
506
507 auto by_max = Aleph::format_string(mat);
508 ASSERT_EQ(by_max.size(), 3u);
509 EXPECT_EQ(by_max.nth(0).nth(0), "id ");
510 EXPECT_EQ(by_max.nth(0).nth(1), "value ");
511 EXPECT_EQ(by_max.nth(1).nth(0), " 7 ");
512 EXPECT_EQ(by_max.nth(1).nth(1), " abc ");
513 EXPECT_EQ(by_max.nth(2).nth(0), "42 ");
514 EXPECT_EQ(by_max.nth(2).nth(1), " x ");
515
516 DynList<size_t> lens;
517 lens.append(3);
518 lens.append(6);
519 auto by_lens = Aleph::format_string(lens, mat);
520 ASSERT_EQ(by_lens.size(), 3u);
521 EXPECT_EQ(by_lens.nth(0).nth(0), " id ");
522 EXPECT_EQ(by_lens.nth(0).nth(1), " value ");
523 EXPECT_EQ(by_lens.nth(1).nth(0), " 7 ");
524 EXPECT_EQ(by_lens.nth(1).nth(1), " abc ");
525 EXPECT_EQ(by_lens.nth(2).nth(0), " 42 ");
526 EXPECT_EQ(by_lens.nth(2).nth(1), " x ");
527
528 std::ostringstream out;
529 Aleph::format_string(out, lens, mat);
530 EXPECT_EQ(out.str(), " id value \n 7 abc \n 42 x \n");
531}
532
534{
536 DynList<string> r1; r1.append("a"); r1.append("b");
537 DynList<string> r2; r2.append("c"); r2.append("d");
538 mat.append(r1);
539 mat.append(r2);
540 auto s = Aleph::to_string(mat);
541 EXPECT_TRUE(contains(s, "a"));
542 EXPECT_TRUE(contains(s, "d"));
543
545 lines.append("x");
546 lines.append("y");
548}
549
551{
552 const auto justified = justify_text("a bb c ddd e", 7, 2);
553 EXPECT_EQ(justified, " a bb c\n ddd e");
554
556 ASSERT_EQ(lines.size(), 2u);
557 EXPECT_EQ(lines.nth(0).size(), 9u); // width + margin
558 EXPECT_EQ(lines.nth(1), " ddd e");
559
560 EXPECT_EQ(justify_text("encyclopedia x", 5), "encyclopedia\nx");
561 EXPECT_EQ(justify_text(" one\t two\nthree ", 6), "one\ntwo\nthree");
562}
563
565{
567 EXPECT_TRUE(is_double("-1.25"));
568 EXPECT_TRUE(is_double("6.022e23"));
569 EXPECT_TRUE(is_double(" +3.5"));
570
572 EXPECT_FALSE(is_double("1.2x"));
573 EXPECT_FALSE(is_double("3.14 "));
574 EXPECT_FALSE(is_double("1e309"));
575 EXPECT_FALSE(is_double("1e-5000"));
576 EXPECT_FALSE(is_double("nan"));
577 EXPECT_FALSE(is_double("inf"));
578
579 EXPECT_DOUBLE_EQ(safe_atof("0"), 0.0);
580 EXPECT_NEAR(safe_atof("-1.25e2"), -125.0, 1e-12);
581 EXPECT_NEAR(safe_atof(" +3.5"), 3.5, 1e-12);
582
583 EXPECT_THROW(safe_atof(""), runtime_error);
584 EXPECT_THROW(safe_atof("abc"), runtime_error);
585 EXPECT_THROW(safe_atof("1.2x"), runtime_error);
586 EXPECT_THROW(safe_atof("3.5 "), runtime_error);
587 EXPECT_THROW(safe_atof("1e309"), runtime_error);
588 EXPECT_THROW(safe_atof("1e-5000"), runtime_error);
589 EXPECT_THROW(safe_atof("nan"), runtime_error);
590 EXPECT_THROW(safe_atof("inf"), runtime_error);
591}
592
594{
595 auto w = split_text_into_words(" a\t b\n c ");
596 ASSERT_EQ(w.size(), 3u);
597 EXPECT_EQ(w.nth(0), "a");
598 EXPECT_EQ(w.nth(1), "b");
599 EXPECT_EQ(w.nth(2), "c");
600
601 auto l = split_text_into_lines("a\nb\n");
602 ASSERT_EQ(l.size(), 2u);
603 EXPECT_EQ(l.nth(0), "a");
604 EXPECT_EQ(l.nth(1), "b");
605}
606
608{
609 const string text = "one two three four five";
610 auto j = justify_line_except_first(text, 10, 4);
611 EXPECT_TRUE(contains(j, "one"));
612 EXPECT_TRUE(contains(j, "\n"));
613
614 auto a = align_text_to_left_except_first(text, 10, 3);
615 EXPECT_TRUE(contains(a, "one"));
616 EXPECT_TRUE(contains(a, "\n"));
617}
618
620{
621 const auto max_st = std::numeric_limits<size_t>::max();
622 EXPECT_TRUE(is_size_t(::std::to_string(max_st)));
623 EXPECT_FALSE(is_size_t(::std::to_string(max_st) + "0"));
624
625 const auto max_l = std::numeric_limits<long>::max();
626 const auto min_l = std::numeric_limits<long>::min();
627 EXPECT_TRUE(is_long(::std::to_string(max_l)));
628 EXPECT_TRUE(is_long(::std::to_string(min_l)));
629 EXPECT_FALSE(is_long(::std::to_string(max_l) + "0"));
630}
631
633{
634 const char *v = std::getenv("ALEPH_STRESS");
635 if (v == nullptr or *v == '\0')
636 return 1;
637
638 char *end = nullptr;
639 const long m = std::strtol(v, &end, 10);
640 if (end == v or *end != '\0')
641 return 1;
642
643 if (m < 1)
644 return 1;
645
646 if (m > 50)
647 return 50;
648
649 return int(m);
650}
651
652static string random_string(std::mt19937 & rng, size_t len)
653{
654 std::uniform_int_distribution<int> byte_dist(0, 255);
655 string s;
656 s.reserve(len);
657 for (size_t i = 0; i < len; ++i)
658 s.push_back(static_cast<char>(byte_dist(rng)));
659 return s;
660}
661
662static string random_ascii_token(std::mt19937 & rng, size_t len)
663{
664 static constexpr char alphabet[] =
665 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
666 std::uniform_int_distribution<int> pick(0, int(sizeof(alphabet) - 2));
667 string s;
668 s.reserve(len);
669 for (size_t i = 0; i < len; ++i)
670 s.push_back(alphabet[pick(rng)]);
671 return s;
672}
673
675{
676 std::mt19937 rng(12345);
677 for (int iter = 0; iter < 2000*stress_multiplier(); ++iter)
678 {
679 const auto s = random_ascii_token(rng, size_t(iter % 64));
680 for (size_t pos = 0; pos <= s.size(); ++pos)
681 {
682 auto p = split_pos(s, pos);
683 EXPECT_EQ(p.first + p.second, s);
684 EXPECT_EQ(p.first.size(), pos);
685 }
686 }
687}
688
690{
691 std::mt19937 rng(54321);
692 for (int iter = 0; iter < 1500*stress_multiplier(); ++iter)
693 {
694 const auto s = random_ascii_token(rng, 1 + size_t(iter % 128));
695 const size_t n = 1 + (size_t(iter) % std::min<size_t>(16, s.size()));
696 auto parts = split_n(s, n);
697 ASSERT_EQ(parts.size(), n);
698 string recomposed;
699 parts.for_each([&](const string &x) { recomposed += x; });
701
702 const size_t base = s.size() / n;
703 for (size_t i = 0; i + 1 < n; ++i)
704 EXPECT_EQ(parts.nth(i).size(), base);
705 }
706}
707
709{
710 std::mt19937 rng(999);
711 static const string delims = " _-";
712 for (int iter = 0; iter < 2000*stress_multiplier(); ++iter)
713 {
714 string s;
715 const size_t tokens = 1 + (size_t(iter) % 12);
716 for (size_t i = 0; i < tokens; ++i)
717 {
718 if (i)
719 s.push_back(delims[size_t(iter + int(i)) % delims.size()]);
720 s += random_ascii_token(rng, 1 + (size_t(iter + int(i)) % 10));
721 }
722
723 auto out = split_to_list(s, delims);
724 ASSERT_FALSE(out.is_empty());
725 out.for_each([&](const string &t)
726 {
727 EXPECT_FALSE(t.empty());
728 for (char c : delims)
729 EXPECT_EQ(t.find(c), string::npos);
730 });
731 }
732}
733
735{
736 std::mt19937 rng(1337);
737 static const string delim_pool = " ,;|/_-\t\n";
738 static const string token_pool =
739 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
740
741 std::uniform_int_distribution<int> delim_size_dist(0, 4);
742 std::uniform_int_distribution<int> delim_pick(0, int(delim_pool.size() - 1));
743 std::uniform_int_distribution<int> token_pick(0, int(token_pool.size() - 1));
744 std::uniform_int_distribution<int> text_len_dist(0, 128);
745 std::bernoulli_distribution use_delim(0.30);
746
747 for (int iter = 0; iter < 2000*stress_multiplier(); ++iter)
748 {
749 string delims;
750 const int dsz = delim_size_dist(rng);
751 for (int i = 0; i < dsz; ++i)
752 delims.push_back(delim_pool[size_t(delim_pick(rng))]);
753
754 string text;
755 const int len = text_len_dist(rng);
756 text.reserve(size_t(len));
757 for (int i = 0; i < len; ++i)
758 if (not delims.empty() and use_delim(rng))
759 text.push_back(delims[size_t(delim_pick(rng)) % delims.size()]);
760 else
761 text.push_back(token_pool[size_t(token_pick(rng))]);
762
764 const auto list_out = split_to_list(text, delims);
765 const auto array_out = split_to_array(text, delims);
766
769 }
770}
771
773{
774 std::mt19937 rng(2024);
775 for (int iter = 0; iter < 3000*stress_multiplier(); ++iter)
776 {
777 auto s = random_string(rng, size_t(iter % 128));
778 auto lo = Aleph::to_lower(s);
779 auto up = Aleph::to_upper(s);
780 EXPECT_EQ(lo.size(), s.size());
781 EXPECT_EQ(up.size(), s.size());
782 }
783}
784
786{
787 std::mt19937 rng(77);
788 std::uniform_int_distribution<int> dist(-100000, 100000);
789
790 for (int iter = 0; iter < 2000*stress_multiplier(); ++iter)
791 {
792 const int a = dist(rng);
793 const int b = dist(rng);
794 const int c = dist(rng);
795
796 const auto got = ::Aleph::build_pars_list(a, b, c);
797 const auto expected = ::std::to_string(a) + ", " + ::std::to_string(b) + ", " + ::std::to_string(c);
799 }
800}
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 DynList< string > reference_split_string(const string &s, const string &delim)
Splits a string into non-empty tokens using a set of delimiter characters.
static void expect_tokens_eq(const DynList< string > &expected, const DynList< string > &got)
Asserts that two DynList<string> contain the same tokens in the same order.
static int stress_multiplier()
long double w
Definition btreepic.C:153
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:139
T & append(const T &data)
Append a copy of data
Definition tpl_array.H:245
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
T & append(const T &item)
Definition htlist.H:1271
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1065
Type & nth(const size_t n)
Return the n-th item of the container.
Definition ah-dry.H:299
Key * append(const Key &key)
Alias for insert() (copy version).
Definition hashDry.H:389
#define TEST(name)
static mt19937 rng
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
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.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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.
Definition ahPair.H:89
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.
Definition ah-date.H:140
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 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)
double safe_atof(const std::string &s)
Convert a std::string to double and throw on parse errors.
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.
std::string only_alpha(const std::string &str)
Extract alphanumeric ASCII characters and normalize letters to lower-case.
STL namespace.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
DynList< int > l