// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // string -- variable-length, mutable run of text, with value semantics // // Author : Michael L. Brooks // Created On : Fri Sep 03 11:00:00 2021 // Last Modified By : Peter A. Buhr // Last Modified On : Sat Sep 2 11:26:28 2023 // Update Count : 55 // #pragma once #include // in string_res.hfa struct string_res; struct charclass_res; struct string { string_res * inner; }; // Getters size_t size(const string & s); // RAII, assignment void ?{}(string & this); // empty string void ?{}(string & s, const char * initial); // copy from string literal (NULL-terminated) void ?{}(string & s, const char * buffer, size_t bsize); // copy specific length from buffer void ?{}(string & s, const string & s2); void ?{}(string & s, string & s2); void ?=?(string & s, const char * other); // copy assignment from literal void ?=?(string & s, const string & other); void ?=?(string & s, char other); string & ?=?(string & s, string & other); // surprising ret seems to help avoid calls to autogen //string ?=?( string &, string ) = void; void ^?{}(string & s); // Alternate construction: request shared edits struct string_WithSharedEdits { string * s; }; string_WithSharedEdits ?`shareEdits( string & this ); void ?{}( string & this, string_WithSharedEdits src ); // IO Operator ofstream & ?|?(ofstream & out, const string & s); void ?|?(ofstream & out, const string & s); ifstream & ?|?(ifstream & in, string & s); void ?|?( ifstream & in, string & this ); static inline { _Ostream_Manip(string) bin( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'b', { .all : 0 } }; } _Ostream_Manip(string) oct( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'o', { .all : 0 } }; } _Ostream_Manip(string) hex( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'x', { .all : 0 } }; } _Ostream_Manip(string) wd( unsigned int w, string s ) { return (_Ostream_Manip(string))@{ s, w, 0, 's', { .all : 0 } }; } _Ostream_Manip(string) wd( unsigned int w, unsigned int pc, string s ) { return (_Ostream_Manip(string))@{ s, w, pc, 's', { .flags.pc : true } }; } _Ostream_Manip(string) & wd( unsigned int w, _Ostream_Manip(string) & fmt ) { fmt.wd = w; return fmt; } _Ostream_Manip(string) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(string) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } _Ostream_Manip(string) & left( _Ostream_Manip(string) & fmt ) { fmt.flags.left = true; return fmt; } _Ostream_Manip(string) & nobase( _Ostream_Manip(string) & fmt ) { fmt.flags.nobsdp = true; return fmt; } } // distribution ofstream & ?|?( ofstream & os, _Ostream_Manip(string) f ); void ?|?( ofstream & os, _Ostream_Manip(string) ); struct _Istream_Sstr { string & s; inline _Istream_str_base; }; // _Istream_Sstr static inline { // read width does not include null terminator _Istream_Sstr wdi( unsigned int rwd, string & s ) { return (_Istream_Sstr)@{ s, {{0p}, rwd, {.flags.rwd : true}} }; } _Istream_Sstr getline( string & s, const char delimiter = '\n' ) { return (_Istream_Sstr)@{ s, {{.delimiter : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} }; } _Istream_Sstr & getline( _Istream_Sstr & fmt, const char delimiter = '\n' ) { fmt.delimiter[0] = delimiter; fmt.delimiter[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt; } _Istream_Sstr incl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ s, {{scanset}, -1, {.flags.inex : false}} }; } _Istream_Sstr & incl( const char scanset[], _Istream_Sstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } _Istream_Sstr excl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ s, {{scanset}, -1, {.flags.inex : true}} }; } _Istream_Sstr & excl( const char scanset[], _Istream_Sstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } _Istream_Sstr ignore( string & s ) { return (_Istream_Sstr)@{ s, {{0p}, -1, {.flags.ignore : true}} }; } _Istream_Sstr & ignore( _Istream_Sstr & fmt ) { fmt.flags.ignore = true; return fmt; } } // distribution ifstream & ?|?( ifstream & is, _Istream_Sstr f ); void ?|?( ifstream & is, _Istream_Sstr t ); // Concatenation void ?+=?(string & s, char other); // append a character void ?+=?(string & s, const string & s2); // append-concatenate to first string void ?+=?(string & s, const char * other); // append-concatenate to first string string ?+?(const string & s, char other); // add a character to a copy of the string string ?+?(const string & s, const string & s2); // copy and concatenate both strings string ?+?(const char * s1, const char * s2); // concatenate both strings string ?+?(const string & s, const char * other); // copy and concatenate with NULL-terminated string // Repetition string ?*?(const string & s, size_t factor); string ?*?(char c, size_t size); string ?*?(const char *s, size_t size); // Character access char ?[?](const string & s, size_t index); string ?[?](string & s, size_t index); // mutable length-1 slice of original //char codePointAt(const string & s, size_t index); // to revisit under Unicode // Comparisons int cmp (const string &, const string &); bool ?==?(const string &, const string &); bool ?!=?(const string &, const string &); bool ?>? (const string &, const string &); bool ?>=?(const string &, const string &); bool ?<=?(const string &, const string &); bool ?? (const string &, const char*); bool ?>=?(const string &, const char*); bool ?<=?(const string &, const char*); bool ?? (const char*, const string &); bool ?>=?(const char*, const string &); bool ?<=?(const char*, const string &); bool ?