Changeset 88001dd for libcfa/src


Ignore:
Timestamp:
Aug 24, 2023, 11:39:08 AM (10 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
aa25216
Parents:
5ad2c6c7
Message:

first attempt reading strings in chunks using C strings

Location:
libcfa/src/containers
Files:
2 edited

Legend:

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

    r5ad2c6c7 r88001dd  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 13 22:50:08 2023
    13 // Update Count     : 7
     12// Last Modified On : Thu Aug 24 11:27:57 2023
     13// Update Count     : 89
    1414//
    1515
     
    118118}
    119119
     120void getline( ifstream & in, string & str, const char delimit = '\n' ) {
     121        // .---------------,
     122        // | | | | |...|0|0| check and guard
     123        // `---------------'
     124        enum { gwd = 256 + 2, wd = gwd - 1 };                           // guarded and unguarded width
     125        char cstr[gwd];                                                                         // read in chunks
     126        bool cont = false;;
     127
     128        cstr[wd] = '\0';                                                                        // guard null terminate string
     129        try {
     130                in | getline( wdi( wd, cstr ), delimit );               // must have room for string terminator
     131                if ( eof( in  ) ) return;                                               // do not change argument
     132        } catch( cstring_length * ) {
     133                cont = true;                                                                    // continue not allowed
     134        } finally {
     135                str = cstr;                                                                             // ok to initialize string
     136        } // try
     137        for ( ; cont; )  {                                                                      // overflow read ?
     138                cont = false;
     139                try {
     140                        in | getline( wdi( wd, cstr ), delimit );       // must have room for string terminator
     141                        if ( eof( in  ) ) return;
     142                } catch( cstring_length * ) {
     143                        cont = true;                                                            // continue not allowed
     144                } finally {
     145                        str += cstr;                                                            // build string chunk at a time
     146                } // try
     147        } // for
     148}
     149
    120150////////////////////////////////////////////////////////
    121151// Slicing
  • libcfa/src/containers/string.hfa

    r5ad2c6c7 r88001dd  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 13 22:46:46 2023
    13 // Update Count     : 4
     12// Last Modified On : Wed Aug 23 11:16:14 2023
     13// Update Count     : 6
    1414//
    1515
     
    5757ifstream & ?|?(ifstream & in, string & s);
    5858void ?|?( ifstream & in, string & this );
     59void getline( ifstream & in, string & this, const char delimit = '\n' );
    5960
    6061// Concatenation
Note: See TracChangeset for help on using the changeset viewer.