Changeset 34c6e1e6
- Timestamp:
- Sep 2, 2023, 3:01:05 PM (15 months ago)
- Branches:
- master
- Children:
- 389fbf5
- Parents:
- 0f107e4
- Location:
- libcfa/src/collections
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r0f107e4 r34c6e1e6 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 31 13:20:41202313 // Update Count : 16112 // Last Modified On : Sat Sep 2 12:05:57 2023 13 // Update Count : 206 14 14 // 15 15 … … 110 110 } 111 111 112 ofstream & ?|?( ofstream & os, _Ostream_Manip(string) f ) { 113 size_t len = size( f.val ); 114 char cstr[len + 1]; // room for null terminator 115 for ( i; len ) cstr[i] = f.val[i]; // copy string 116 cstr[len] = '\0'; // terminate 117 _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all} }; 118 os | cf | nonl; 119 return os; 120 } // ?|? 121 122 void ?|?( ofstream & os, _Ostream_Manip(string) f ) { 123 (ofstream &)(os | f); ends( os ); 124 } 125 112 126 ifstream & ?|?(ifstream & in, string & this) { 113 127 return in | (*this.inner); // read to internal string_res … … 118 132 } 119 133 120 ifstream & ?|?( ifstream & is, _Istream_str f ) { 121 // skip, same as for char * 122 if ( ! &f.s ) { 123 // fprintf( stderr, "skip %s %d\n", f.scanset, f.wd ); 124 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments 125 else for ( f.wd ) fmt( is, "%*c" ); 126 return is; 127 } // if 128 134 ifstream & ?|?( ifstream & is, _Istream_Sstr f ) { 129 135 // .---------------, 130 // | | | | |...|0|0| check and guard136 // | | | | |...|0|0| null terminator and guard if missing 131 137 // `---------------' 132 enum { gwd = 128 + 2, wd = gwd - 1 }; // guarded and unguarded width138 enum { gwd = 128 + 1, wd = gwd - 1 }; // guard and unguard width 133 139 char cstr[gwd]; // read in chunks 134 140 bool cont = false; 135 141 136 if ( f.wd == -1 ) f.wd = wd;137 _Istream_Cstr cfmt = { cstr, (_Istream_str_base)f };142 _Istream_Cstr cf = { cstr, (_Istream_str_base)f }; 143 if ( ! cf.flags.rwd ) cf.wd = wd; 138 144 139 145 cstr[wd] = '\0'; // guard null terminate string 140 146 try { 141 is | cf mt;147 is | cf; 142 148 } catch( cstring_length * ) { 143 149 cont = true; … … 148 154 cont = false; 149 155 try { 150 is | cf mt;156 is | cf; 151 157 } catch( cstring_length * ) { 152 158 cont = true; // continue not allowed … … 158 164 } // ?|? 159 165 160 void ?|?( ifstream & in, _Istream_ str f ) {166 void ?|?( ifstream & in, _Istream_Sstr f ) { 161 167 (ifstream &)(in | f); ends( in ); 162 168 } -
libcfa/src/collections/string.hfa
r0f107e4 r34c6e1e6 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 31 11:47:27202313 // Update Count : 4912 // Last Modified On : Sat Sep 2 11:26:28 2023 13 // Update Count : 55 14 14 // 15 15 … … 58 58 void ?|?( ifstream & in, string & this ); 59 59 60 struct _Istream_str { 60 static inline { 61 _Ostream_Manip(string) bin( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'b', { .all : 0 } }; } 62 _Ostream_Manip(string) oct( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'o', { .all : 0 } }; } 63 _Ostream_Manip(string) hex( string s ) { return (_Ostream_Manip(string))@{ s, 1, 0, 'x', { .all : 0 } }; } 64 _Ostream_Manip(string) wd( unsigned int w, string s ) { return (_Ostream_Manip(string))@{ s, w, 0, 's', { .all : 0 } }; } 65 _Ostream_Manip(string) wd( unsigned int w, unsigned int pc, string s ) { return (_Ostream_Manip(string))@{ s, w, pc, 's', { .flags.pc : true } }; } 66 _Ostream_Manip(string) & wd( unsigned int w, _Ostream_Manip(string) & fmt ) { fmt.wd = w; return fmt; } 67 _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; } 68 _Ostream_Manip(string) & left( _Ostream_Manip(string) & fmt ) { fmt.flags.left = true; return fmt; } 69 _Ostream_Manip(string) & nobase( _Ostream_Manip(string) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 70 } // distribution 71 ofstream & ?|?( ofstream & os, _Ostream_Manip(string) f ); 72 void ?|?( ofstream & os, _Ostream_Manip(string) ); 73 74 struct _Istream_Sstr { 61 75 string & s; 62 76 inline _Istream_str_base; 63 }; // _Istream_ str77 }; // _Istream_Sstr 64 78 65 79 static inline { 66 80 // read width does not include null terminator 67 _Istream_str wdi( unsigned int rwd, string & s ) { return (_Istream_str)@{ s, {{0p}, rwd, {.flags.rwd : true}} }; } 68 _Istream_str skip( const char scanset[] ) { return (_Istream_str)@{ *0p, {{scanset}, -1, {.all : 0}} }; } 69 _Istream_str skip( unsigned int wd ) { return (_Istream_str)@{ *0p, {{0p}, wd, {.all : 0}} }; } 70 _Istream_str getline( string & s, const char delimit = '\n' ) { 71 return (_Istream_str)@{ s, {{.delimit : { delimit, '\0' } }, -1, {.flags.delimit : true, .flags.inex : true}} }; 81 _Istream_Sstr wdi( unsigned int rwd, string & s ) { return (_Istream_Sstr)@{ s, {{0p}, rwd, {.flags.rwd : true}} }; } 82 _Istream_Sstr getline( string & s, const char delimiter = '\n' ) { 83 return (_Istream_Sstr)@{ s, {{.delimiter : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} }; 72 84 } 73 _Istream_ str & getline( _Istream_str & fmt, const char delimit= '\n' ) {74 fmt.delimit [0] = delimit; fmt.delimit[1] = '\0'; fmt.flags.delimit= true; fmt.flags.inex = true; return fmt;85 _Istream_Sstr & getline( _Istream_Sstr & fmt, const char delimiter = '\n' ) { 86 fmt.delimiter[0] = delimiter; fmt.delimiter[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt; 75 87 } 76 _Istream_ str incl( const char scanset[], string & s ) { return (_Istream_str)@{ s, {{scanset}, -1, {.flags.inex : false}} }; }77 _Istream_ str & incl( const char scanset[], _Istream_str & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }78 _Istream_ str excl( const char scanset[], string & s ) { return (_Istream_str)@{ s, {{scanset}, -1, {.flags.inex : true}} }; }79 _Istream_ str & excl( const char scanset[], _Istream_str & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; }80 _Istream_ str ignore( string & s ) { return (_Istream_str)@{ s, {{0p}, -1, {.flags.ignore : true}} }; }81 _Istream_ str & ignore( _Istream_str & fmt ) { fmt.flags.ignore = true; return fmt; }88 _Istream_Sstr incl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ s, {{scanset}, -1, {.flags.inex : false}} }; } 89 _Istream_Sstr & incl( const char scanset[], _Istream_Sstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } 90 _Istream_Sstr excl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ s, {{scanset}, -1, {.flags.inex : true}} }; } 91 _Istream_Sstr & excl( const char scanset[], _Istream_Sstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } 92 _Istream_Sstr ignore( string & s ) { return (_Istream_Sstr)@{ s, {{0p}, -1, {.flags.ignore : true}} }; } 93 _Istream_Sstr & ignore( _Istream_Sstr & fmt ) { fmt.flags.ignore = true; return fmt; } 82 94 } // distribution 83 ifstream & ?|?( ifstream & is, _Istream_ str f );84 void ?|?( ifstream & is, _Istream_ str t );95 ifstream & ?|?( ifstream & is, _Istream_Sstr f ); 96 void ?|?( ifstream & is, _Istream_Sstr t ); 85 97 86 98 // Concatenation
Note: See TracChangeset
for help on using the changeset viewer.