source: libcfa/src/containers/string_res.hfa @ 0f781fb8

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 0f781fb8 was 0f781fb8, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

Refactoring of string internals. Existing tests pass.

Adding tracking for multiple string heaps, or "scratchpads."
Cases of allocating across different pad contexts aren't implemented yet.
Adding basic controls to manage these contexts, which lead to expected assertion failures
at unimplemented cases.

  • Property mode set to 100644
File size: 4.9 KB
Line 
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    VbyteHeap *ulink;                   // upward link
30
31    char *s;                                            // pointer to byte string
32    unsigned int lnth;                                  // length of byte string
33}; // HandleNode
34
35VbyteHeap * DEBUG_string_heap();
36size_t DEBUG_string_bytes_avail_until_gc( VbyteHeap * heap );
37const char * DEBUG_string_heap_start( VbyteHeap * heap );
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
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)
86void ?=?(string_res &s, const string_res &other);
87void ?=?(string_res &s, string_res &other);
88void ?=?(string_res &s, char other);
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
99void ?+=?(string_res &s, const char* other);
100void append(string_res &s, const char* buffer, size_t bsize);
101
102// Character access
103void assignAt(const string_res &s, size_t index, char val);
104char ?[?](const string_res &s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
105//char codePointAt(const string_res &s, size_t index); // revisit under Unicode
106
107// Comparisons
108bool ?==?(const string_res &s, const string_res &other);
109bool ?!=?(const string_res &s, const string_res &other);
110bool ?==?(const string_res &s, const char* other);
111bool ?!=?(const string_res &s, const char* other);
112
113// String search
114bool contains(const string_res &s, char ch); // single character
115
116int find(const string_res &s, char search);
117int find(const string_res &s, const string_res &search);
118int find(const string_res &s, const char* search);
119int find(const string_res &s, const char* search, size_t searchsize);
120
121bool includes(const string_res &s, const string_res &search);
122bool includes(const string_res &s, const char* search);
123bool includes(const string_res &s, const char* search, size_t searchsize);
124
125bool startsWith(const string_res &s, const string_res &prefix);
126bool startsWith(const string_res &s, const char* prefix);
127bool startsWith(const string_res &s, const char* prefix, size_t prefixsize);
128
129bool endsWith(const string_res &s, const string_res &suffix);
130bool endsWith(const string_res &s, const char* suffix);
131bool endsWith(const string_res &s, const char* suffix, size_t suffixsize);
132
133int include(const string_res &s, const charclass_res &mask);
134int exclude(const string_res &s, const charclass_res &mask);
135
136// Modifiers
137void padStart(string_res &s, size_t n);
138void padStart(string_res &s, size_t n, char padding);
139void padEnd(string_res &s, size_t n);
140void padEnd(string_res &s, size_t n, char padding);
141
Note: See TracBrowser for help on using the repository browser.