skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

fmtscan_num.c (364B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/fmtscan.h>
      4 
      5 unsigned char fmtscan_num (unsigned char c, unsigned char n)
      6 {
      7   return
      8     ((c < '0') || (n > 36)) ? n :
      9     (n <= 10) ? (c - '0' <= n) ? c - '0' : n :
     10     (c - '0' <= 9) ? c - '0' :
     11     (c < 'A') ? n :
     12     (c - 'A' < n - 10) ? c - 'A' + 10 :
     13     (c < 'a') ? n :
     14     (c - 'a' < n - 10) ? c - 'a' + 10 :
     15     n ;
     16 }