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

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

Fixing LL API not allowing simple assignment.
Removing accidentally commited performance regression of attribute-no-inline.

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