- Timestamp:
- Feb 10, 2024, 5:59:21 PM (15 months ago)
- Branches:
- master
- Children:
- 9d4628b
- Parents:
- 956299b
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified libcfa/src/collections/string_res.cfa ¶
r956299b r714e206 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 7 22:21:33202413 // Update Count : 8 112 // Last Modified On : Sat Feb 10 17:47:22 2024 13 // Update Count : 83 14 14 // 15 15 … … 252 252 253 253 ifstream & ?|?( ifstream & is, _Istream_Rquoted f ) with( f.rstr ) { 254 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 254 255 int args; 255 256 fini: { 256 args = fmt( is, "%*[ \f\n\r\t\v]" ); // remove leading whitespace 257 if ( eof( is ) ) break fini; 258 char rfmt[4] = { delimiters[0], '%', 'n', '\0' }; 259 int len = 0; // may not be set in fmt 260 args = fmt( is, rfmt, &len ); // remove leading quote 261 if ( len == 0 || eof( is ) ) break fini; 257 char rfmt[5] = { ' ', delimiters[0], '%', 'n', '\0' }; 258 int len = -1; // may not be set in fmt 259 args = fmt( is, rfmt, &len ); // remove leading whitespace and quote 260 if ( eof( is ) || len == -1 ) break fini; 262 261 263 262 // Change the remainder of the read into a getline by reseting the closing delimiter. -
TabularUnified libcfa/src/iostream.cfa ¶
r956299b r714e206 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 7 22:19:59202413 // Update Count : 19 1812 // Last Modified On : Sat Feb 10 09:28:32 2024 13 // Update Count : 1946 14 14 // 15 15 … … 774 774 forall( istype & | basic_istream( istype ) ) { 775 775 istype & ?|?( istype & is, bool & b ) { 776 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 776 777 char val[6]; 777 778 int args = fmt( is, "%5s", val ); 778 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );779 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 779 780 if ( strcmp( val, "true" ) == 0 ) b = true; 780 781 else if ( strcmp( val, "false" ) == 0 ) b = false; … … 787 788 788 789 istype & ?|?( istype & is, char & c ) { 790 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 789 791 char temp; 790 792 for () { 791 793 int args = fmt( is, "%c", &temp ); 792 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );794 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 793 795 // do not overwrite parameter with newline unless appropriate 794 796 if ( temp != '\n' || getANL$( is ) ) { c = temp; break; } … … 799 801 800 802 istype & ?|?( istype & is, signed char & sc ) { 803 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 801 804 int args = fmt( is, "%hhi", &sc ); 802 if ( args != -1 && args !=1 ) throwResume ExceptionInst( missing_data );805 if ( args != 1 ) throwResume ExceptionInst( missing_data ); 803 806 return is; 804 807 } // ?|? 805 808 806 809 istype & ?|?( istype & is, unsigned char & usc ) { 810 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 807 811 int args = fmt( is, "%hhi", &usc ); 808 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );812 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 809 813 return is; 810 814 } // ?|? 811 815 812 816 istype & ?|?( istype & is, short int & si ) { 817 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 813 818 int args = fmt( is, "%hi", &si ); 814 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );819 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 815 820 return is; 816 821 } // ?|? 817 822 818 823 istype & ?|?( istype & is, unsigned short int & usi ) { 824 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 819 825 int args = fmt( is, "%hi", &usi ); 820 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );826 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 821 827 return is; 822 828 } // ?|? 823 829 824 830 istype & ?|?( istype & is, int & i ) { 831 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 825 832 int args = fmt( is, "%i", &i ); 826 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );833 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 827 834 return is; 828 835 } // ?|? 829 836 830 837 istype & ?|?( istype & is, unsigned int & ui ) { 838 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 831 839 int args = fmt( is, "%i", &ui ); 832 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );840 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 833 841 return is; 834 842 } // ?|? 835 843 836 844 istype & ?|?( istype & is, long int & li ) { 845 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 837 846 int args = fmt( is, "%li", &li ); 838 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );847 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 839 848 return is; 840 849 } // ?|? 841 850 842 851 istype & ?|?( istype & is, unsigned long int & ulli ) { 852 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 843 853 int args = fmt( is, "%li", &ulli ); 844 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );854 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 845 855 return is; 846 856 } // ?|? 847 857 848 858 istype & ?|?( istype & is, long long int & lli ) { 859 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 849 860 int args = fmt( is, "%lli", &lli ); 850 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );861 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 851 862 return is; 852 863 } // ?|? 853 864 854 865 istype & ?|?( istype & is, unsigned long long int & ulli ) { 866 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 855 867 int args = fmt( is, "%lli", &ulli ); 856 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );868 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 857 869 return is; 858 870 } // ?|? … … 881 893 882 894 istype & ?|?( istype & is, float & f ) { 895 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 883 896 int args = fmt( is, "%f", &f ); 884 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );897 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 885 898 return is; 886 899 } // ?|? 887 900 888 901 istype & ?|?( istype & is, double & d ) { 902 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 889 903 int args = fmt( is, "%lf", &d ); 890 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );904 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 891 905 return is; 892 906 } // ?|? 893 907 894 908 istype & ?|?( istype & is, long double & ld ) { 909 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 895 910 int args = fmt( is, "%Lf", &ld ); 896 if ( args != -1&& args != 1 ) throwResume ExceptionInst( missing_data );911 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 897 912 return is; 898 913 } // ?|? 899 914 900 915 istype & ?|?( istype & is, float _Complex & fc ) { 916 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 901 917 float re, im; 902 918 int args = fmt( is, "%f%fi", &re, &im ); 903 if ( args != -1&& args != 2 ) throwResume ExceptionInst( missing_data );919 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data ); 904 920 fc = re + im * _Complex_I; 905 921 return is; … … 907 923 908 924 istype & ?|?( istype & is, double _Complex & dc ) { 925 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 909 926 double re, im; 910 927 int args = fmt( is, "%lf%lfi", &re, &im ); 911 if ( args != -1&& args != 2 ) throwResume ExceptionInst( missing_data );928 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data ); 912 929 dc = re + im * _Complex_I; 913 930 return is; … … 915 932 916 933 istype & ?|?( istype & is, long double _Complex & ldc ) { 934 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 917 935 long double re, im; 918 936 int args = fmt( is, "%Lf%Lfi", &re, &im ); 919 if ( args != -1&& args != 2 ) throwResume ExceptionInst( missing_data );937 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data ); 920 938 ldc = re + im * _Complex_I; 921 939 return is; … … 923 941 924 942 istype & ?|?( istype & is, const char fmt[] ) { 943 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 925 944 size_t len = strlen( fmt ); 926 char fmt 2[len + 16];927 strcpy( fmt 2, fmt ); // copy format and add %n928 strcpy( &fmt 2[len], "%n" );945 char fmtstr[len + 16]; 946 strcpy( fmtstr, fmt ); // copy format and add %n 947 strcpy( &fmtstr[len], "%n" ); 929 948 int len2 = -1; 930 int args = fmt( is, fmt2, &len2 );931 if ( args != -1&& len2 == -1 ) throwResume ExceptionInst( missing_data );949 fmt( is, fmtstr, &len2 ); 950 if ( ! eof( is ) && len2 == -1 ) throwResume ExceptionInst( missing_data ); 932 951 return is; 933 952 } // ?|? … … 963 982 forall( istype & | basic_istream( istype ) ) { 964 983 istype & ?|?( istype & is, _Istream_Cskip f ) { 965 // printf( "skip %s %d\n", f.scanset, f.wd);984 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 966 985 if ( f.scanset ) { 967 986 int nscanset = strlen(f.scanset); … … 971 990 strcpy( &fmtstr[pos], f.scanset ); pos += nscanset; 972 991 strcpy( &fmtstr[pos], "]" ); 973 fmt( is, fmtstr, "" ); // skip scanset 992 fmt( is, fmtstr, "" ); // skip scanset, zero or more 974 993 } else { 975 994 char ch; 976 // fprintf( stderr, "skip " );977 995 for ( f.wd ) { // skip N characters 978 if ( eof( is ) ) break; 979 fmt( is, "%c", &ch ); 980 // fprintf( stderr, "`%c' ", ch ); 996 int args = fmt( is, "%c", &ch ); 997 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 981 998 } // for 982 999 } // if … … 985 1002 986 1003 istype & ?|?( istype & is, _Istream_Cquoted f ) with( f.cstr ) { 1004 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 987 1005 int args; 988 1006 fini: { 989 args = fmt( is, "%*[ \f\n\r\t\v]" ); // remove leading whitespace 990 if ( eof( is ) ) break fini; 991 char rfmt[4] = { delimiters[0], '%', 'n', '\0' }; 992 int len = 0; // may not be set in fmt 993 args = fmt( is, rfmt, &len ); // remove leading quote 994 if ( len == 0 || eof( is ) ) break fini; 1007 char rfmt[5] = { ' ', delimiters[0], '%', 'n', '\0' }; 1008 int len = -1; // may not be set in fmt 1009 args = fmt( is, rfmt, &len ); // remove leading whitespace and quote 1010 if ( eof( is ) || len == -1 ) break fini; 995 1011 996 1012 // Change the remainder of the read into a getline by reseting the closing delimiter. … … 1011 1027 1012 1028 istype & ?|?( istype & is, _Istream_Cstr f ) with( f.cstr ) { 1029 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 1013 1030 const char * scanset; 1014 1031 size_t nscanset = 0; … … 1046 1063 fmt( is, "%c", &peek ); // check for whitespace terminator 1047 1064 // fprintf( stderr, "peek %d '%c'\n", args, peek ); 1048 if ( ! eof( is ) ) { 1065 if ( ! eof( is ) ) { // can only fail at eof 1049 1066 ungetc( is, peek ); 1050 1067 if ( ! isspace( peek ) ) throwResume ExceptionInst( cstring_length ); … … 1056 1073 if ( flags.delimiter ) { // getline 1057 1074 int len = 0; // may not be set in fmt 1058 if ( delimiters[2] != '\0' ) { // read single character ?1075 if ( delimiters[2] != '\0' ) { // (quoted) read single character ? 1059 1076 sprintf( &fmtstr[pos], "c%%n" ); 1060 1077 } else { … … 1063 1080 if ( flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*' 1064 1081 else args = fmt( is, fmtstr, s, &len ); 1082 1083 // cannot have empty character constant '' 1084 if ( delimiters[2] != '\0' && len != 1 ) throwResume ExceptionInst( missing_data ); 1085 1065 1086 if ( check && len == rwd && ! eof( is ) ) { // might not fit 1066 1087 char peek; … … 1096 1117 } // if 1097 1118 if ( args == 1 && eof( is ) ) { // data but scan ended at EOF 1098 // fprintf( stderr, "clear\n" );1099 1119 clear( is ); // => reset EOF => detect again on next read 1100 1120 } // if
Note: See TracChangeset
for help on using the changeset viewer.