source: libcfa/src/collections/string.hfa@ bc547d3

Last change on this file since bc547d3 was bc547d3, checked in by Peter A. Buhr <pabuhr@…>, 10 hours ago

formatting

  • Property mode set to 100644
File size: 20.7 KB
RevLine 
[f450f2f]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
[6264087]11// Last Modified By : Peter A. Buhr
[bc547d3]12// Last Modified On : Fri May 8 18:07:38 2026
13// Update Count : 367
[f450f2f]14//
15
16#pragma once
17
[3f631d6]18#include <iostream.hfa>
[9018dcf]19#include <string_res.hfa>
[f450f2f]20
[d03a386]21static struct __cfa_string_preference_boost_t {} __cfa_string_preference_boost;
22#define PBOOST forall ( | { __cfa_string_preference_boost_t __cfa_string_preference_boost; } )
23
[f450f2f]24struct string {
[4223317]25 string_res * inner;
[f450f2f]26};
27
28// RAII, assignment
[234c432]29void ^?{}( string & s );
30
[4223317]31void ?{}( string & s ); // empty string
[570e7ad]32void ?{}( string & s, string s2, size_t maxlen );
[d03a386]33PBOOST void ?{}( string & s, string s2 );
[4dab7e8]34void ?{}( string & s, char );
[bc547d3]35void ?{}( string & s, const char cs[] ); // copy from string literal (NULL-terminated)
36void ?{}( string & s, const char cs[], size_t size ); // copy specific length from buffer
[f2898df]37void ?{}( string & s, size_t rhs );
[2f16569]38void ?{}( string & s, ssize_t rhs );
[f2898df]39void ?{}( string & s, double rhs );
40void ?{}( string & s, long double rhs );
41void ?{}( string & s, double _Complex rhs );
42void ?{}( string & s, long double _Complex rhs );
[2f16569]43
44PBOOST string & ?=?( string & s, string rhs );
45string & ?=?( string & s, char rhs ); // copy from 'l'
[bc547d3]46string & ?=?( string & s, const char rhs[] ); // copy from "literal"
[2f16569]47string & assign( string & s, const string & rhs, size_t n );
[bc547d3]48string & assign( string & s, const char rhs[], size_t n );
[f2898df]49string & ?=?( string & s, size_t rhs );
[2f16569]50string & ?=?( string & s, ssize_t rhs );
[f2898df]51string & ?=?( string & s, double rhs );
52string & ?=?( string & s, long double rhs );
53string & ?=?( string & s, double _Complex rhs );
54string & ?=?( string & s, long double _Complex rhs );
55
[2f16569]56// Conversion
[d8a2f98]57static inline string tostr( char c ) { string s = c; return s; }
[bc547d3]58static inline string tostr( const char cs[] ) { string s = cs; return s; }
[d8a2f98]59static inline string tostr( size_t v ) { string s = v; return s; }
[2f16569]60static inline string tostr( ssize_t v ) { string s = v; return s; }
[d8a2f98]61static inline string tostr( double v ) { string s = v; return s; }
62static inline string tostr( long double v ) { string s = v; return s; }
63static inline string tostr( long double _Complex v ) { string s = v; return s; }
64
[2f16569]65// C compatibility
[bc547d3]66static inline string & strcpy( string & s, const char cs[] ) { s = cs; return s; }
67static inline string & strncpy( string & s, const char cs[], size_t n ) { assign( s, cs, n ); return s; }
[d8a2f98]68static inline string & strcpy( string & s1, const string & s2 ) { s1 = s2; return s1; }
69static inline string & strncpy( string & s, const string & cs, size_t n ) { assign( s, cs, n ); return s; }
[bc547d3]70char * strncpy( char dst[], string & src, size_t n );
[829a955]71char * ?=?( char *& dst, string & src );
72void ?{}( char *& dst, string & src );
[f450f2f]73
74// Alternate construction: request shared edits
[8c2723f]75struct string_Share {
[4223317]76 string * s;
[f450f2f]77};
[8c2723f]78string_Share ?`share( string & s );
79void ?{}( string & s, string_Share src );
[f450f2f]80
[234c432]81// Getters
82static inline size_t len( const string & s ) { return len( *s.inner ); }
[bc547d3]83static inline size_t len( const char cs[] ) { return strlen( cs ); };
[234c432]84static inline size_t strlen( const string & s ) { return len( s ); }
[5ad6f0d]85size_t strnlen( const string & s, size_t maxlen );
[234c432]86
[f450f2f]87// IO Operator
[3f631d6]88forall( ostype & | basic_ostream( ostype ) ) {
89 ostype & ?|?( ostype & out, string s );
90 void ?|?( ostype & out, string s );
91}
92forall( istype & | basic_istream( istype ) )
93istype & ?|?( istype & in, string & s );
[7e1dbd7]94
[34c6e1e6]95static inline {
[b19b362]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 } }; }
[bb1eabc]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 }; }
[b19b362]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; }
[34c6e1e6]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; }
[b19b362]107 _Ostream_Manip(string) & upcase( _Ostream_Manip(string) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; }
[bb1eabc]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; }
[34c6e1e6]110} // distribution
[dab6e39]111
[3f631d6]112forall( ostype & | basic_ostream( ostype ) ) {
113 ostype & ?|?( ostype & os, _Ostream_Manip(string) f );
114 void ?|?( ostype & os, _Ostream_Manip(string) );
115}
[34c6e1e6]116
[211def2]117struct _Istream_Swidth {
118 string & s;
119 inline _Istream_str_base;
120}; // _Istream_Swidth
121
[bc547d3]122// Restrict nesting of input manipulators to those combinations that make sense.
123
[30548de]124struct _Istream_Squote {
[211def2]125 _Istream_Swidth sstr;
[30548de]126}; // _Istream_Squote
[211def2]127
[34c6e1e6]128struct _Istream_Sstr {
[7e1dbd7]129 string & s;
[38de914]130 inline _Istream_str_base;
[211def2]131// _Istream_Swidth sstr;
[34c6e1e6]132}; // _Istream_Sstr
[7e1dbd7]133
134static inline {
135 // read width does not include null terminator
[1a7203d]136 _Istream_Swidth wdi( unsigned int rwd, string & s ) { return (_Istream_Swidth)@{ .s = s, { {.scanset = 0p}, .wd = rwd, {.flags.rwd = true} } }; }
[34c6e1e6]137 _Istream_Sstr getline( string & s, const char delimiter = '\n' ) {
[1a7203d]138 return (_Istream_Sstr)@{ .s = s, { {.delimiters = { delimiter, '\0' } }, .wd = -1, {.flags.delimiter = true} } };
[211def2]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 }
[30548de]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} } } };
[7e1dbd7]145 }
[30548de]146 _Istream_Squote & quote( _Istream_Swidth & f, const char Ldelimiter = '"', const char Rdelimiter = '\0' ) {
[211def2]147 f.delimiters[0] = Ldelimiter; f.delimiters[1] = Rdelimiter; f.delimiters[2] = '\0';
[30548de]148 return (_Istream_Squote &)f;
[7e1dbd7]149 }
[1a7203d]150 _Istream_Sstr incl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ .s = s, { {.scanset = scanset}, .wd = -1, {.flags.inex = false} } }; }
[211def2]151 _Istream_Sstr & incl( const char scanset[], _Istream_Swidth & f ) { f.scanset = scanset; f.flags.inex = false; return (_Istream_Sstr &)f; }
[1a7203d]152 _Istream_Sstr excl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ .s = s, { {.scanset = scanset}, .wd = -1, {.flags.inex = true} } }; }
[211def2]153 _Istream_Sstr & excl( const char scanset[], _Istream_Swidth & f ) { f.scanset = scanset; f.flags.inex = true; return (_Istream_Sstr &)f; }
[1a7203d]154 _Istream_Sstr ignore( string & s ) { return (_Istream_Sstr)@{ .s = s, { {.scanset = 0p}, .wd = -1, {.flags.ignore = true} } }; }
[211def2]155 _Istream_Sstr & ignore( _Istream_Swidth & f ) { f.flags.ignore = true; return (_Istream_Sstr &)f; }
[30548de]156 _Istream_Squote & ignore( _Istream_Squote & f ) { f.sstr.flags.ignore = true; return (_Istream_Squote &)f; }
[211def2]157 _Istream_Sstr & ignore( _Istream_Sstr & f ) { f.flags.ignore = true; return (_Istream_Sstr &)f; }
[7e1dbd7]158} // distribution
[dab6e39]159
[3f631d6]160forall( istype & | basic_istream( istype ) ) {
[30548de]161 istype & ?|?( istype & is, _Istream_Squote f );
[3f631d6]162 istype & ?|?( istype & is, _Istream_Sstr f );
163 static inline istype & ?|?( istype & is, _Istream_Swidth f ) { return is | *(_Istream_Sstr *)&f; }
164}
[f450f2f]165
166// Concatenation
[6b765d5]167void ?+=?( string & s, char c );
[c4f8c4bf]168PBOOST void ?+=?( string & s, string );
[6b765d5]169void append( string & s, const string & s2, size_t maxlen );
[bc547d3]170void ?+=?( string & s, const char cs[] );
171void append( string & s, const char buffer[], size_t bsize );
[6b765d5]172
[570e7ad]173string ?+?( string s, char c );
174string ?+?( char c, string s );
[d03a386]175PBOOST string ?+?( string s, string s2 );
[bc547d3]176string ?+?( const char cs[], char c ); // not backwards compatible
177string ?+?( char c, const char cs[] );
178string ?+?( const char cs1[] , const char cs2[] );
179string ?+?( const char cs[] , string s );
180string ?+?( string s, const char cs[] );
[6b765d5]181string ?+?( char, char ); // not being called 8-(
[4dab7e8]182
[d8a2f98]183static inline string & strcat( string & s1, const string & s2 ) { s1 += s2; return s1; }
[bc547d3]184static inline string & strcat( string & s, const char cs[] ) { s += cs; return s; }
[d8a2f98]185static inline string & strncat( string & s1, const string & s2, size_t maxlen ) { append( s1, s2, maxlen ); return s1; }
[bc547d3]186static inline string & strncat( string & s, const char buffer[], size_t bsize ) { append( s, buffer, bsize ); return s; }
[e891349]187
[f450f2f]188// Repetition
[570e7ad]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`.
193typedef signed long long int strmul_factor_t;
194
195void ?*=?( string & s, strmul_factor_t factor );
196string ?*?( char c, strmul_factor_t factor ); // not backwards compatible
[d03a386]197PBOOST string ?*?( string s, strmul_factor_t factor );
[bc547d3]198string ?*?( const char cs[], strmul_factor_t factor );
[421b242]199static inline string ?*?( strmul_factor_t factor, char c ) { return c * factor; }
[d03a386]200PBOOST static inline string ?*?( strmul_factor_t factor, string s ) { return s * factor; }
[bc547d3]201static inline string ?*?( strmul_factor_t factor, const char cs[] ) { return cs * factor; }
[f450f2f]202
203// Character access
[4dab7e8]204char ?[?]( const string & s, size_t index );
205string ?[?]( string & s, size_t index ); // mutable length-1 slice of original
206//char codePointAt(const string & s, size_t index ); // to revisit under Unicode
[f450f2f]207
208// Comparisons
[5ad6f0d]209static inline int strcmp( const string & s1, const string & s2 ) { return strcmp( *s1.inner, *s2.inner ); }
210int strncmp( const string & s1, const string & s2, size_t maxlen );
211static inline bool ?==?( const string & s1, const string & s2 ) { return *s1.inner == *s2.inner; }
212static inline bool ?!=?( const string & s1, const string & s2 ) { return *s1.inner != *s2.inner; }
213static inline bool ?>? ( const string & s1, const string & s2 ) { return *s1.inner > *s2.inner; }
214static inline bool ?>=?( const string & s1, const string & s2 ) { return *s1.inner >= *s2.inner; }
215static inline bool ?<=?( const string & s1, const string & s2 ) { return *s1.inner <= *s2.inner; }
216static inline bool ?<? ( const string & s1, const string & s2 ) { return *s1.inner < *s2.inner; }
217
[bc547d3]218static inline int strcmp( const string & s, const char cs[] ) { return strcmp( *s.inner, cs ); }
219int strncmp( const string & s1, const char cs[], size_t maxlen );
220static inline bool ?==?( const string & s, const char cs[] ) { return *s.inner == cs; }
221static inline bool ?!=?( const string & s, const char cs[] ) { return *s.inner != cs; }
222static inline bool ?>? ( const string & s, const char cs[] ) { return *s.inner > cs; }
223static inline bool ?>=?( const string & s, const char cs[] ) { return *s.inner >= cs; }
224static inline bool ?<=?( const string & s, const char cs[] ) { return *s.inner <= cs; }
225static inline bool ?<? ( const string & s, const char cs[] ) { return *s.inner < cs; }
226
227static inline int strcmp( const char cs[], const string & s ) { return strcmp( cs, *s.inner ); }
228int strncmp( const char cs[], const string & s, size_t maxlen );
229static inline bool ?==?( const char cs[], const string & s ) { return cs == *s.inner; }
230static inline bool ?!=?( const char cs[], const string & s ) { return cs != *s.inner; }
231static inline bool ?>? ( const char cs[], const string & s ) { return cs > *s.inner; }
232static inline bool ?>=?( const char cs[], const string & s ) { return cs >= *s.inner; }
233static inline bool ?<=?( const char cs[], const string & s ) { return cs <= *s.inner; }
234static inline bool ?<? ( const char cs[], const string & s ) { return cs < *s.inner; }
[416b443]235
[f450f2f]236// String search
237
[9018dcf]238size_t find( const string & s, char key );
[bc547d3]239size_t find( const string & s, const char key[] );
[9018dcf]240size_t find( const string & s, const string & key );
[bc547d3]241size_t find( const string & s, const char key[], size_t keysize );
[9018dcf]242
243size_t find( const string & s, size_t start, char key );
244size_t find( const string & s, size_t start, const string & key );
[bc547d3]245size_t find( const string & s, size_t start, const char key[] );
246size_t find( const string & s, size_t start, const char key[], size_t keysize );
[08ed947]247
[2f16569]248static inline bool includes( const string & s, char key ) { return find( s, key ) < len( s ); }
[bc547d3]249static inline bool includes( const string & s, const char key[] ) { return find( s, key ) < len( s ); }
[2f16569]250static inline bool includes( const string & s, const string & key ) { return find( s, key ) < len( s ); }
[bc547d3]251static inline bool includes( const string & s, const char key[], size_t keysize ){ return find( s, key, keysize ) < len( s ); }
[f450f2f]252
[4dab7e8]253bool startsWith( const string & s, const string & prefix );
[bc547d3]254bool startsWith( const string & s, const char prefix[] );
255bool startsWith( const string & s, const char prefix[], size_t prefixsize );
[f450f2f]256
[4dab7e8]257bool endsWith( const string & s, const string & suffix );
[bc547d3]258bool endsWith( const string & s, const char suffix[] );
259bool endsWith( const string & s, const char suffix[], size_t suffixsize );
[f450f2f]260
[ed5023d1]261// Slicing
[9018dcf]262string ?()( string & s, ssize_t start, ssize_t len );
263static inline string ?()( const string & s, ssize_t start, ssize_t len ) { string & w = (string &)s; return w( start, len ); } // FIX ME
[ed5023d1]264string ?()( string & s, ssize_t start );
[9018dcf]265static inline string ?()( const string & s, ssize_t start ) { string & w = (string &)s; return w( start ); } // FIX ME
[ed5023d1]266static inline string ?()( string & s, char m ) { return s( find( s, m ), 1 )`share; }
[9018dcf]267static inline string ?()( const string & s, char m ) { string & w = (string &)s; return w( find( s, m ), 1 )`share; } // FIX ME
[bc547d3]268static inline string ?()( string & s, const char m[] ) { return s( find( s, m ), len( m ) )`share; }
269static inline string ?()( const string & s, const char m[] ) { string & w = (string &)s; return w( find( s, m ), len( m ) )`share; } // FIX ME
[ed5023d1]270static inline string ?()( string & s, const string & m ) { return s( find( s, m ), len( m ) )`share; }
[9018dcf]271static inline string ?()( const string & s, const string & m ) { string & w = (string &)s; return w( find( s, m ), len( m ) )`share; } // FIX ME
[f450f2f]272
273struct charclass {
[4223317]274 charclass_res * inner;
[f450f2f]275};
276
277void ?{}( charclass & ) = void;
[4dab7e8]278void ?{}( charclass &, charclass ) = void;
279charclass ?=?( charclass &, charclass ) = void;
[f450f2f]280
[4dab7e8]281void ?{}( charclass &, const string & chars );
[bc547d3]282void ?{}( charclass &, const char chars[] );
283void ?{}( charclass &, const char chars[], size_t charssize );
[f450f2f]284void ^?{}( charclass & );
285
[9018dcf]286size_t include( const string & s, const charclass & mask );
[bc547d3]287static inline size_t include( const string & s, const char mask[] ) { return include( s, (charclass){ mask } ); }
[1324fde]288static inline size_t include( const string & s, const string & mask ) { return include( s, (charclass){ mask } ); }
[bc547d3]289static inline size_t include( const char cs[], const charclass & mask ) { return include( (string){ cs }, mask ); }
290static inline size_t include( const char cs[], const char mask[] ) { return include( (string){ cs }, (charclass){ mask } ); }
291static inline size_t include( const char cs[], const string & mask ) { return include( (string){ cs }, (charclass){ mask } ); }
[1324fde]292
[5ad6f0d]293static inline string include( const string & s, const charclass & mask ) { return s( 0, include( s, mask ) ); }
[bc547d3]294static inline string include( const string & s, const char mask[] ) { return s( 0, include( s, (charclass){ mask } ) ); }
[1324fde]295static inline string include( const string & s, const string & mask ) { return s( 0, include( s, (charclass){ mask } ) ); }
[bc547d3]296static inline string include( const char cs[], const charclass & mask ) { const string s = cs; return s( 0, include( s, mask ) ); }
297static inline string include( const char cs[], const char mask[] ) { const string s = cs; return s( 0, include( s, (charclass){ mask } ) ); }
298static inline string include( const char cs[], const string & mask ) { const string s = cs; return s( 0, include( s, (charclass){ mask } ) ); }
[9018dcf]299
300size_t exclude( const string & s, const charclass & mask );
[bc547d3]301static inline size_t exclude( const string & s, const char mask[] ) { return exclude( s, (charclass){ mask } ); }
[1324fde]302static inline size_t exclude( const string & s, const string & mask ) { return exclude( s, (charclass){ mask } ); }
[bc547d3]303static inline size_t exclude( const char cs[], const charclass & mask ) { return exclude( (string){ cs }, mask ); }
304static inline size_t exclude( const char cs[], const string & mask ) { return exclude( (string){ cs }, (charclass){ mask } ); }
305static inline size_t exclude( const char cs[], const char mask[] ) { return exclude( (string){ cs }, (charclass){ mask } ); }
[1324fde]306
[5ad6f0d]307static inline string exclude( const string & s, const charclass & mask ) { return s( 0, exclude( s, mask ) ); }
[bc547d3]308static inline string exclude( const string & s, const char mask[] ) { return s( 0, exclude( s, (charclass){ mask } ) ); }
[1324fde]309static inline string exclude( const string & s, const string & mask ) { return s( 0, exclude( s, (charclass){ mask } ) ); }
[bc547d3]310static inline string exclude( const char cs[], const charclass & mask ) { const string s = cs; return s( 0, exclude( s, mask ) ); }
311static inline string exclude( const char cs[], const string & mask ) { const string s = cs; return s( 0, exclude( s, (charclass){ mask } ) ); }
312static inline string exclude( const char cs[], const char mask[] ) { const string s = cs; return s( 0, exclude( s, (charclass){ mask } ) ); }
[1324fde]313
314size_t include( const string & s, int (* f)( int ) ); // for C character-class functions, e.g., isdigit
[bc547d3]315static inline size_t include( const char cs[], int (* f)( int ) ) { return include( (string){ cs }, f ); }
[1324fde]316static inline string include( const string & s, int (* f)( int ) ) { return s( 0, include( s, f ) ); }
[bc547d3]317static inline string include( const char cs[], int (* f)( int ) ) { const string s = cs; return s( 0, include( s, f ) ); }
[5ad6f0d]318
[1324fde]319static inline size_t include( const string & s, bool (* f)( char ) ) { return include( s, (int (*)( int ))f ); }
[bc547d3]320static inline size_t include( const char cs[], bool (* f)( char ) ) { return include( (string){ cs }, f ); }
[1324fde]321static inline string include( const string & s, bool (* f)( char ) ) { return s( 0, include( s, f ) ); }
[bc547d3]322static inline string include( const char cs[], bool (* f)( char ) ) { const string s = cs; return s( 0, include( s, f ) ); }
[5ad6f0d]323
[1324fde]324size_t exclude( const string & s, int (* f)( int ) ); // for C character-class functions, e.g., isdigit
[bc547d3]325static inline size_t exclude( const char cs[], int (* f)( int ) ) { return exclude( (string){ cs }, f ); }
[1324fde]326static inline string exclude( const string & s, int (* f)( int ) ) { return s( 0, exclude( s, f ) ); }
[bc547d3]327static inline string exclude( const char cs[], int (* f)( int ) ) { const string s = cs; return s( 0, exclude( s, f ) ); }
[1324fde]328
329static inline size_t exclude( const string & s, bool (* f)( char ) ) { return exclude( s, (int (*)( int ))f ); }
[bc547d3]330static inline size_t exclude( const char cs[], bool (* f)( char ) ) { return exclude( (string){ cs }, f ); }
[1324fde]331static inline string exclude( const string & s, bool (* f)( char ) ) { return s( 0, exclude( s, f ) ); }
[bc547d3]332static inline string exclude( const char cs[], bool (* f)( char ) ) { const string s = cs; return s( 0, exclude( s, f ) ); }
[5ad6f0d]333
334string replace( const string & s, const string & from, const string & to );
[bc547d3]335static inline string replace( const char cs[], const char from[], const char to[] ) { return replace( (string){ cs }, (string){ from }, (string){ to } ); }
336static inline string replace( const string & s, const char from[], const char to[] ) { return replace( s, (string){ from }, (string){ to } ); }
337static inline string replace( const string & s, const char from[], const string & to ) { return replace( s, (string){ from }, to ); }
338static inline string replace( const string & s, string & from, const char to[] ) { return replace( s, from, (string){ to } ); }
[1324fde]339
340string translate( const string & s, int (* f)( int ) ); // for C character-class functions, e.g., isdigit
[bc547d3]341static inline string translate( const char cs[], int (* f)( int ) ) { return translate( (string){ cs }, f ); }
[9018dcf]342
[1324fde]343static inline string translate( const string & s, bool (* f)( char ) ) { return translate( s, (int (*)( int ))f ); }
[bc547d3]344static inline string translate( const char cs[], bool (* f)( char ) ) { return translate( (string){ cs }, f ); }
[d03a386]345
346#ifndef _COMPILING_STRING_CFA_
347#undef PBOOST
348#endif
Note: See TracBrowser for help on using the repository browser.