1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // string -- variable-length, mutable run of text, with value semantics |
---|
8 | // |
---|
9 | // Author : Michael L. Brooks |
---|
10 | // Created On : Fri Sep 03 11:00:00 2021 |
---|
11 | // Last Modified By : Michael L. Brooks |
---|
12 | // Last Modified On : Fri Sep 03 11:00:00 2021 |
---|
13 | // Update Count : 1 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <fstream.hfa> |
---|
19 | |
---|
20 | |
---|
21 | // in string_res.hfa |
---|
22 | struct string_res; |
---|
23 | struct charclass_res; |
---|
24 | |
---|
25 | struct string { |
---|
26 | string_res * inner; |
---|
27 | }; |
---|
28 | |
---|
29 | // Getters |
---|
30 | size_t size(const string &s); |
---|
31 | |
---|
32 | // RAII, assignment |
---|
33 | void ?{}( string & this ); // empty string |
---|
34 | void ?{}(string &s, const char* initial); // copy from string literal (NULL-terminated) |
---|
35 | void ?{}(string &s, const char* buffer, size_t bsize); // copy specific length from buffer |
---|
36 | |
---|
37 | void ?{}(string &s, const string & s2); |
---|
38 | void ?{}(string &s, string & s2); |
---|
39 | |
---|
40 | void ?=?(string &s, const char* other); // copy assignment from literal |
---|
41 | void ?=?(string &s, const string &other); |
---|
42 | void ?=?(string &s, char other); |
---|
43 | string & ?=?(string &s, string &other); // surprising ret seems to help avoid calls to autogen |
---|
44 | //string ?=?( string &, string ) = void; |
---|
45 | void ^?{}(string &s); |
---|
46 | |
---|
47 | // Alternate construction: request shared edits |
---|
48 | struct string_WithSharedEdits { |
---|
49 | string * s; |
---|
50 | }; |
---|
51 | string_WithSharedEdits ?`shareEdits( string & this ); |
---|
52 | void ?{}( string & this, string_WithSharedEdits src ); |
---|
53 | |
---|
54 | // IO Operator |
---|
55 | ofstream & ?|?(ofstream &out, const string &s); |
---|
56 | void ?|?(ofstream &out, const string &s); |
---|
57 | |
---|
58 | // Concatenation |
---|
59 | void ?+=?(string &s, char other); // append a character |
---|
60 | void ?+=?(string &s, const string &s2); // append-concatenate to first string |
---|
61 | void ?+=?(string &s, const char* other); // append-concatenate to first string |
---|
62 | string ?+?(const string &s, char other); // add a character to a copy of the string |
---|
63 | string ?+?(const string &s, const string &s2); // copy and concatenate both strings |
---|
64 | string ?+?(const char* s1, const char* s2); // concatenate both strings |
---|
65 | string ?+?(const string &s, const char* other); // copy and concatenate with NULL-terminated string |
---|
66 | |
---|
67 | // Repetition |
---|
68 | string ?*?(const string &s, size_t factor); |
---|
69 | string ?*?(char c, size_t size); |
---|
70 | string ?*?(const char *s, size_t size); |
---|
71 | |
---|
72 | // Character access |
---|
73 | char ?[?](const string &s, size_t index); |
---|
74 | string ?[?](string &s, size_t index); // mutable length-1 slice of original |
---|
75 | //char codePointAt(const string &s, size_t index); // to revisit under Unicode |
---|
76 | |
---|
77 | // Comparisons |
---|
78 | bool ?==?(const string &s, const string &other); |
---|
79 | bool ?!=?(const string &s, const string &other); |
---|
80 | bool ?==?(const string &s, const char* other); |
---|
81 | bool ?!=?(const string &s, const char* other); |
---|
82 | |
---|
83 | // Slicing |
---|
84 | string ?()( string & this, size_t start, size_t end ); // TODO const? |
---|
85 | string ?()( string & this, size_t start); |
---|
86 | |
---|
87 | // String search |
---|
88 | bool contains(const string &s, char ch); // single character |
---|
89 | |
---|
90 | int find(const string &s, char search); |
---|
91 | int find(const string &s, const string &search); |
---|
92 | int find(const string &s, const char* search); |
---|
93 | int find(const string &s, const char* search, size_t searchsize); |
---|
94 | |
---|
95 | bool includes(const string &s, const string &search); |
---|
96 | bool includes(const string &s, const char* search); |
---|
97 | bool includes(const string &s, const char* search, size_t searchsize); |
---|
98 | |
---|
99 | bool startsWith(const string &s, const string &prefix); |
---|
100 | bool startsWith(const string &s, const char* prefix); |
---|
101 | bool startsWith(const string &s, const char* prefix, size_t prefixsize); |
---|
102 | |
---|
103 | bool endsWith(const string &s, const string &suffix); |
---|
104 | bool endsWith(const string &s, const char* suffix); |
---|
105 | bool endsWith(const string &s, const char* suffix, size_t suffixsize); |
---|
106 | |
---|
107 | // Modifiers |
---|
108 | void padStart(string &s, size_t n); |
---|
109 | void padStart(string &s, size_t n, char padding); |
---|
110 | void padEnd(string &s, size_t n); |
---|
111 | void padEnd(string &s, size_t n, char padding); |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | struct charclass { |
---|
116 | charclass_res * inner; |
---|
117 | }; |
---|
118 | |
---|
119 | void ?{}( charclass & ) = void; |
---|
120 | void ?{}( charclass &, charclass) = void; |
---|
121 | charclass ?=?( charclass &, charclass) = void; |
---|
122 | |
---|
123 | void ?{}( charclass &, const string & chars); |
---|
124 | void ?{}( charclass &, const char * chars ); |
---|
125 | void ?{}( charclass &, const char * chars, size_t charssize ); |
---|
126 | void ^?{}( charclass & ); |
---|
127 | |
---|
128 | int include(const string &s, const charclass &mask); |
---|
129 | |
---|
130 | int exclude(const string &s, const charclass &mask); |
---|
131 | |
---|
132 | /* |
---|
133 | What to do with? |
---|
134 | StrRet include(string &s, const charclass &mask); |
---|
135 | StrRet exclude(string &s, const charclass &mask); |
---|
136 | */ |
---|
137 | |
---|
138 | |
---|