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