Changeset b19b362 for libcfa/src/iostream.cfa
- Timestamp:
- May 3, 2026, 8:25:27 AM (3 days ago)
- Branches:
- master
- Children:
- c136863
- Parents:
- efa8439a
- File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
refa8439a rb19b362 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 18 08:23:40 202513 // Update Count : 2 17512 // Last Modified On : Sun May 3 08:08:29 2026 13 // Update Count : 2241 14 14 // 15 15 … … 52 52 fmt( os, "%c", c ); 53 53 if ( c == '\n' ) setNL$( os, true ); 54 return nosep( os ); 54 return nosep( os ); // no separator after char 55 55 } // ?|? 56 56 OSTYPE_VOID_IMPL( os, char ) … … 204 204 ostype & ?|?( ostype & os, float _Complex fc ) with ( basic_ostream_table ) { 205 205 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 206 // os | crealf( fc ) | nonl;207 206 PRINT_WITH_DP( os, "%'g", crealf( fc ) ); 208 207 PRINT_WITH_DP( os, "%'+g", cimagf( fc ) ); … … 271 270 if ( ch == '\n' ) setNL$( os, true ); // check *AFTER* sepPrt$ call above as it resets NL flag 272 271 return os; 273 // return write( os, s, len );274 272 } // ?|? 275 273 OSTYPE_VOID_IMPL( os, const char * ) … … 645 643 #define FLOATING_POINT_FMT_IMPL( T, DFMTNP, DFMTP ) \ 646 644 forall( ostype & | basic_ostream( ostype ) ) { \ 647 static void eng( T & value, int & pc, int & exp10 ) { \645 static void eng( T & value, int & pc, int & exp10 ) { \ 648 646 exp10 = lrint( floor( log10( abs( value ) ) ) ); /* round to desired precision */ \ 649 647 if ( exp10 < 0 ) exp10 -= 2; \ … … 697 695 fmtuc.flags.pc = f.flags.pc; 698 696 fmtuc.flags.nobsdp = f.flags.nobsdp; 699 // os | fmtuc | nonl; 697 return (ostype &)(os | fmtuc); 698 } // if 699 if ( f.flags.quote ) { // print as string 700 char qv[] = "' '"; 701 qv[1] = f.val; 702 f.flags.quote = false; // already quoted 703 _Ostream_Manip(const char *) fmtuc @= { qv, f.wd, f.pc, 's', {f.all} }; 700 704 (ostype &)(os | fmtuc); 701 return os;702 } // if 703 704 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 705 706 #define CFMTNP "% * "705 return nosep( os ); // no separator after char 706 } // if 707 708 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 709 710 #define CFMTNP "% *c" 707 711 char fmtstr[sizeof(CFMTNP)]; // sizeof includes '\0' 708 712 memcpy( &fmtstr, CFMTNP, sizeof(CFMTNP) ); … … 713 717 fmtstr[star] = '%'; 714 718 715 fmtstr[sizeof(CFMTNP)-2] = f.base; // sizeof includes '\0'716 719 // printf( "%d %s\n", f.wd, &fmtstr[star] ); 717 720 fmt( os, &fmtstr[star], f.wd, f.val ); 718 return os;721 return nosep( os ); // no separator after char 719 722 } // ?|? 720 723 OSTYPE_VOID_IMPL( os, _Ostream_Manip(char) ) … … 733 736 for ( i; 0 ~ @ : @; f.val[i] != '\0' ) { 734 737 fmtuc.val = f.val[i]; 735 // os | fmtuc | nonl;736 738 (ostype &)(os | fmtuc); 737 739 } // for 738 740 return os; 739 741 } // if 742 if ( f.flags.quote ) { // print as string 743 int len = strlen( f.val ); 744 char qv[len + 3]; // space for quotes and '\0' 745 qv[0] = '"'; // copy string surrounded with quotes 746 strcpy( &qv[1], f.val ); 747 qv[len + 1] = '"'; 748 qv[len + 2] = '\0'; 749 f.flags.quote = false; // already quoted 750 _Ostream_Manip(const char *) fmtuc @= { qv, f.wd, f.pc, 's', {f.all} }; 751 return (ostype &)(os | fmtuc); 752 } // if 740 753 741 754 if ( f.val[0] != '\0' && // null string => no leading separator 742 755 sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 743 756 744 #define SFMTNP "% * "745 #define SFMTP "% *.* "757 #define SFMTNP "% *s" 758 #define SFMTP "% *.*s" 746 759 char fmtstr[sizeof(SFMTP)]; // sizeof includes '\0' 747 760 if ( ! f.flags.pc ) memcpy( &fmtstr, SFMTNP, sizeof(SFMTNP) ); … … 755 768 if ( ! f.flags.pc ) { // no precision 756 769 // printf( "%d %s\n", f.wd, &fmtstr[star] ); 757 fmtstr[sizeof(SFMTNP)-2] = f.base; // sizeof includes '\0'758 770 fmt( os, &fmtstr[star], f.wd, f.val ); 759 771 } else { // precision 760 fmtstr[sizeof(SFMTP)-2] = f.base; // sizeof includes '\0'761 772 // printf( "%d %d %s\n", f.wd, f.pc, &fmtstr[star] ); 762 773 fmt( os, &fmtstr[star], f.wd, f.pc, f.val ); … … 796 807 for () { 797 808 int args = fmt( is, "%c", &temp ); // can be called with EOF on 798 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );809 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 799 810 assert( args == 1 ); // if not EOF => a single character must be read 800 811 // do not overwrite parameter with newline unless appropriate 801 if ( temp != '\n' || getANL$( is ) ) { c = temp; break; }812 if ( temp != '\n' || getANL$( is ) ) { c = temp; break; } 802 813 } // for 803 814 return is;
Note:
See TracChangeset
for help on using the changeset viewer.