Changeset 8f650f0
- Timestamp:
- Mar 17, 2024, 8:36:08 AM (9 months ago)
- Branches:
- master
- Children:
- 057608a
- Parents:
- 42422fb
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r42422fb r8f650f0 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 15 18:47:28202413 // Update Count : 6 8512 // Last Modified On : Sun Mar 17 08:25:32 2024 13 // Update Count : 699 14 14 // 15 15 … … 21 21 22 22 #include <string.h> // memcpy, memset 23 //#include <math.h> // fabsf, fabs, fabsl24 23 #include <complex.h> // _Complex_I 25 24 #include <assert.h> 26 #include <ctype.h> 25 #include <ctype.h> // isblank 27 26 28 27 #pragma GCC visibility push(default) … … 66 65 //--------------------------------------- 67 66 68 // C annot overload with singular (isspace) counterparts because they are macros.69 70 bool isalnums( const char s[]) {67 // Check if all string characters are a specific kind, e.g., checkif( s, isblank ) 68 69 bool checkif( const char s[], int (* kind)( int ) ) { 71 70 for () { 72 71 if ( *s == '\0' ) return true; 73 if ( ! isalnum( *s ) ) return false;72 if ( ! kind( *s ) ) return false; 74 73 s += 1; 75 74 } // for 76 } // isalnums77 78 bool isalphas( const char s[]) {75 } // checkif 76 77 bool checkif( const char s[], int (* kind)( int, locale_t ), locale_t locale ) { 79 78 for () { 80 79 if ( *s == '\0' ) return true; 81 if ( ! isalpha( *s) ) return false;80 if ( ! kind( *s, locale ) ) return false; 82 81 s += 1; 83 82 } // for 84 } // isblanks 85 86 bool iscntrls( const char s[] ) { 87 for () { 88 if ( *s == '\0' ) return true; 89 if ( ! iscntrl( *s ) ) return false; 90 s += 1; 91 } // for 92 } // iscntrls 93 94 bool isdigits( const char s[] ) { 95 for () { 96 if ( *s == '\0' ) return true; 97 if ( ! isdigit( *s ) ) return false; 98 s += 1; 99 } // for 100 } // isdigits 101 102 bool isgraphs( const char s[] ) { 103 for () { 104 if ( *s == '\0' ) return true; 105 if ( ! isgraph( *s ) ) return false; 106 s += 1; 107 } // for 108 } // isgraphs 109 110 bool islowers( const char s[] ) { 111 for () { 112 if ( *s == '\0' ) return true; 113 if ( ! islower( *s ) ) return false; 114 s += 1; 115 } // for 116 } // islowers 117 118 bool isprints( const char s[] ) { 119 for () { 120 if ( *s == '\0' ) return true; 121 if ( ! isprint( *s ) ) return false; 122 s += 1; 123 } // for 124 } // isprints 125 126 bool ispuncts( const char s[] ) { 127 for () { 128 if ( *s == '\0' ) return true; 129 if ( ! ispunct( *s ) ) return false; 130 s += 1; 131 } // for 132 } // ispuncts 133 134 bool isspaces( const char s[] ) { 135 for () { 136 if ( *s == '\0' ) return true; 137 if ( ! isspace( *s ) ) return false; 138 s += 1; 139 } // for 140 } // isspaces 141 142 bool isblanks( const char s[] ) { 143 for () { 144 if ( *s == '\0' ) return true; 145 if ( ! isblank( *s ) ) return false; 146 s += 1; 147 } // for 148 } // isblanks 149 150 bool isuppers( const char s[] ) { 151 for () { 152 if ( *s == '\0' ) return true; 153 if ( ! isupper( *s ) ) return false; 154 s += 1; 155 } // for 156 } // isuppers 157 158 bool isxdigits( const char s[] ) { 159 for () { 160 if ( *s == '\0' ) return true; 161 if ( ! isxdigit( *s ) ) return false; 162 s += 1; 163 } // for 164 } // isxdigits 83 } // checkif 165 84 166 85 //--------------------------------------- … … 225 144 if ( errno == ERANGE ) throw ExceptionInst( out_of_range ); 226 145 if ( eptr == sptr || // conversion failed, no characters generated 227 eptr[0] != '\0' && ! isspaces( eptr) ) throw ExceptionInst( invalid_argument ); // not at end of blank str ?146 eptr[0] != '\0' && ! checkif( eptr, isblank ) ) throw ExceptionInst( invalid_argument ); // not at end of blank str ? 228 147 return val; 229 148 } // convert … … 236 155 if ( errno == ERANGE ) throw ExceptionInst( out_of_range ); 237 156 if ( eptr == sptr || // conversion failed, no characters generated 238 eptr[0] != '\0' && ! isspaces( eptr) ) throw ExceptionInst( invalid_argument ); // not at end of blank str ?157 eptr[0] != '\0' && ! checkif( eptr, isblank ) ) throw ExceptionInst( invalid_argument ); // not at end of blank str ? 239 158 return val; 240 159 } // convert -
libcfa/src/stdlib.hfa
r42422fb r8f650f0 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 15 18:47:26202413 // Update Count : 79 212 // Last Modified On : Sun Mar 17 08:25:31 2024 13 // Update Count : 796 14 14 // 15 15 … … 293 293 //--------------------------------------- 294 294 295 // Cannot overload with singular (isspace) counterparts because they are macros. 296 297 bool isalnums( const char s[] ); 298 bool isalphas( const char s[] ); 299 bool iscntrls( const char s[] ); 300 bool isdigits( const char s[] ); 301 bool isgraphs( const char s[] ); 302 bool islowers( const char s[] ); 303 bool isprints( const char s[] ); 304 bool ispuncts( const char s[] ); 305 bool isspaces( const char s[] ); 306 bool isblanks( const char s[] ); 307 bool isuppers( const char s[] ); 308 bool isxdigits( const char s[] ); 295 // Check if all string characters are a specific kind, e.g., checkif( s, isblank ) 296 bool checkif( const char s[], int (* kind)( int ) ); 297 bool checkif( const char s[], int (* kind)( int, locale_t ), locale_t locale ); 309 298 310 299 //---------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.