forked from basilTeam/basil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr.h
82 lines (72 loc) · 2.31 KB
/
str.h
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
/*
* Copyright (c) 2021, the Basil authors
* All rights reserved.
*
* This source code is licensed under the 3-Clause BSD License, the full text
* of which can be found in the LICENSE file in the root directory
* of this project.
*/
#ifndef BASIL_STRING_H
#define BASIL_STRING_H
#include "defs.h"
class string {
u8* data;
u32 _size, _capacity;
u8 buf[16];
void free();
void init(u32 size);
void copy(const u8* s);
void grow();
i32 cmp(const u8* s) const;
i32 cmp(const char* s) const;
public:
string();
~string();
string(const string& other);
string(string&& other);
string(const char* s);
string(const const_slice<u8>& range);
string(buffer& buf);
string& operator=(const string& other);
string& operator=(string&& other);
string& operator+=(u8 c);
string& operator+=(char c);
string& operator+=(const u8* s);
string& operator+=(const char* s);
string& operator+=(const string& s);
u32 size() const;
u32 capacity() const;
const u8& operator[](u32 i) const;
u8& operator[](u32 i);
const_slice<u8> operator[](pair<u32, u32> range) const;
slice<u8> operator[](pair<u32, u32> range);
bool endswith(u8 c) const;
const u8* raw() const;
bool operator==(const u8* s) const;
bool operator==(const char* s) const;
bool operator==(const string& s) const;
bool operator<(const u8* s) const;
bool operator<(const char* s) const;
bool operator<(const string& s) const;
bool operator>(const u8* s) const;
bool operator>(const char* s) const;
bool operator>(const string& s) const;
bool operator!=(const u8* s) const;
bool operator!=(const char* s) const;
bool operator!=(const string& s) const;
bool operator<=(const u8* s) const;
bool operator<=(const char* s) const;
bool operator<=(const string& s) const;
bool operator>=(const u8* s) const;
bool operator>=(const char* s) const;
bool operator>=(const string& s) const;
};
string operator+(string s, char c);
string operator+(string s, const char* cs);
string operator+(string s, const string& cs);
string escape(const string& s);
void write(stream& io, const string& s);
void read(stream& io, string& s);
void write(stream& io, const const_slice<u8>& str);
void write(stream& io, const slice<u8>& str);
#endif