- Timestamp:
- Jul 8, 2024, 8:37:18 PM (5 months ago)
- Branches:
- master
- Children:
- d287f3e
- Parents:
- a4e1b09
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
ra4e1b09 rc015e2d 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Feb 12 09:26:05 202413 // Update Count : 196612 // Last Modified On : Mon Jul 8 16:49:05 2024 13 // Update Count : 2017 14 14 // 15 15 … … 772 772 773 773 774 #define FALSE "false" 775 #define TRUE "true" 776 774 777 forall( istype & | basic_istream( istype ) ) { 775 778 istype & ?|?( istype & is, bool & b ) { 776 779 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 777 char val[6]; 778 int args = fmt( is, "%5s", val ); 779 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 780 if ( strcmp( val, "true" ) == 0 ) b = true; 781 else if ( strcmp( val, "false" ) == 0 ) b = false; 782 else { 783 fprintf( stderr, "invalid Boolean constant\n" ); 784 abort(); // cannot use abort stream 780 int len = -1; // len not set if no match 781 // Optional leading whitespace at start of strings. 782 fmt( is, " " FALSE "%n", &len ); // try false 783 if ( len != sizeof( FALSE ) - 1 ) { // remove null terminate 784 fmt( is, " " TRUE "%n", &len ); // try true 785 if ( len != sizeof( TRUE ) - 1 ) throwResume ExceptionInst( missing_data ); 785 786 } // if 786 787 return is; … … 940 941 } // ?|? 941 942 942 istype & ?|?( istype & is, const char fmt[] ) { 943 istype & ?|?( istype & is, const char fmt[] ) { // match text 943 944 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 944 945 size_t len = strlen( fmt ); … … 946 947 strcpy( fmtstr, fmt ); // copy format and add %n 947 948 strcpy( &fmtstr[len], "%n" ); 948 int len2 = -1; 949 fmt( is, fmtstr, &len2 ); 950 if ( ! eof( is ) && len2 == -1 ) throwResume ExceptionInst( missing_data ); 949 len = -1; 950 // scanf cursor does not move if no match 951 fmt( is, fmtstr, &len ); 952 if ( ! eof( is ) && len == -1 ) throwResume ExceptionInst( missing_data ); 951 953 return is; 952 954 } // ?|? -
libcfa/src/iostream.hfa
ra4e1b09 rc015e2d 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S un Apr 21 07:32:19202413 // Update Count : 7 4412 // Last Modified On : Sat Jul 6 11:33:31 2024 13 // Update Count : 758 14 14 // 15 15 … … 359 359 istype & ?|?( istype &, long double _Complex & ); 360 360 361 istype & ?|?( istype &, const char [] ); 361 // This is too restrictive as it prevents building a format in a string and using that format. 362 // inline istype & ?|?( istype &, char [] ) { // possible error, too restrictive to change 363 // _Static_assert( false, "reading a character array without a maximum length is unsafe. Use input manipulator \"wdi( N, s )\", where \"char s[N]\" or fmt( s )." ); 364 // } 365 istype & ?|?( istype &, const char [] ); // match text 362 366 363 367 // manipulators
Note: See TracChangeset
for help on using the changeset viewer.