Changes in / [4b30318b:8a9a3ab]


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/collections/string.cfa

    r4b30318b r8a9a3ab  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep  2 12:05:57 2023
    13 // Update Count     : 206
     12// Last Modified On : Thu Aug 31 13:20:41 2023
     13// Update Count     : 161
    1414//
    1515
     
    110110}
    111111
    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 
    126112ifstream & ?|?(ifstream & in, string & this) {
    127113    return in | (*this.inner); // read to internal string_res
     
    132118}
    133119
    134 ifstream & ?|?( ifstream & is, _Istream_Sstr f ) {
     120ifstream & ?|?( 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
    135129        // .---------------,
    136         // | | | | |...|0|0| null terminator and guard if missing
     130        // | | | | |...|0|0| check and guard
    137131        // `---------------'
    138         enum { gwd = 128 + 1, wd = gwd - 1 };                           // guard and unguard width
     132        enum { gwd = 128 + 2, wd = gwd - 1 };                           // guarded and unguarded width
    139133        char cstr[gwd];                                                                         // read in chunks
    140134        bool cont = false;
    141135
    142         _Istream_Cstr cf = { cstr, (_Istream_str_base)f };
    143         if ( ! cf.flags.rwd ) cf.wd = wd;
     136        if ( f.wd == -1 ) f.wd = wd;
     137        _Istream_Cstr cfmt = { cstr, (_Istream_str_base)f };
    144138
    145139        cstr[wd] = '\0';                                                                        // guard null terminate string
    146140        try {
    147                 is | cf;
     141                is | cfmt;
    148142        } catch( cstring_length * ) {
    149143                cont = true;
     
    154148                cont = false;
    155149                try {
    156                         is | cf;
     150                        is | cfmt;
    157151                } catch( cstring_length * ) {
    158152                        cont = true;                                                            // continue not allowed
     
    164158} // ?|?
    165159
    166 void ?|?( ifstream & in, _Istream_Sstr f ) {
     160void ?|?( ifstream & in, _Istream_str f ) {
    167161    (ifstream &)(in | f); ends( in );
    168162}
  • libcfa/src/collections/string.hfa

    r4b30318b r8a9a3ab  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep  2 11:26:28 2023
    13 // Update Count     : 55
     12// Last Modified On : Thu Aug 31 11:47:27 2023
     13// Update Count     : 49
    1414//
    1515
     
    5858void ?|?( ifstream & in, string & this );
    5959
    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 {
     60struct _Istream_str {
    7561        string & s;
    7662        inline _Istream_str_base;
    77 }; // _Istream_Sstr
     63}; // _Istream_str
    7864
    7965static inline {
    8066        // read width does not include null terminator
    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}} };
     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}} };
    8472        }
    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;
     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;
    8775        }
    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; }
     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; }
    9482} // distribution
    95 ifstream & ?|?( ifstream & is, _Istream_Sstr f );
    96 void ?|?( ifstream & is, _Istream_Sstr t );
     83ifstream & ?|?( ifstream & is, _Istream_str f );
     84void ?|?( ifstream & is, _Istream_str t );
    9785
    9886// Concatenation
  • libcfa/src/iostream.cfa

    r4b30318b r8a9a3ab  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep  2 14:42:01 2023
    13 // Update Count     : 1561
     12// Last Modified On : Thu Aug 31 11:27:56 2023
     13// Update Count     : 1545
    1414//
    1515
     
    922922        ISTYPE_VOID_IMPL( long double _Complex & )
    923923
    924         istype & ?|?( istype & is, const char fmt[] ) {
    925                 fmt( is, fmt, "" );
    926                 return is;
    927         } // ?|?
    928         ISTYPE_VOID_IMPL( const char * )
     924        // istype & ?|?( istype & is, const char fmt[] ) {
     925        //      fmt( is, fmt, "" );
     926        //      return is;
     927        // } // ?|?
     928
     929        // istype & ?|?( istype & is, char s[] ) {
     930        //      fmt( is, "%s", s );
     931        //      return is;
     932        // } // ?|?
     933        // ISTYPE_VOID_IMPL( char * )
    929934
    930935        // manipulators
     
    957962
    958963forall( istype & | basic_istream( istype ) ) {
    959         istype & ?|?( istype & is, _Istream_Cskip f ) {
    960                 // printf( "skip %s %d\n", f.scanset, f.wd );
    961                 if ( f.scanset ) fmt( is, f.scanset, "" );              // no input arguments
    962                 else for ( f.wd ) fmt( is, "%*c" );
    963                 return is;
    964         }
    965         ISTYPE_VOID_IMPL( _Istream_Cskip )
    966 
    967964        istype & ?|?( istype & is, _Istream_Cstr f ) {
     965                // skip
     966                if ( ! f.s ) {
     967                        // printf( "skip %s %d\n", f.scanset, f.wd );
     968                        if ( f.wd == -1 ) fmt( is, f.scanset, "" );     // no input arguments
     969                        else for ( f.wd ) fmt( is, "%*c" );
     970                        return is;
     971                } // if
     972
    968973                const char * scanset = f.scanset;
    969                 if ( f.flags.delimiter ) scanset = f.delimiter; // getline ?
     974                if ( f.flags.delimit ) scanset = f.delimit;             // getline ?
    970975
    971976                size_t len = 0;
     
    975980                fmtstr[0] = '%';
    976981                if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; }
    977                 // no maximum width necessary because text ignored => width is read width
    978982                if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); }
    979983
     
    10011005                        throw (cstring_length){ &cstring_length_vt };
    10021006
    1003                 if ( f.flags.delimiter ) {                                              // getline ?
     1007                if ( f.flags.delimit ) {                                                // getline ?
    10041008                        if ( len == 0 ) f.s[0] = '\0';                          // empty read => argument unchanged => set empty
    1005                         if ( ! eof( is ) ) {                                            // ignore delimiter, may not be present because of width
    1006                                 char delimiter;
    1007                                 fmt( is, "%c", &delimiter );
    1008                                 if ( delimiter != f.delimiter[0] ) ungetc( is, delimiter );
    1009                         } // if
     1009                        if ( ! eof( is ) ) fmt( is, "%*c" );            // ignore delimiter
    10101010                } //if
    10111011                return is;
  • libcfa/src/iostream.hfa

    r4b30318b r8a9a3ab  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep  2 14:42:13 2023
    13 // Update Count     : 567
     12// Last Modified On : Thu Aug 31 10:55:35 2023
     13// Update Count     : 544
    1414//
    1515
     
    388388        ISTYPE_VOID( long double _Complex & );
    389389
    390         istype & ?|?( istype &, const char [] );
    391         ISTYPE_VOID( const char [] );
     390//      istype & ?|?( istype &, const char [] );
     391//      istype & ?|?( istype &, char [] );
     392//      ISTYPE_VOID( char [] );
    392393
    393394        // manipulators
     
    405406// *********************************** manipulators ***********************************
    406407
    407 struct _Istream_Cskip {
    408         const char * scanset;
    409         unsigned wd;                                                                            // scan width
    410 }; // _Istream_Cskip
    411 
    412 static inline {
    413         _Istream_Cskip skip( const char scanset[] ) { return (_Istream_Cskip)@{ scanset, 0 }; }
    414         _Istream_Cskip skip( unsigned int wd ) { return (_Istream_Cskip)@{ 0p, wd }; }
    415 } // distribution
    416 forall( istype & | basic_istream( istype ) ) {
    417         istype & ?|?( istype & is, _Istream_Cskip f );
    418         ISTYPE_VOID( _Istream_Cskip );
    419 }
    420 
    421408struct _Istream_str_base {
    422409        union {
    423410                const char * scanset;
    424                 char delimiter[2];
     411                char delimit[2];
    425412        };
    426413        int wd;                                                                                         // width
     
    430417                        unsigned char ignore:1;                                         // do not change input argument
    431418                        unsigned char inex:1;                                           // include/exclude characters in scanset
    432                         unsigned char delimiter:1;                                      // delimit character
     419                        unsigned char delimit:1;                                        // delimit character
    433420                        unsigned char rwd:1;                                            // read width
    434421                } flags;
     
    449436                return (_Istream_Cstr)@{ s, { {0p}, rwd, {.flags.rwd : true} } };
    450437        }
    451         _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimiter = '\n' ) {
    452                 fmt.delimiter[0] = delimiter; fmt.delimiter[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt; }
     438        _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr)@{ 0p, { {scanset}, -1, {.all : 0} } }; }
     439        _Istream_Cstr skip( unsigned int wd ) { return (_Istream_Cstr)@{ 0p, { {0p}, wd, {.all : 0} } }; }
     440        _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimit = '\n' ) {
     441                fmt.delimit[0] = delimit; fmt.delimit[1] = '\0'; fmt.flags.delimit = true; fmt.flags.inex = true; return fmt; }
    453442        _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
    454443        _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; }
  • tests/io/.in/manipulatorsInput.txt

    r4b30318b r8a9a3ab  
    55abcyyy
    66aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww
    7 abc
    87abc
    98xx
  • tests/io/manipulatorsInput.cfa

    r4b30318b r8a9a3ab  
    77// Created On       : Sat Jun  8 17:58:54 2019
    88// Last Modified By : Peter A. Buhr
    9 // Last Modified On : Sat Sep  2 14:27:46 2023
    10 // Update Count     : 65
     9// Last Modified On : Mon Aug 14 17:38:52 2023
     10// Update Count     : 63
    1111//
    1212
     
    3636                char s[] = "yyyyyyyyyyyyyyyyyyyy";
    3737                char sk[] = "abc";
    38                 sin | "abc " | skip( sk ) | skip( 5 );                  sout | "1" | s;
     38                sin /*| "abc "*/ | skip( sk ) | skip( 5 );              sout | "1" | s;
    3939                sin | wdi( sizeof(s), s );                                              sout | "2" | s;
    4040                sin | ignore( s );                                                              sout | "3" | s;
Note: See TracChangeset for help on using the changeset viewer.