-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.cpp
More file actions
34 lines (27 loc) · 1009 Bytes
/
example.cpp
File metadata and controls
34 lines (27 loc) · 1009 Bytes
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
/*
* Copyright (c) 2023 Alex <uni@vrsal.xyz>
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "cppstr.hpp"
#include <iostream>
int main()
{
cppstr test = "Test123";
/* Basic usage like a normal std::string, access to the underlying std::string via test.str() */
std::cout << test.c_str() << "\n";
for (auto const& c : test) {
std::cout << c;
}
std::cout << "\n";
std::cout << "test = \"" << test.c_str() << "\"\n";
// Slices similar to python
std::cout << "test[0:4]: " << (test[SLICE(0:4)]).c_str() << "\n";
std::cout << "test[2:3]: " << (test[SLICE(2:3)]).c_str() << "\n";
std::cout << "test[0]: " << test[0] << "\n";
std::cout << "test[-3:]: " << (test[{-3, {}}]).c_str() << "\n";
std::cout << "test[-3:-1]: " << (test[SLICE(-3:-1)]).c_str() << "\n";
// Misc functions
std::cout << "Starts with 'Test' " << test.startswith("Test") << "\n";
std::cout << "Ends with '123' " << test.endswith("123") << "\n";
return 0;
}