| 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 Sep 14 10:58:28 2025
|
|---|
| 13 | // Update Count : 311
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #pragma once
|
|---|
| 17 |
|
|---|
| 18 | #include <iostream.hfa>
|
|---|
| 19 | #include <string_res.hfa>
|
|---|
| 20 |
|
|---|
| 21 | static struct __cfa_string_preference_boost_t {} __cfa_string_preference_boost;
|
|---|
| 22 | #define PBOOST forall ( | { __cfa_string_preference_boost_t __cfa_string_preference_boost; } )
|
|---|
| 23 |
|
|---|
| 24 | struct string {
|
|---|
| 25 | string_res * inner;
|
|---|
| 26 | };
|
|---|
| 27 |
|
|---|
| 28 | // RAII, assignment
|
|---|
| 29 | void ^?{}( string & s );
|
|---|
| 30 |
|
|---|
| 31 | void ?{}( string & s ); // empty string
|
|---|
| 32 | void ?{}( string & s, string s2, size_t maxlen );
|
|---|
| 33 | PBOOST void ?{}( string & s, string s2 );
|
|---|
| 34 | void ?{}( string & s, char );
|
|---|
| 35 | void ?{}( string & s, const char * c ); // copy from string literal (NULL-terminated)
|
|---|
| 36 | void ?{}( string & s, const char * c, size_t size ); // copy specific length from buffer
|
|---|
| 37 |
|
|---|
| 38 | void ?{}( string & s, signed long int rhs );
|
|---|
| 39 | void ?{}( string & s, size_t rhs );
|
|---|
| 40 | void ?{}( string & s, double rhs );
|
|---|
| 41 | void ?{}( string & s, long double rhs );
|
|---|
| 42 | void ?{}( string & s, double _Complex rhs );
|
|---|
| 43 | void ?{}( string & s, long double _Complex rhs );
|
|---|
| 44 | static inline void ?{}( string & s, int rhs ) { (s){(signed long int) rhs}; }
|
|---|
| 45 |
|
|---|
| 46 | PBOOST string & ?=?( string & s, string c );
|
|---|
| 47 | string & ?=?( string & s, const char * c ); // copy from "literal"
|
|---|
| 48 | string & ?=?( string & s, char c ); // copy from 'l'
|
|---|
| 49 | string & assign( string & s, const string & c, size_t n );
|
|---|
| 50 | string & assign( string & s, const char * c, size_t n );
|
|---|
| 51 | string & ?=?( string & s, signed long int rhs );
|
|---|
| 52 | string & ?=?( string & s, size_t rhs );
|
|---|
| 53 | string & ?=?( string & s, double rhs );
|
|---|
| 54 | string & ?=?( string & s, long double rhs );
|
|---|
| 55 | string & ?=?( string & s, double _Complex rhs );
|
|---|
| 56 | string & ?=?( string & s, long double _Complex rhs );
|
|---|
| 57 | static inline string & ?=?( string & s, int rhs ) { return s = ((signed long int) rhs); } // to match cost of (char * int): int
|
|---|
| 58 |
|
|---|
| 59 | static inline string & strcpy( string & s, const char * c ) { s = c; return s; }
|
|---|
| 60 | static inline string & strncpy( string & s, const char * c, size_t n ) { assign( s, c, n ); return s; }
|
|---|
| 61 | static inline string & strcpy( string & s, const string & c ) { s = c; return s; }
|
|---|
| 62 | static inline string & strncpy( string & s, const string & c, size_t n ) { assign( s, c, n ); return s; }
|
|---|
| 63 | char * strncpy( char * dst, string & src, size_t n );
|
|---|
| 64 | char * ?=?( char *& dst, string & src );
|
|---|
| 65 | void ?{}( char *& dst, string & src );
|
|---|
| 66 |
|
|---|
| 67 | // Alternate construction: request shared edits
|
|---|
| 68 | struct string_Share {
|
|---|
| 69 | string * s;
|
|---|
| 70 | };
|
|---|
| 71 | string_Share ?`share( string & s );
|
|---|
| 72 | void ?{}( string & s, string_Share src );
|
|---|
| 73 |
|
|---|
| 74 | // Getters
|
|---|
| 75 | static inline size_t len( const string & s ) { return len( *s.inner ); }
|
|---|
| 76 | static inline size_t len( const char * cs ) { return strlen( cs ); };
|
|---|
| 77 | static inline size_t strlen( const string & s ) { return len( s ); }
|
|---|
| 78 | size_t strnlen( const string & s, size_t maxlen );
|
|---|
| 79 |
|
|---|
| 80 | // IO Operator
|
|---|
| 81 | forall( ostype & | basic_ostream( ostype ) ) {
|
|---|
| 82 | ostype & ?|?( ostype & out, string s );
|
|---|
| 83 | void ?|?( ostype & out, string s );
|
|---|
| 84 | }
|
|---|
| 85 | forall( istype & | basic_istream( istype ) )
|
|---|
| 86 | istype & ?|?( istype & in, string & s );
|
|---|
| 87 |
|
|---|
| 88 | static inline {
|
|---|
| 89 | _Ostream_Manip(string) bin( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'b', { .all = 0 } }; }
|
|---|
| 90 | _Ostream_Manip(string) oct( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'o', { .all = 0 } }; }
|
|---|
| 91 | _Ostream_Manip(string) hex( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'x', { .all = 0 } }; }
|
|---|
| 92 | _Ostream_Manip(string) wd( unsigned int w, string s ) { return (_Ostream_Manip(string))@{ s, w, 0, 's', { .all = 0 } }; }
|
|---|
| 93 | _Ostream_Manip(string) wd( unsigned int w, unsigned int pc, string s ) { return (_Ostream_Manip(string))@{ s, w, pc, 's', { .flags.pc = true } }; }
|
|---|
| 94 | _Ostream_Manip(string) & wd( unsigned int w, _Ostream_Manip(string) & fmt ) { fmt.wd = w; return fmt; }
|
|---|
| 95 | _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; }
|
|---|
| 96 | _Ostream_Manip(string) & left( _Ostream_Manip(string) & fmt ) { fmt.flags.left = true; return fmt; }
|
|---|
| 97 | _Ostream_Manip(string) & nobase( _Ostream_Manip(string) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
|
|---|
| 98 | } // distribution
|
|---|
| 99 |
|
|---|
| 100 | forall( ostype & | basic_ostream( ostype ) ) {
|
|---|
| 101 | ostype & ?|?( ostype & os, _Ostream_Manip(string) f );
|
|---|
| 102 | void ?|?( ostype & os, _Ostream_Manip(string) );
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | struct _Istream_Swidth {
|
|---|
| 106 | string & s;
|
|---|
| 107 | inline _Istream_str_base;
|
|---|
| 108 | }; // _Istream_Swidth
|
|---|
| 109 |
|
|---|
| 110 | struct _Istream_Squote {
|
|---|
| 111 | _Istream_Swidth sstr;
|
|---|
| 112 | }; // _Istream_Squote
|
|---|
| 113 |
|
|---|
| 114 | struct _Istream_Sstr {
|
|---|
| 115 | string & s;
|
|---|
| 116 | inline _Istream_str_base;
|
|---|
| 117 | // _Istream_Swidth sstr;
|
|---|
| 118 | }; // _Istream_Sstr
|
|---|
| 119 |
|
|---|
| 120 | static inline {
|
|---|
| 121 | // read width does not include null terminator
|
|---|
| 122 | _Istream_Swidth wdi( unsigned int rwd, string & s ) { return (_Istream_Swidth)@{ .s = s, { {.scanset = 0p}, .wd = rwd, {.flags.rwd = true} } }; }
|
|---|
| 123 | _Istream_Sstr getline( string & s, const char delimiter = '\n' ) {
|
|---|
| 124 | return (_Istream_Sstr)@{ .s = s, { {.delimiters = { delimiter, '\0' } }, .wd = -1, {.flags.delimiter = true} } };
|
|---|
| 125 | }
|
|---|
| 126 | _Istream_Sstr & getline( _Istream_Swidth & f, const char delimiter = '\n' ) {
|
|---|
| 127 | f.delimiters[0] = delimiter; f.delimiters[1] = '\0'; f.flags.delimiter = true; return (_Istream_Sstr &)f;
|
|---|
| 128 | }
|
|---|
| 129 | _Istream_Squote quote( string & s, const char Ldelimiter = '\"', const char Rdelimiter = '\0' ) {
|
|---|
| 130 | return (_Istream_Squote)@{ { .s = s, { {.delimiters = { Ldelimiter, Rdelimiter, '\0' }}, .wd = -1, {.flags.rwd = true} } } };
|
|---|
| 131 | }
|
|---|
| 132 | _Istream_Squote & quote( _Istream_Swidth & f, const char Ldelimiter = '"', const char Rdelimiter = '\0' ) {
|
|---|
| 133 | f.delimiters[0] = Ldelimiter; f.delimiters[1] = Rdelimiter; f.delimiters[2] = '\0';
|
|---|
| 134 | return (_Istream_Squote &)f;
|
|---|
| 135 | }
|
|---|
| 136 | _Istream_Sstr incl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ .s = s, { {.scanset = scanset}, .wd = -1, {.flags.inex = false} } }; }
|
|---|
| 137 | _Istream_Sstr & incl( const char scanset[], _Istream_Swidth & f ) { f.scanset = scanset; f.flags.inex = false; return (_Istream_Sstr &)f; }
|
|---|
| 138 | _Istream_Sstr excl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ .s = s, { {.scanset = scanset}, .wd = -1, {.flags.inex = true} } }; }
|
|---|
| 139 | _Istream_Sstr & excl( const char scanset[], _Istream_Swidth & f ) { f.scanset = scanset; f.flags.inex = true; return (_Istream_Sstr &)f; }
|
|---|
| 140 | _Istream_Sstr ignore( string & s ) { return (_Istream_Sstr)@{ .s = s, { {.scanset = 0p}, .wd = -1, {.flags.ignore = true} } }; }
|
|---|
| 141 | _Istream_Sstr & ignore( _Istream_Swidth & f ) { f.flags.ignore = true; return (_Istream_Sstr &)f; }
|
|---|
| 142 | _Istream_Squote & ignore( _Istream_Squote & f ) { f.sstr.flags.ignore = true; return (_Istream_Squote &)f; }
|
|---|
| 143 | _Istream_Sstr & ignore( _Istream_Sstr & f ) { f.flags.ignore = true; return (_Istream_Sstr &)f; }
|
|---|
| 144 | } // distribution
|
|---|
| 145 |
|
|---|
| 146 | forall( istype & | basic_istream( istype ) ) {
|
|---|
| 147 | istype & ?|?( istype & is, _Istream_Squote f );
|
|---|
| 148 | istype & ?|?( istype & is, _Istream_Sstr f );
|
|---|
| 149 | static inline istype & ?|?( istype & is, _Istream_Swidth f ) { return is | *(_Istream_Sstr *)&f; }
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | // Concatenation
|
|---|
| 153 | void ?+=?( string & s, char c );
|
|---|
| 154 | PBOOST void ?+=?( string & s, string );
|
|---|
| 155 | void append( string & s, const string & s2, size_t maxlen );
|
|---|
| 156 | void ?+=?( string & s, const char * s2 );
|
|---|
| 157 | void append( string & s, const char * buffer, size_t bsize );
|
|---|
| 158 |
|
|---|
| 159 | string ?+?( string s, char c );
|
|---|
| 160 | string ?+?( char c, string s );
|
|---|
| 161 | PBOOST string ?+?( string s, string s2 );
|
|---|
| 162 | string ?+?( const char * s, char c ); // not backwards compatible
|
|---|
| 163 | string ?+?( char c, const char * s );
|
|---|
| 164 | string ?+?( const char * c, const char * s );
|
|---|
| 165 | string ?+?( const char * c, string s );
|
|---|
| 166 | string ?+?( string s, const char * c );
|
|---|
| 167 | string ?+?( char, char ); // not being called 8-(
|
|---|
| 168 |
|
|---|
| 169 | static inline string & strcat( string & s, const string & s2 ) { s += s2; return s; }
|
|---|
| 170 | static inline string & strcat( string & s, const char * c ) { s += c; return s; }
|
|---|
| 171 | static inline string & strncat( string & s, const string & s2, size_t maxlen ) { append( s, s2, maxlen ); return s; }
|
|---|
| 172 | static inline string & strncat( string & s, const char * buffer, size_t bsize ) { append( s, buffer, bsize ); return s; }
|
|---|
| 173 |
|
|---|
| 174 | // Repetition
|
|---|
| 175 |
|
|---|
| 176 | // Type `signed long long int` chosen for `factor` argument to achieve cost detente.
|
|---|
| 177 | // This way, the call `'a' * 3` gets the same safe conversion cost calling here as for
|
|---|
| 178 | // the built-in definition `int * int`.
|
|---|
| 179 | typedef signed long long int strmul_factor_t;
|
|---|
| 180 |
|
|---|
| 181 | void ?*=?( string & s, strmul_factor_t factor );
|
|---|
| 182 | string ?*?( char c, strmul_factor_t factor ); // not backwards compatible
|
|---|
| 183 | PBOOST string ?*?( string s, strmul_factor_t factor );
|
|---|
| 184 | string ?*?( const char * s, strmul_factor_t factor );
|
|---|
| 185 | static inline string ?*?( strmul_factor_t factor, char c ) { return c * factor; }
|
|---|
| 186 | PBOOST static inline string ?*?( strmul_factor_t factor, string s ) { return s * factor; }
|
|---|
| 187 | static inline string ?*?( strmul_factor_t factor, const char * s ) { return s * factor; }
|
|---|
| 188 |
|
|---|
| 189 | // Character access
|
|---|
| 190 | char ?[?]( const string & s, size_t index );
|
|---|
| 191 | string ?[?]( string & s, size_t index ); // mutable length-1 slice of original
|
|---|
| 192 | //char codePointAt(const string & s, size_t index ); // to revisit under Unicode
|
|---|
| 193 |
|
|---|
| 194 | // Comparisons
|
|---|
| 195 | static inline int strcmp( const string & s1, const string & s2 ) { return strcmp( *s1.inner, *s2.inner ); }
|
|---|
| 196 | int strncmp( const string & s1, const string & s2, size_t maxlen );
|
|---|
| 197 | static inline bool ?==?( const string & s1, const string & s2 ) { return *s1.inner == *s2.inner; }
|
|---|
| 198 | static inline bool ?!=?( const string & s1, const string & s2 ) { return *s1.inner != *s2.inner; }
|
|---|
| 199 | static inline bool ?>? ( const string & s1, const string & s2 ) { return *s1.inner > *s2.inner; }
|
|---|
| 200 | static inline bool ?>=?( const string & s1, const string & s2 ) { return *s1.inner >= *s2.inner; }
|
|---|
| 201 | static inline bool ?<=?( const string & s1, const string & s2 ) { return *s1.inner <= *s2.inner; }
|
|---|
| 202 | static inline bool ?<? ( const string & s1, const string & s2 ) { return *s1.inner < *s2.inner; }
|
|---|
| 203 |
|
|---|
| 204 | static inline int strcmp( const string & s1, const char * s2 ) { return strcmp( *s1.inner, s2 ); }
|
|---|
| 205 | int strncmp( const string & s1, const char * s2, size_t maxlen );
|
|---|
| 206 | static inline bool ?==?( const string & s1, const char * s2 ) { return *s1.inner == s2; }
|
|---|
| 207 | static inline bool ?!=?( const string & s1, const char * s2 ) { return *s1.inner != s2; }
|
|---|
| 208 | static inline bool ?>? ( const string & s1, const char * s2 ) { return *s1.inner > s2; }
|
|---|
| 209 | static inline bool ?>=?( const string & s1, const char * s2 ) { return *s1.inner >= s2; }
|
|---|
| 210 | static inline bool ?<=?( const string & s1, const char * s2 ) { return *s1.inner <= s2; }
|
|---|
| 211 | static inline bool ?<? ( const string & s1, const char * s2 ) { return *s1.inner < s2; }
|
|---|
| 212 |
|
|---|
| 213 | static inline int strcmp( const char * s1, const string & s2 ) { return strcmp( s1, *s2.inner ); }
|
|---|
| 214 | int strncmp( const char * s1, const string & s2, size_t maxlen );
|
|---|
| 215 | static inline bool ?==?( const char * s1, const string & s2 ) { return s1 == *s2.inner; }
|
|---|
| 216 | static inline bool ?!=?( const char * s1, const string & s2 ) { return s1 != *s2.inner; }
|
|---|
| 217 | static inline bool ?>? ( const char * s1, const string & s2 ) { return s1 > *s2.inner; }
|
|---|
| 218 | static inline bool ?>=?( const char * s1, const string & s2 ) { return s1 >= *s2.inner; }
|
|---|
| 219 | static inline bool ?<=?( const char * s1, const string & s2 ) { return s1 <= *s2.inner; }
|
|---|
| 220 | static inline bool ?<? ( const char * s1, const string & s2 ) { return s1 < *s2.inner; }
|
|---|
| 221 |
|
|---|
| 222 | // String search
|
|---|
| 223 | bool contains( const string & s, char ch ); // single character
|
|---|
| 224 |
|
|---|
| 225 | //int find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen );
|
|---|
| 226 | size_t find$( const string_res & s, size_t start, size_t len, const string & key_res, size_t kstart, size_t klen );
|
|---|
| 227 |
|
|---|
| 228 | size_t find( const string & s, char key );
|
|---|
| 229 | size_t find( const string & s, const char * key );
|
|---|
| 230 | size_t find( const string & s, const string & key );
|
|---|
| 231 | size_t find( const string & s, const char * key, size_t keysize );
|
|---|
| 232 |
|
|---|
| 233 | size_t find( const string & s, size_t start, char key );
|
|---|
| 234 | size_t find( const string & s, size_t start, const string & key );
|
|---|
| 235 | size_t find( const string & s, size_t start, const char * key );
|
|---|
| 236 | size_t find( const string & s, size_t start, const char * key, size_t keysize );
|
|---|
| 237 |
|
|---|
| 238 | bool includes( const string & s, const string & mask );
|
|---|
| 239 | bool includes( const string & s, const char * mask );
|
|---|
| 240 | bool includes( const string & s, const char * mask, size_t masksize );
|
|---|
| 241 |
|
|---|
| 242 | bool startsWith( const string & s, const string & prefix );
|
|---|
| 243 | bool startsWith( const string & s, const char * prefix );
|
|---|
| 244 | bool startsWith( const string & s, const char * prefix, size_t prefixsize );
|
|---|
| 245 |
|
|---|
| 246 | bool endsWith( const string & s, const string & suffix );
|
|---|
| 247 | bool endsWith( const string & s, const char * suffix );
|
|---|
| 248 | bool endsWith( const string & s, const char * suffix, size_t suffixsize );
|
|---|
| 249 |
|
|---|
| 250 | // Slicing
|
|---|
| 251 | string ?()( string & s, ssize_t start, ssize_t len );
|
|---|
| 252 | static inline string ?()( const string & s, ssize_t start, ssize_t len ) { string & w = (string &)s; return w( start, len ); } // FIX ME
|
|---|
| 253 | string ?()( string & s, ssize_t start );
|
|---|
| 254 | static inline string ?()( const string & s, ssize_t start ) { string & w = (string &)s; return w( start ); } // FIX ME
|
|---|
| 255 | static inline string ?()( string & s, char m ) { return s( find( s, m ), 1 )`share; }
|
|---|
| 256 | static inline string ?()( const string & s, char m ) { string & w = (string &)s; return w( find( s, m ), 1 )`share; } // FIX ME
|
|---|
| 257 | static inline string ?()( string & s, const char * m ) { return s( find( s, m ), len( m ) )`share; }
|
|---|
| 258 | static inline string ?()( const string & s, const char * m ) { string & w = (string &)s; return w( find( s, m ), len( m ) )`share; } // FIX ME
|
|---|
| 259 | static inline string ?()( string & s, const string & m ) { return s( find( s, m ), len( m ) )`share; }
|
|---|
| 260 | static inline string ?()( const string & s, const string & m ) { string & w = (string &)s; return w( find( s, m ), len( m ) )`share; } // FIX ME
|
|---|
| 261 |
|
|---|
| 262 | struct charclass {
|
|---|
| 263 | charclass_res * inner;
|
|---|
| 264 | };
|
|---|
| 265 |
|
|---|
| 266 | void ?{}( charclass & ) = void;
|
|---|
| 267 | void ?{}( charclass &, charclass ) = void;
|
|---|
| 268 | charclass ?=?( charclass &, charclass ) = void;
|
|---|
| 269 |
|
|---|
| 270 | void ?{}( charclass &, const string & chars );
|
|---|
| 271 | void ?{}( charclass &, const char * chars );
|
|---|
| 272 | void ?{}( charclass &, const char * chars, size_t charssize );
|
|---|
| 273 | void ^?{}( charclass & );
|
|---|
| 274 |
|
|---|
| 275 | size_t include( const string & s, const charclass & mask );
|
|---|
| 276 | static inline size_t include( const string & s, const char * mask ) { return include( s, (charclass){ mask } ); }
|
|---|
| 277 | static inline size_t include( const string & s, const string & mask ) { return include( s, (charclass){ mask } ); }
|
|---|
| 278 | static inline size_t include( const char * cs, const charclass & mask ) { return include( (string){ cs }, mask ); }
|
|---|
| 279 | static inline size_t include( const char * cs, const char * mask ) { return include( (string){ cs }, (charclass){ mask } ); }
|
|---|
| 280 | static inline size_t include( const char * cs, const string & mask ) { return include( (string){ cs }, (charclass){ mask } ); }
|
|---|
| 281 |
|
|---|
| 282 | static inline string include( const string & s, const charclass & mask ) { return s( 0, include( s, mask ) ); }
|
|---|
| 283 | static inline string include( const string & s, const char * mask ) { return s( 0, include( s, (charclass){ mask } ) ); }
|
|---|
| 284 | static inline string include( const string & s, const string & mask ) { return s( 0, include( s, (charclass){ mask } ) ); }
|
|---|
| 285 | static inline string include( const char * cs, const charclass & mask ) { const string s = cs; return s( 0, include( s, mask ) ); }
|
|---|
| 286 | static inline string include( const char * cs, const char * mask ) { const string s = cs; return s( 0, include( s, (charclass){ mask } ) ); }
|
|---|
| 287 | static inline string include( const char * cs, const string & mask ) { const string s = cs; return s( 0, include( s, (charclass){ mask } ) ); }
|
|---|
| 288 |
|
|---|
| 289 | size_t exclude( const string & s, const charclass & mask );
|
|---|
| 290 | static inline size_t exclude( const string & s, const char * mask ) { return exclude( s, (charclass){ mask } ); }
|
|---|
| 291 | static inline size_t exclude( const string & s, const string & mask ) { return exclude( s, (charclass){ mask } ); }
|
|---|
| 292 | static inline size_t exclude( const char * cs, const charclass & mask ) { return exclude( (string){ cs }, mask ); }
|
|---|
| 293 | static inline size_t exclude( const char * cs, const string & mask ) { return exclude( (string){ cs }, (charclass){ mask } ); }
|
|---|
| 294 | static inline size_t exclude( const char * cs, const char * mask ) { return exclude( (string){ cs }, (charclass){ mask } ); }
|
|---|
| 295 |
|
|---|
| 296 | static inline string exclude( const string & s, const charclass & mask ) { return s( 0, exclude( s, mask ) ); }
|
|---|
| 297 | static inline string exclude( const string & s, const char * mask ) { return s( 0, exclude( s, (charclass){ mask } ) ); }
|
|---|
| 298 | static inline string exclude( const string & s, const string & mask ) { return s( 0, exclude( s, (charclass){ mask } ) ); }
|
|---|
| 299 | static inline string exclude( const char * cs, const charclass & mask ) { const string s = cs; return s( 0, exclude( s, mask ) ); }
|
|---|
| 300 | static inline string exclude( const char * cs, const string & mask ) { const string s = cs; return s( 0, exclude( s, (charclass){ mask } ) ); }
|
|---|
| 301 | static inline string exclude( const char * cs, const char * mask ) { const string s = cs; return s( 0, exclude( s, (charclass){ mask } ) ); }
|
|---|
| 302 |
|
|---|
| 303 | size_t include( const string & s, int (* f)( int ) ); // for C character-class functions, e.g., isdigit
|
|---|
| 304 | static inline size_t include( const char * cs, int (* f)( int ) ) { return include( (string){ cs }, f ); }
|
|---|
| 305 | static inline string include( const string & s, int (* f)( int ) ) { return s( 0, include( s, f ) ); }
|
|---|
| 306 | static inline string include( const char * cs, int (* f)( int ) ) { const string s = cs; return s( 0, include( s, f ) ); }
|
|---|
| 307 |
|
|---|
| 308 | static inline size_t include( const string & s, bool (* f)( char ) ) { return include( s, (int (*)( int ))f ); }
|
|---|
| 309 | static inline size_t include( const char * cs, bool (* f)( char ) ) { return include( (string){ cs }, f ); }
|
|---|
| 310 | static inline string include( const string & s, bool (* f)( char ) ) { return s( 0, include( s, f ) ); }
|
|---|
| 311 | static inline string include( const char * cs, bool (* f)( char ) ) { const string s = cs; return s( 0, include( s, f ) ); }
|
|---|
| 312 |
|
|---|
| 313 | size_t exclude( const string & s, int (* f)( int ) ); // for C character-class functions, e.g., isdigit
|
|---|
| 314 | static inline size_t exclude( const char * cs, int (* f)( int ) ) { return exclude( (string){ cs }, f ); }
|
|---|
| 315 | static inline string exclude( const string & s, int (* f)( int ) ) { return s( 0, exclude( s, f ) ); }
|
|---|
| 316 | static inline string exclude( const char * cs, int (* f)( int ) ) { const string s = cs; return s( 0, exclude( s, f ) ); }
|
|---|
| 317 |
|
|---|
| 318 | static inline size_t exclude( const string & s, bool (* f)( char ) ) { return exclude( s, (int (*)( int ))f ); }
|
|---|
| 319 | static inline size_t exclude( const char * cs, bool (* f)( char ) ) { return exclude( (string){ cs }, f ); }
|
|---|
| 320 | static inline string exclude( const string & s, bool (* f)( char ) ) { return s( 0, exclude( s, f ) ); }
|
|---|
| 321 | static inline string exclude( const char * cs, bool (* f)( char ) ) { const string s = cs; return s( 0, exclude( s, f ) ); }
|
|---|
| 322 |
|
|---|
| 323 | string replace( const string & s, const string & from, const string & to );
|
|---|
| 324 | static inline string replace( const char * s, const char * from, const char * to ) { return replace( (string){ s }, (string){ from }, (string){ to } ); }
|
|---|
| 325 | static inline string replace( const string & s, const char * from, const char * to ) { return replace( s, (string){ from }, (string){ to } ); }
|
|---|
| 326 | static inline string replace( const string & s, const char * from, const string & to ) { return replace( s, (string){ from }, to ); }
|
|---|
| 327 | static inline string replace( const string & s, string & from, const char * to ) { return replace( s, from, (string){ to } ); }
|
|---|
| 328 |
|
|---|
| 329 | string translate( const string & s, int (* f)( int ) ); // for C character-class functions, e.g., isdigit
|
|---|
| 330 | static inline string translate( const char * cs, int (* f)( int ) ) { return translate( (string){ cs }, f ); }
|
|---|
| 331 |
|
|---|
| 332 | static inline string translate( const string & s, bool (* f)( char ) ) { return translate( s, (int (*)( int ))f ); }
|
|---|
| 333 | static inline string translate( const char * cs, bool (* f)( char ) ) { return translate( (string){ cs }, f ); }
|
|---|
| 334 |
|
|---|
| 335 | #ifndef _COMPILING_STRING_CFA_
|
|---|
| 336 | #undef PBOOST
|
|---|
| 337 | #endif
|
|---|