source: libcfa/src/containers/string_res.hfa @ 18783b4

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

Baseline of the string implementation.

  • Property mode set to 100644
File size: 4.7 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
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 ?=?(string_res &s, const char* other); // copy assignment from literal
85void ?=?(string_res &s, const string_res &other);
86void ?=?(string_res &s, string_res &other);
87void ?=?(string_res &s, char other);  // Str tolerates memcpys; still saw calls to autogen
88
89void ^?{}(string_res &s);
90
91// IO Operator
92ofstream & ?|?(ofstream &out, const string_res &s);
93void ?|?(ofstream &out, const string_res &s);
94
95// Concatenation
96void ?+=?(string_res &s, char other); // append a character
97void ?+=?(string_res &s, const string_res &s2); // append-concatenate to first string
98void ?+=?(string_res &s, const char* other); // append-concatenate to first string
99
100// Character access
101char ?[?](const string_res &s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
102//char codePointAt(const string_res &s, size_t index); // revisit under Unicode
103
104// Comparisons
105bool ?==?(const string_res &s, const string_res &other);
106bool ?!=?(const string_res &s, const string_res &other);
107bool ?==?(const string_res &s, const char* other);
108bool ?!=?(const string_res &s, const char* other);
109
110// String search
111bool contains(const string_res &s, char ch); // single character
112
113int find(const string_res &s, char search);
114int find(const string_res &s, const string_res &search);
115int find(const string_res &s, const char* search);
116int find(const string_res &s, const char* search, size_t searchsize);
117
118bool includes(const string_res &s, const string_res &search);
119bool includes(const string_res &s, const char* search);
120bool includes(const string_res &s, const char* search, size_t searchsize);
121
122bool startsWith(const string_res &s, const string_res &prefix);
123bool startsWith(const string_res &s, const char* prefix);
124bool startsWith(const string_res &s, const char* prefix, size_t prefixsize);
125
126bool endsWith(const string_res &s, const string_res &suffix);
127bool endsWith(const string_res &s, const char* suffix);
128bool endsWith(const string_res &s, const char* suffix, size_t suffixsize);
129
130int include(const string_res &s, const charclass_res &mask);
131int exclude(const string_res &s, const charclass_res &mask);
132
133// Modifiers
134void padStart(string_res &s, size_t n);
135void padStart(string_res &s, size_t n, char padding);
136void padEnd(string_res &s, size_t n);
137void padEnd(string_res &s, size_t n, char padding);
138
Note: See TracBrowser for help on using the repository browser.