9std::string
trim(
const std::string& str) {
10 const std::string_view whitespace =
" \t\n\r\f\v";
11 size_t first = str.find_first_not_of(whitespace);
12 if (std::string::npos == first) {
15 size_t last = str.find_last_not_of(whitespace);
16 return str.substr(first, last - first + 1);
50 for (
int i = 0; i < 50000; i++) {
52 std::string a = std::string(
"Hello, ") +
"world!";
53 std::cout <<
"string validation passed: operator+" << std::endl;
55 if (!a.starts_with(
"Hello")) {
56 std::cout <<
"string valiation failed: startswith 'Hello'" << std::endl;
59 std::cout <<
"string valiation passed: startswith 'Hello'" << std::endl;
61 if (!a.ends_with(
"!")) {
62 std::cout <<
"string valiation failed: endswith '!'" << std::endl;
65 std::cout <<
"string valiation passed: endswith '!'" << std::endl;
67 if (a.substr(0, 5) !=
"Hello") {
68 std::cout <<
"string valiation failed: substring(0, 5) == 'Hello'" << std::endl;
71 std::cout <<
"string valiation passed: substring(0, 5) == 'Hello'" << std::endl;
73 if (a.find(
"llo") != 2) {
74 std::cout <<
"string valiation failed: find('llo') == 2" << std::endl;
77 std::cout <<
"string valiation passed: find('llo') == 2" << std::endl;
78 std::cout << a << std::endl;
80 std::string b =
trim(
" May all the beauty be blessed. ");
81 if (b !=
"May all the beauty be blessed.") {
82 std::cout <<
"string valiation failed: trim()" << std::endl;
85 std::cout << b << std::endl;
87 std::string c =
"K423 & Raiden Mei & K423";
90 std::cout <<
"string valiation failed: find_all('Raiden') == 1 && find_all('K423') == 2" << std::endl;
93 std::cout <<
"string valiation passed: find_all('Raiden') == 1 && find_all('K423') == 2" << std::endl;
97 if (c !=
"Kiana Kaslana & Raiden Mei & Kiana Kaslana") {
98 std::cout <<
"string valiation failed: replace('K423', 'Kiana Kaslana')" << std::endl;
101 std::cout << c << std::endl;
102 std::cout <<
"string valiation passed: replace('K423', 'Kiana Kaslana')" << std::endl;
104 std::string d = std::to_string(-123);
106 std::cout <<
"string valiation failed: to_string()" << std::endl;
109 std::cout << d << std::endl;
110 std::cout <<
"string valiation passed: to_string()" << std::endl;
115 std::string f = std::format(
116 "{}: RESPOND ME! {}!\n{}: {} {}, {}, {}~",
117 "Raiden Mei",
"ELYSIA",
"Elysia",
"Can you hear me?", 1, 2, 3);
119 const std::string expected_format_output =
"Raiden Mei: RESPOND ME! ELYSIA!\nElysia: Can you hear me? 1, 2, 3~";
120 if (f != expected_format_output) {
121 std::cout << f << std::endl;
122 std::cout <<
"string valiation failed: format()" << std::endl;
125 std::cout << f << std::endl;
126 std::cout <<
"string valiation passed: format()" << std::endl;
128 std::cout <<
"string valiation passed: all tests passed" << std::endl;