pluto-src 0.1.1+0.10.4

Sources of Pluto (Lua 5.4 dialect) and logic to build it.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
#pragma once

#include <algorithm> // transform

#include <cmath> // fmod

#include <cstdint>
#include <cstring> // strlen

#include <filesystem>
#include <string>
#include <vector>

#include "base.hpp"
#include "Optional.hpp"

#undef min

NAMESPACE_SOUP
{
	class string
	{
		// from int

	private:
		template <typename Str, typename Int, uint8_t Base>
		[[nodiscard]] static Str fromIntImplAscii(Int _i)
		{
			if (_i == 0)
			{
				return Str(1, '0');
			}
			using UInt = std::make_unsigned_t<Int>;
			UInt i;
			bool neg = false;
			if constexpr (std::is_signed_v<Int>)
			{
				neg = (_i < 0);
				if (neg)
				{
					i = (_i * -1);
				}
				else
				{
					i = _i;
				}
			}
			else
			{
				i = _i;
			}
			Str res{};
			for (; i != 0; i /= Base)
			{
				const auto digit = (i % Base);
				res.insert(0, 1, static_cast<typename Str::value_type>('0' + digit));
			}
			if (neg)
			{
				res.insert(0, 1, '-');
			}
			return res;
		}

	public:
		template <typename Str = std::string, typename Int>
		[[nodiscard]] static Str decimal(Int i) // prefer std::to_string if possible as it's more optimsed
		{
			return fromIntImplAscii<Str, Int, 10>(i);
		}

		template <typename Float>
		[[nodiscard]] static std::string fdecimal(Float f) SOUP_EXCAL
		{
			if (std::fmod(f, 1) == 0)
			{
				std::string str = std::to_string((long long)f);
				str.append(".0");
				return str;
			}
			else
			{
				std::string str = std::to_string(f);
				while (str.back() == '0')
				{
					str.pop_back();
				}
				if (str.back() == '.')
				{
					str.push_back('0');
				}
				return str;
			}
		}

		template <typename Str = std::string, typename Int>
		[[nodiscard]] static Str binary(Int i)
		{
			return fromIntImplAscii<Str, Int, 2>(i);
		}

		template <typename Int>
		[[nodiscard]] static std::string hex(Int i)
		{
			return fromIntWithMap<std::string, Int, 16>(i, charset_hex);
		}

		template <typename Int>
		[[nodiscard]] static std::string hexLower(Int i)
		{
			return fromIntWithMap<std::string, Int, 16>(i, charset_hex_lower);
		}

		static constexpr const char* charset_hex = "0123456789ABCDEF";
		static constexpr const char* charset_hex_lower = "0123456789abcdef";

		template <typename Str, typename Int, uint8_t Base>
		[[nodiscard]] static Str fromIntWithMap(Int i, const typename Str::value_type* map)
		{
			if (i == 0)
			{
				return Str(1, map[0]);
			}
			const bool neg = (i < 0);
			if (neg)
			{
				i = i * -1;
			}
			Str res{};
			for (; i != 0; i /= Base)
			{
				const auto digit = (i % Base);
				res.insert(0, 1, map[digit]);
			}
			if (neg)
			{
				res.insert(0, 1, '-');
			}
			return res;
		}

		// char attributes

		template <typename T>
		[[nodiscard]] static constexpr bool isUppercaseLetter(const T c) noexcept
		{
			return c >= 'A' && c <= 'Z';
		}

		template <typename T>
		[[nodiscard]] static constexpr bool isLowercaseLetter(const T c) noexcept
		{
			return c >= 'a' && c <= 'z';
		}

		template <typename T>
		[[nodiscard]] static constexpr bool isLetter(const T c) noexcept
		{
			return isUppercaseLetter(c) || isLowercaseLetter(c);
		}

		template <typename T>
		[[nodiscard]] static constexpr bool isSpace(const T c) noexcept
		{
			return c == ' ' || c == '\t' || c == '\n' || c == '\r';
		}

		template <typename T>
		[[nodiscard]] static constexpr bool isNumberChar(const T c) noexcept
		{
			return c >= '0' && c <= '9';
		}

		template <typename T>
		[[nodiscard]] static constexpr bool isAlphaNum(const T c) noexcept
		{
			return isLetter(c) || isNumberChar(c);
		}

		template <typename T>
		[[nodiscard]] static constexpr bool isHexDigitChar(const T c) noexcept
		{
			return isNumberChar(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
		}

		template <typename T>
		[[nodiscard]] static constexpr bool isWordChar(const T c) noexcept
		{
			return isLetter(c) || isNumberChar(c) || c == '_';
		}

		// string attributes

		template <typename T>
		[[nodiscard]] static bool isNumeric(const T& str)
		{
			for (const auto& c : str)
			{
				if (!isNumberChar(c))
				{
					return false;
				}
			}
			return true;
		}

		template <typename T>
		[[nodiscard]] static bool containsWord(const T& haystack, const T& needle)
		{
			if (!needle.empty())
			{
				for (size_t i, off = 0; i = haystack.find(needle, off), i != T::npos; off = i + needle.size())
				{
					if ((i == 0 || !isLetter(haystack.at(i - 1)))
						&& (i + needle.size() == haystack.size() || !isLetter(haystack.at(i + needle.size())))
						)
					{
						return true;
					}
				}
			}
			return false;
		}

		template <typename T = std::string>
		[[nodiscard]] static bool equalsIgnoreCase(const T& a, const T& b)
		{
			if (a.size() != b.size())
			{
				return false;
			}
			for (size_t i = 0; i != a.size(); ++i)
			{
				if (std::tolower(a.at(i)) != std::tolower(b.at(i)))
				{
					return false;
				}
			}
			return true;
		}

		template <typename T = std::string>
		[[nodiscard]] static size_t levenshtein(const T& a, const T& b)
		{
			// Adapted from https://github.com/guilhermeagostinelli/levenshtein/blob/master/levenshtein.cpp & https://gist.github.com/TheRayTracer/2644387

			size_t n = a.size() + 1;
			size_t m = b.size() + 1;

			auto d = new size_t[n * m];

			//memset(d, 0, n * m * sizeof(size_t));
			for (size_t i = 0; i != n; ++i)
			{
				d[0 * n + i] = i;
			}
			for (size_t j = 0; j != m; ++j)
			{
				d[j * n + 0] = j;
			}

			for (size_t i = 1, im = 0; i < m; ++i, ++im)
			{
				for (size_t j = 1, jn = 0; j < n; ++j, ++jn)
				{
					size_t cost = (a[jn] == b[im]) ? 0 : 1;

					if (a[jn] == b[im])
					{
						d[(i * n) + j] = d[((i - 1) * n) + (j - 1)];
					}
					else
					{
						d[(i * n) + j] = std::min(
							std::min(d[(i - 1) * n + j], d[i * n + (j - 1)]) + 1,
							d[(i - 1) * n + (j - 1)] + cost
						);
					}
				}
			}

			const auto r = d[n * m - 1];

			delete[] d;

			return r;
		}

		// conversions

		[[nodiscard]] static std::string bin2hex(const std::string& str, bool spaces = false) SOUP_EXCAL
		{
			return bin2hexImpl(str.data(), str.size(), spaces, charset_hex);
		}

		[[nodiscard]] static std::string bin2hex(const char* data, size_t size, bool spaces = false) SOUP_EXCAL
		{
			return bin2hexImpl(data, size, spaces, charset_hex);
		}

		[[nodiscard]] static std::string bin2hexLower(const std::string& str, bool spaces = false) SOUP_EXCAL
		{
			return bin2hexImpl(str.data(), str.size(), spaces, charset_hex_lower);
		}

		[[nodiscard]] static std::string bin2hexLower(const char* data, size_t size, bool spaces = false) SOUP_EXCAL
		{
			return bin2hexImpl(data, size, spaces, charset_hex_lower);
		}

		[[nodiscard]] static std::string bin2hexImpl(const char* data, size_t size, bool spaces, const char* map) SOUP_EXCAL
		{
			std::string res{};
			res.reserve(size * (2 + spaces));
			for (; size; ++data, --size)
			{
				res.push_back(map[(unsigned char)(*data) >> 4]);
				res.push_back(map[(*data) & 0b1111]);
				if (spaces)
				{
					res.push_back(' ');
				}
			}
			if (spaces && !res.empty())
			{
				res.pop_back();
			}
			return res;
		}

		static void bin2hexAt(char* out, const char* data, size_t size, const char* map) noexcept
		{
			for (; size; ++data, --size)
			{
				*out++ = map[(unsigned char)(*data) >> 4];
				*out++ = map[(*data) & 0b1111];
			}
		}

		[[nodiscard]] static constexpr size_t bin2hexWithSpacesSize(size_t size) noexcept
		{
			return size != 0 ? (size * 3) - 1 : 0;
		}

		static void bin2hexWithSpaces(char* out, const char* data, size_t size, const char* map) noexcept
		{
			for (; size; ++data)
			{
				*out++ = map[(unsigned char)(*data) >> 4];
				*out++ = map[(*data) & 0b1111];
				if (--size)
				{
					*out++ = ' ';
				}
			}
		}

		[[nodiscard]] static std::string hex2bin(const std::string& hex) SOUP_EXCAL { return hex2bin(hex.data(), hex.size()); }
		[[nodiscard]] static std::string hex2bin(const char* data, size_t size) SOUP_EXCAL;

		enum ToIntFlags : uint8_t
		{
			TI_FULL = 1 << 0, // The entire string must be processed. If the string is too long or contains invalid characters, nullopt or fallback will be returned.
		};

		template <typename IntT, uint8_t Base = 10, typename CharT>
		[[nodiscard]] static Optional<IntT> toIntEx(const CharT* it, uint8_t flags = 0, const CharT** end = nullptr) noexcept
		{
			bool neg = false;
			if (*it == '\0')
			{
			_fail:
				if (end)
				{
					*end = it;
				}
				return std::nullopt;
			}
			switch (*it)
			{
			case '-':
				if constexpr (std::is_unsigned_v<IntT>)
				{
					goto _fail;
				}
				neg = true;
				[[fallthrough]];
			case '+':
				if (*++it == '\0')
				{
					goto _fail;
				}
			}
			IntT val = 0;
			{
				bool had_number_char = false;
				IntT max = 0;
				IntT prev_max = 0;
				while (true)
				{
					if constexpr (std::is_unsigned_v<IntT>)
					{
						max *= Base;
						max += (Base - 1);
						SOUP_IF_UNLIKELY (!(max > prev_max))
						{
							break;
						}
						prev_max = max;
					}

					const CharT c = *it;
					if (isNumberChar(c))
					{
						val *= Base;
						val += (c - '0');
					}
					else if (Base > 10 && c >= 'a' && c <= ('a' + Base - 11))
					{
						val *= Base;
						val += 0xA + (c - 'a');
					}
					else if (Base > 10 && c >= 'A' && c <= ('A' + Base - 11))
					{
						val *= Base;
						val += 0xA + (c - 'A');
					}
					else
					{
						break;
					}
					++it;
					had_number_char = true;

					if constexpr (std::is_signed_v<IntT>)
					{
						max *= Base;
						max += (Base - 1);
						SOUP_IF_UNLIKELY (max < prev_max)
						{
							break;
						}
						prev_max = max;
					}
				}
				if (!had_number_char)
				{
					goto _fail;
				}
			}
			if (flags & TI_FULL)
			{
				if (*it != '\0')
				{
					goto _fail;
				}
			}
			if constexpr (std::is_signed_v<IntT>)
			{
				if (neg)
				{
					val *= -1;
				}
			}
			if (end)
			{
				*end = it;
			}
			return Optional<IntT>(val);
		}

		template <typename IntT>
		[[nodiscard]] static Optional<IntT> toIntOpt(const std::string& str, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT>(str.c_str(), flags);
		}

		template <typename IntT>
		[[nodiscard]] static Optional<IntT> toIntOpt(const std::wstring& str, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT>(str.c_str(), flags);
		}

		template <typename IntT>
		[[nodiscard]] static IntT toInt(const char* str, IntT fallback, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT>(str, flags).value_or(fallback);
		}

		template <typename IntT>
		[[nodiscard]] static IntT toInt(const std::string& str, IntT fallback, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT>(str.c_str(), flags).value_or(fallback);
		}

		template <typename IntT>
		[[nodiscard]] static IntT toInt(const wchar_t* str, IntT fallback, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT>(str, flags).value_or(fallback);
		}

		template <typename IntT>
		[[nodiscard]] static IntT toInt(const std::wstring& str, IntT fallback, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT>(str.c_str(), flags).value_or(fallback);
		}

		template <typename IntT>
		[[nodiscard]] static Optional<IntT> hexToIntOpt(const char* str, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT, 0x10>(str, flags);
		}

		template <typename IntT>
		[[nodiscard]] static Optional<IntT> hexToIntOpt(const std::string& str, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT, 0x10>(str.c_str(), flags);
		}

		template <typename IntT>
		[[nodiscard]] static Optional<IntT> hexToIntOpt(const std::wstring& str, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT, 0x10>(str.c_str(), flags);
		}

		template <typename IntT>
		[[nodiscard]] static IntT hexToInt(const char* str, IntT fallback, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT, 0x10>(str, flags).value_or(fallback);
		}

		template <typename IntT>
		[[nodiscard]] static IntT hexToInt(const std::string& str, IntT fallback, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT, 0x10>(str.c_str(), flags).value_or(fallback);
		}

		template <typename IntT>
		[[nodiscard]] static IntT hexToInt(const wchar_t* str, IntT fallback, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT, 0x10>(str, flags).value_or(fallback);
		}

		template <typename IntT>
		[[nodiscard]] static IntT hexToInt(const std::wstring& str, IntT fallback, uint8_t flags = 0) noexcept
		{
			return toIntEx<IntT, 0x10>(str.c_str(), flags).value_or(fallback);
		}

		// string mutation

		template <class S>
		static void replaceAll(S& str, const S& from, const S& to) SOUP_EXCAL
		{
			size_t start_pos = 0;
			while ((start_pos = str.find(from, start_pos)) != S::npos)
			{
				str.replace(start_pos, from.length(), to);
				start_pos += to.length();
			}
		}

		static void replaceAll(std::string& str, const std::string& from, const std::string& to) SOUP_EXCAL
		{
			return replaceAll<std::string>(str, from, to);
		}

		static void replaceAll(std::wstring& str, const std::wstring& from, const std::wstring& to) SOUP_EXCAL
		{
			return replaceAll<std::wstring>(str, from, to);
		}

		template <class S>
		[[nodiscard]] static S replaceAll(const S& str, const S& from, const S& to) SOUP_EXCAL
		{
			S cpy(str);
			replaceAll(cpy, from, to);
			return cpy;
		}

		[[nodiscard]] static std::string replaceAll(const std::string& str, const std::string& from, const std::string& to) SOUP_EXCAL
		{
			return replaceAll<std::string>(str, from, to);
		}

		[[nodiscard]] static std::wstring replaceAll(const std::wstring& str, const std::wstring& from, const std::wstring& to) SOUP_EXCAL
		{
			return replaceAll<std::wstring>(str, from, to);
		}

		[[nodiscard]] static std::string escape(const std::string& str);

		template <typename S>
		static constexpr size_t len(S str) noexcept
		{
			if constexpr (std::is_same_v<S, char> || std::is_same_v<S, wchar_t>)
			{
				return 1;
			}
			else if constexpr (std::is_pointer_v<S>)
			{
				size_t len = 0;
				while (str[len] != 0)
				{
					++len;
				}
				return len;
			}
			else
			{
				return str.size();
			}
		}

		template <typename S, typename D>
		[[nodiscard]] static std::vector<S> explode(const S& str, D delim) SOUP_EXCAL
		{
			std::vector<S> res{};
			if (!str.empty())
			{
				res.reserve(5);
				size_t prev = 0;
				size_t del_pos;
				while ((del_pos = str.find(delim, prev)) != std::string::npos)
				{
					res.emplace_back(str.substr(prev, del_pos - prev));
					prev = del_pos + len(delim);
				}
				auto remain_len = (str.length() - prev);
				res.emplace_back(str.substr(prev, remain_len));
			}
			return res;
		}

		[[nodiscard]] static std::string join(const std::vector<std::string>& arr, const char glue);
		[[nodiscard]] static std::string join(const std::vector<std::string>& arr, const std::string& glue);

		template <typename S, typename C>
		static S lpad(S&& str, size_t desired_len, C pad_char)
		{
			lpad(str, desired_len, std::move(pad_char));
			return str;
		}

		template <typename S, typename C>
		static void lpad(S& str, size_t desired_len, C pad_char)
		{
			if (auto diff = desired_len - str.length(); diff > 0)
			{
				str.insert(0, diff, pad_char);
			}
		}

		template <typename S, typename C>
		static S rpad(S&& str, size_t desired_len, C pad_char)
		{
			rpad(str, desired_len, std::move(pad_char));
			return str;
		}

		template <typename S, typename C>
		static void rpad(S& str, size_t desired_len, C pad_char)
		{
			if (auto diff = desired_len - str.length(); diff > 0)
			{
				str.append(diff, pad_char);
			}
		}

		// example:
		// in str = "a b c"
		// target = " "
		// out str = "abc"
		template <typename T>
		static void erase(T& str, const T& target)
		{
			for (size_t i = 0; i = str.find(target, i), i != T::npos; )
			{
				str.erase(i, target.size());
			}
		}

		// example:
		// in str = "a b c"
		// target = " "
		// out str = "a"
		template <typename T>
		static void limit(T& str, const T& target)
		{
			if (size_t i = str.find(target); i != T::npos)
			{
				str.erase(i);
			}
		}

		// example:
		// in str = "a b c"
		// target = " "
		// out str = "a b"
		template <typename T>
		static void limitLast(T& str, const T& target)
		{
			if (size_t i = str.find_last_of(target); i != T::npos)
			{
				str.erase(0, i);
			}
		}

		static void listAppend(std::string& str, std::string&& add);

		template <typename T>
		static void trim(T& str)
		{
			ltrim(str);
			rtrim(str);
		}

		template <typename T>
		static void ltrim(T& str)
		{
			while (!str.empty())
			{
				auto i = str.begin();
				const char c = *i;
				if (!isSpace(c))
				{
					return;
				}
				str.erase(i);
			}
		}

		template <typename T>
		static void rtrim(T& str)
		{
			while (!str.empty())
			{
				auto i = (str.end() - 1);
				const char c = *i;
				if (!isSpace(c))
				{
					return;
				}
				str.erase(i);
			}
		}

		[[nodiscard]] static std::string _xor(const std::string& l, const std::string& r); // Did you know that "xor" was a C++ keyword?
		[[nodiscard]] static std::string xorSameLength(const std::string& l, const std::string& r);

#if SOUP_CPP20
		[[nodiscard]] static std::string fixType(std::u8string str) noexcept
		{
			std::string fixed = std::move(*reinterpret_cast<std::string*>(&str));
			return fixed;
		}

		[[nodiscard]] static std::u8string toUtf8Type(std::string str) noexcept
		{
			std::u8string u8 = std::move(*reinterpret_cast<std::u8string*>(&str));
			return u8;
		}
#else
		[[nodiscard]] static std::string fixType(std::string str) noexcept
		{
			return str;
		}
#endif

		template <typename T>
		static void truncateWithEllipsis(T& str, size_t max_len)
		{
			SOUP_DEBUG_ASSERT(max_len >= 3);
			if (str.size() > max_len)
			{
				str.resize(max_len);
				auto* data = str.data();
				data[max_len - 3] = '.';
				data[max_len - 2] = '.';
				data[max_len - 1] = '.';
			}
		}

		template <typename T>
		[[nodiscard]] static T truncateWithEllipsis(T&& str, size_t max_len)
		{
			truncateWithEllipsis(str, max_len);
			return str;
		}

		// char mutation

		template <typename Char>
		[[nodiscard]] static Char lower_char(Char c) noexcept
		{
			if (c >= 'A' && c <= 'Z')
			{
				return c - 'A' + 'a';
			}
			return c;
		}

		template <typename Str>
		static void lower(Str& str) noexcept
		{
			std::transform(str.begin(), str.end(), str.begin(), &lower_char<typename Str::value_type>);
		}

		template <typename Str>
		[[nodiscard]] static Str lower(Str&& str) noexcept
		{
			lower(str);
			return str;
		}

		template <typename Char>
		[[nodiscard]] static Char upper_char(Char c) noexcept
		{
			if (c >= 'a' && c <= 'z')
			{
				return c - 'a' + 'A';
			}
			return c;
		}

		template <typename Str>
		static void upper(Str& str) noexcept
		{
			std::transform(str.begin(), str.end(), str.begin(), &upper_char<typename Str::value_type>);
		}

		template <typename Str>
		[[nodiscard]] static Str upper(Str&& str) noexcept
		{
			upper(str);
			return str;
		}

		// "hello world" -> "Hello World"
		template <typename Str>
		static void title(Str& str)
		{
			bool first = true;
			for (auto& c : str)
			{
				if (first)
				{
					first = false;
					c = upper_char(c);
				}
				else
				{
					c = lower_char(c);
				}
				if (isSpace(c))
				{
					first = true;
				}
			}
		}

		template <typename Str>
		[[nodiscard]] static Str title(Str&& str)
		{
			title(str);
			return str;
		}

		[[nodiscard]] static constexpr char rot13(char c) noexcept
		{
			if (isUppercaseLetter(c))
			{
				char val = (c - 'A');
				val += 13;
				if (val >= 26)
				{
					val -= 26;
				}
				return (val + 'A');
			}
			if (isLowercaseLetter(c))
			{
				char val = (c - 'a');
				val += 13;
				if (val >= 26)
				{
					val -= 26;
				}
				return (val + 'a');
			}
			return c;
		}

		// file

		[[nodiscard]] static std::string fromFile(const char* file);
		[[nodiscard]] static std::string fromFile(const std::string& file);
		[[nodiscard]] static std::string fromFile(const std::filesystem::path& file);
		[[deprecated("Replace 'fromFilePath' with 'fromFile'")]] inline static std::string fromFilePath(const std::filesystem::path& file) { return fromFile(file); }
		static void toFile(const char* file, const std::string& contents);
		static void toFile(const std::string& file, const std::string& contents);
		static void toFile(const std::filesystem::path& file, const std::string& contents);
	};
}