source: libcfa/src/containers/string_res.hfa @ a3769cc

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since a3769cc was d8d512e, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

Reorganizing string constructor/assignment overload calls for better performance.

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[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_res -- variable-length, mutable run of text, with resource 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//######################### HandleNode #########################
22//private
23
24struct VbyteHeap;
25
26struct HandleNode {
27    HandleNode *flink;                                  // forward link
28    HandleNode *blink;                                  // backward link
29
30    char *s;                                            // pointer to byte string
31    unsigned int lnth;                                  // length of byte string
32}; // HandleNode
33
34void ?{}( HandleNode & );                       // constructor for header node
35
36void ?{}( HandleNode &, VbyteHeap & );          // constructor for nodes in the handle list
37void ^?{}( HandleNode & );                      // destructor for handle nodes
38
39
40//######################### String #########################
41
42// A dynamically-sized string
43struct string_res {
44    HandleNode Handle; // chars, start, end, global neighbours
45    string_res * shareEditSet_prev;
46    string_res * shareEditSet_next;
47};
48
49
50//######################### charclass_res #########################
51
52struct charclass_res {
53    string_res chars;
54};
55
56void ?{}( charclass_res & ) = void;
57void ?{}( charclass_res &, charclass_res) = void;
58charclass_res ?=?( charclass_res &, charclass_res) = void;
59void ?{}( charclass_res &, const string_res & chars);
60void ?{}( charclass_res &, const char * chars );
61void ?{}( charclass_res &, const char * chars, size_t charssize );
62void ^?{}( charclass_res & );
63
64
65//######################### String #########################
66
67// Getters
68size_t size(const string_res &s);
69
70// Constructors, Assignment Operators, Destructor
71void ?{}(string_res &s); // empty string
72void ?{}(string_res &s, const char* initial); // copy from string literal (NULL-terminated)
73void ?{}(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer
74
75void ?{}(string_res &s, const string_res & s2) = void;
76void ?{}(string_res &s, string_res & s2) = void;
77
78enum StrResInitMode { COPY_VALUE, SHARE_EDITS };
79void ?{}(string_res &s, const string_res & src, StrResInitMode, size_t start, size_t end );
80static inline void ?{}(string_res &s, const string_res & src, StrResInitMode mode ) {
81    ?{}( s, src, mode, 0, size(src));
82}
83
[d8d512e]84void assign(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer
85void ?=?(string_res &s, const char* other); // copy from string literal (NULL-terminated)
[f450f2f]86void ?=?(string_res &s, const string_res &other);
87void ?=?(string_res &s, string_res &other);
[d8d512e]88void ?=?(string_res &s, char other);
[f450f2f]89
90void ^?{}(string_res &s);
91
92// IO Operator
93ofstream & ?|?(ofstream &out, const string_res &s);
94void ?|?(ofstream &out, const string_res &s);
95
96// Concatenation
97void ?+=?(string_res &s, char other); // append a character
98void ?+=?(string_res &s, const string_res &s2); // append-concatenate to first string
[d8d512e]99void ?+=?(string_res &s, const char* other);
100void append(string_res &s, const char* buffer, size_t bsize);
[f450f2f]101
102// Character access
103char ?[?](const string_res &s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
104//char codePointAt(const string_res &s, size_t index); // revisit under Unicode
105
106// Comparisons
107bool ?==?(const string_res &s, const string_res &other);
108bool ?!=?(const string_res &s, const string_res &other);
109bool ?==?(const string_res &s, const char* other);
110bool ?!=?(const string_res &s, const char* other);
111
112// String search
113bool contains(const string_res &s, char ch); // single character
114
115int find(const string_res &s, char search);
116int find(const string_res &s, const string_res &search);
117int find(const string_res &s, const char* search);
118int find(const string_res &s, const char* search, size_t searchsize);
119
120bool includes(const string_res &s, const string_res &search);
121bool includes(const string_res &s, const char* search);
122bool includes(const string_res &s, const char* search, size_t searchsize);
123
124bool startsWith(const string_res &s, const string_res &prefix);
125bool startsWith(const string_res &s, const char* prefix);
126bool startsWith(const string_res &s, const char* prefix, size_t prefixsize);
127
128bool endsWith(const string_res &s, const string_res &suffix);
129bool endsWith(const string_res &s, const char* suffix);
130bool endsWith(const string_res &s, const char* suffix, size_t suffixsize);
131
132int include(const string_res &s, const charclass_res &mask);
133int exclude(const string_res &s, const charclass_res &mask);
134
135// Modifiers
136void padStart(string_res &s, size_t n);
137void padStart(string_res &s, size_t n, char padding);
138void padEnd(string_res &s, size_t n);
139void padEnd(string_res &s, size_t n, char padding);
140
Note: See TracBrowser for help on using the repository browser.