source: libcfa/src/containers/string_res.hfa @ 6cc87c0

Last change on this file since 6cc87c0 was 6cc87c0, checked in by Michael Brooks <mlbrooks@…>, 2 months ago

String bug fixes and new tests.

Enabled white-box visibility (DEBUG_ functions) into the string representation for heap-oriented tests.

string-gc/basicFillCompact

  • newly testable, now with the DEBUG_ visibility, but was basically already working

string-gc/fillCompact_withSharedEdits

  • new check for bug fixed here, where an append that triggers a compaction left substrings with dangling pointers

to the old text-pad range; fix is how string_res/assign now sequences growth-pushing operations before grabbing
pointers into the ranges of the old-version

string-overwrite

  • new broad check a few of whose cases are fixed here; fixes are the adjustments to the case priorities and

edge-case classifications in string_res/assign "adjust all substring string and handle locations" section

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