[f450f2f] | 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); |
---|
[4b3b352] | 43 | string & ?=?(string &s, string &other); // surprising ret seems to help avoid calls to autogen |
---|
| 44 | //string ?=?( string &, string ) = void; |
---|
[f450f2f] | 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 | |
---|
[08ed947] | 95 | int findFrom(const string &s, size_t fromPos, char search); |
---|
| 96 | int findFrom(const string &s, size_t fromPos, const string &search); |
---|
| 97 | int findFrom(const string &s, size_t fromPos, const char* search); |
---|
| 98 | int findFrom(const string &s, size_t fromPos, const char* search, size_t searchsize); |
---|
| 99 | |
---|
[f450f2f] | 100 | bool includes(const string &s, const string &search); |
---|
| 101 | bool includes(const string &s, const char* search); |
---|
| 102 | bool includes(const string &s, const char* search, size_t searchsize); |
---|
| 103 | |
---|
| 104 | bool startsWith(const string &s, const string &prefix); |
---|
| 105 | bool startsWith(const string &s, const char* prefix); |
---|
| 106 | bool startsWith(const string &s, const char* prefix, size_t prefixsize); |
---|
| 107 | |
---|
| 108 | bool endsWith(const string &s, const string &suffix); |
---|
| 109 | bool endsWith(const string &s, const char* suffix); |
---|
| 110 | bool endsWith(const string &s, const char* suffix, size_t suffixsize); |
---|
| 111 | |
---|
| 112 | // Modifiers |
---|
| 113 | void padStart(string &s, size_t n); |
---|
| 114 | void padStart(string &s, size_t n, char padding); |
---|
| 115 | void padEnd(string &s, size_t n); |
---|
| 116 | void padEnd(string &s, size_t n, char padding); |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | struct charclass { |
---|
| 121 | charclass_res * inner; |
---|
| 122 | }; |
---|
| 123 | |
---|
| 124 | void ?{}( charclass & ) = void; |
---|
| 125 | void ?{}( charclass &, charclass) = void; |
---|
| 126 | charclass ?=?( charclass &, charclass) = void; |
---|
| 127 | |
---|
| 128 | void ?{}( charclass &, const string & chars); |
---|
| 129 | void ?{}( charclass &, const char * chars ); |
---|
| 130 | void ?{}( charclass &, const char * chars, size_t charssize ); |
---|
| 131 | void ^?{}( charclass & ); |
---|
| 132 | |
---|
| 133 | int include(const string &s, const charclass &mask); |
---|
| 134 | |
---|
| 135 | int exclude(const string &s, const charclass &mask); |
---|
| 136 | |
---|
| 137 | /* |
---|
| 138 | What to do with? |
---|
| 139 | StrRet include(string &s, const charclass &mask); |
---|
| 140 | StrRet exclude(string &s, const charclass &mask); |
---|
| 141 | */ |
---|
| 142 | |
---|
| 143 | |
---|