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

Last change on this file since 6264087 was 6264087, checked in by Peter A. Buhr <pabuhr@…>, 15 months ago

formatting

  • Property mode set to 100644
File size: 4.8 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 : Peter A. Buhr
12// Last Modified On : Sun Aug 13 22:46:46 2023
13// Update Count     : 4
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);
57ifstream & ?|?(ifstream & in, string & s);
58void ?|?( ifstream & in, string & this );
59
60// Concatenation
61void ?+=?(string & s, char other); // append a character
62void ?+=?(string & s, const string & s2); // append-concatenate to first string
63void ?+=?(string & s, const char * other); // append-concatenate to first string
64string ?+?(const string & s, char other); // add a character to a copy of the string
65string ?+?(const string & s, const string & s2); // copy and concatenate both strings
66string ?+?(const char * s1, const char * s2); // concatenate both strings
67string ?+?(const string & s, const char * other); // copy and concatenate with NULL-terminated string
68
69// Repetition
70string ?*?(const string & s, size_t factor);
71string ?*?(char c, size_t size);
72string ?*?(const char *s, size_t size);
73
74// Character access
75char ?[?](const string & s, size_t index);
76string ?[?](string & s, size_t index);  // mutable length-1 slice of original
77//char codePointAt(const string & s, size_t index);  // to revisit under Unicode
78
79// Comparisons
80bool ?==?(const string & s, const string & other);
81bool ?!=?(const string & s, const string & other);
82bool ?==?(const string & s, const char * other);
83bool ?!=?(const string & s, const char * other);
84
85// Slicing
86string ?()( string & this, size_t start, size_t end );  // TODO const?
87string ?()( string & this, size_t start);
88
89// String search
90bool contains(const string & s, char ch); // single character
91
92int find(const string & s, char search);
93int find(const string & s, const string & search);
94int find(const string & s, const char * search);
95int find(const string & s, const char * search, size_t searchsize);
96
97int findFrom(const string & s, size_t fromPos, char search);
98int findFrom(const string & s, size_t fromPos, const string & search);
99int findFrom(const string & s, size_t fromPos, const char * search);
100int findFrom(const string & s, size_t fromPos, const char * search, size_t searchsize);
101
102bool includes(const string & s, const string & search);
103bool includes(const string & s, const char * search);
104bool includes(const string & s, const char * search, size_t searchsize);
105
106bool startsWith(const string & s, const string & prefix);
107bool startsWith(const string & s, const char * prefix);
108bool startsWith(const string & s, const char * prefix, size_t prefixsize);
109
110bool endsWith(const string & s, const string & suffix);
111bool endsWith(const string & s, const char * suffix);
112bool endsWith(const string & s, const char * suffix, size_t suffixsize);
113
114// Modifiers
115void padStart(string & s, size_t n);
116void padStart(string & s, size_t n, char padding);
117void padEnd(string & s, size_t n);
118void padEnd(string & s, size_t n, char padding);
119
120
121
122struct charclass {
123    charclass_res * inner;
124};
125
126void ?{}( charclass & ) = void;
127void ?{}( charclass &, charclass) = void;
128charclass ?=?( charclass &, charclass) = void;
129
130void ?{}( charclass &, const string & chars);
131void ?{}( charclass &, const char * chars );
132void ?{}( charclass &, const char * chars, size_t charssize );
133void ^?{}( charclass & );
134
135int include(const string & s, const charclass & mask);
136
137int exclude(const string & s, const charclass & mask);
138
139/*
140What to do with?
141StrRet include(string & s, const charclass & mask);
142StrRet exclude(string & s, const charclass & mask);
143*/
Note: See TracBrowser for help on using the repository browser.