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

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

String hybrid has working separated sharing contexts

  • Property mode set to 100644
File size: 4.3 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 -- variable-length, mutable run of text, with value 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// in string_res.hfa
22struct string_res;
23struct charclass_res;
24
25struct string {
26    string_res * inner;
27};
28
29// Getters
30size_t size(const string &s);
31
32// RAII, assignment
33void ?{}( string & this ); // empty string
34void ?{}(string &s, const char* initial); // copy from string literal (NULL-terminated)
35void ?{}(string &s, const char* buffer, size_t bsize); // copy specific length from buffer
36
37void ?{}(string &s, const string & s2);
38void ?{}(string &s, string & s2);
39
40void ?=?(string &s, const char* other); // copy assignment from literal
41void ?=?(string &s, const string &other);
42void ?=?(string &s, char other);
43string & ?=?(string &s, string &other);  // surprising ret seems to help avoid calls to autogen
44//string ?=?( string &, string ) = void;
45void ^?{}(string &s);
46
47// Alternate construction: request shared edits
48struct string_WithSharedEdits {
49    string * s;
50};
51string_WithSharedEdits ?`shareEdits( string & this );
52void ?{}( string & this, string_WithSharedEdits src );
53
54// IO Operator
55ofstream & ?|?(ofstream &out, const string &s);
56void ?|?(ofstream &out, const string &s);
57
58// Concatenation
59void ?+=?(string &s, char other); // append a character
60void ?+=?(string &s, const string &s2); // append-concatenate to first string
61void ?+=?(string &s, const char* other); // append-concatenate to first string
62string ?+?(const string &s, char other); // add a character to a copy of the string
63string ?+?(const string &s, const string &s2); // copy and concatenate both strings
64string ?+?(const char* s1, const char* s2); // concatenate both strings
65string ?+?(const string &s, const char* other); // copy and concatenate with NULL-terminated string
66
67// Repetition
68string ?*?(const string &s, size_t factor);
69string ?*?(char c, size_t size);
70string ?*?(const char *s, size_t size);
71
72// Character access
73char ?[?](const string &s, size_t index);
74string ?[?](string &s, size_t index);  // mutable length-1 slice of original
75//char codePointAt(const string &s, size_t index);  // to revisit under Unicode
76
77// Comparisons
78bool ?==?(const string &s, const string &other);
79bool ?!=?(const string &s, const string &other);
80bool ?==?(const string &s, const char* other);
81bool ?!=?(const string &s, const char* other);
82
83// Slicing
84string ?()( string & this, size_t start, size_t end );  // TODO const?
85string ?()( string & this, size_t start);
86
87// String search
88bool contains(const string &s, char ch); // single character
89
90int find(const string &s, char search);
91int find(const string &s, const string &search);
92int find(const string &s, const char* search);
93int find(const string &s, const char* search, size_t searchsize);
94
95bool includes(const string &s, const string &search);
96bool includes(const string &s, const char* search);
97bool includes(const string &s, const char* search, size_t searchsize);
98
99bool startsWith(const string &s, const string &prefix);
100bool startsWith(const string &s, const char* prefix);
101bool startsWith(const string &s, const char* prefix, size_t prefixsize);
102
103bool endsWith(const string &s, const string &suffix);
104bool endsWith(const string &s, const char* suffix);
105bool endsWith(const string &s, const char* suffix, size_t suffixsize);
106
107// Modifiers
108void padStart(string &s, size_t n);
109void padStart(string &s, size_t n, char padding);
110void padEnd(string &s, size_t n);
111void padEnd(string &s, size_t n, char padding);
112
113
114
115struct charclass {
116    charclass_res * inner;
117};
118
119void ?{}( charclass & ) = void;
120void ?{}( charclass &, charclass) = void;
121charclass ?=?( charclass &, charclass) = void;
122
123void ?{}( charclass &, const string & chars);
124void ?{}( charclass &, const char * chars );
125void ?{}( charclass &, const char * chars, size_t charssize );
126void ^?{}( charclass & );
127
128int include(const string &s, const charclass &mask);
129
130int exclude(const string &s, const charclass &mask);
131
132/*
133What to do with?
134StrRet include(string &s, const charclass &mask);
135StrRet exclude(string &s, const charclass &mask);
136*/
137
138
Note: See TracBrowser for help on using the repository browser.