From a81ee1d982f85883bc5c0db80a51238e86cd0781 Mon Sep 17 00:00:00 2001 From: dtb Date: Tue, 21 Jun 2022 11:33:16 -0400 Subject: [PATCH] libstr sux --- lib/libstr.c | 90 ---------------------------------------------------- lib/libstr.h | 10 ------ 2 files changed, 100 deletions(-) delete mode 100644 lib/libstr.c delete mode 100644 lib/libstr.h diff --git a/lib/libstr.c b/lib/libstr.c deleted file mode 100644 index fcaebd4..0000000 --- a/lib/libstr.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "libstr.h" - -/* Use strchr in */ -/* char *charin(char c, char *str){ return strchr(str, c); } */ -/* size_t charindex(char c, char *str){ return strchr(str, c) - str; } */ -/* bool charisin(char c, char *str){ return strchr(str, c) == NULL; } */ - -/* lower bound is a limitation of mathematics, - * upper bound is controlled by how many digits are defined - * in the header */ -#define CHECKBASE(b) ((b) >= 2 && base < (sizeof(ASCII_DIGITS_LOWER) / sizeof(*ASCII_DIGITS_LOWER)) - -int * -strtonumb(char *s, enum Strtype t, void *n, int base){ - int i; - int polarity; - int retval; - retval = 0; - while(*s != '\0'){ - if(!CHECKBASE(base)) - return NULL; - /* assume *s is in ASCII_DIGITS_LOWER or ASCII_DIGITS_UPPER */ - for(i = 0; i < base; ++i) - if(ASCII_DIGITS_LOWER[i] == *s - || ASCII_DIGITS_UPPER == *s){ - retval = retval * 10 + i; - break; - } - if(i == base) - return NULL; - ++s; - } - *n = retval; - return n; -} - -int -stris(enum Strtype t, char *s){ - return strisb(t, s, 10); -} - -int -strisb(enum Strtype t, char *s, int base) -{ - int retval; - retval = 0; - - int i; - - if(!CHECKBASE(base)) - return -1; - - /* negatives */ - if((t == STRIS_TYPE_FLOAT || t == STRIS_TYPE_INT) && *s == '-'){ - ++s; - if(t == STRIS_TYPE_INT) - t = STRIS_TYPE_UINT; - } - - while(*s != '\0') - switch(t){ - case STRIS_TYPE_FLOAT: - if(*s == '.'){ - ++s; - t = STRIS_TYPE_UINT; - break; - } - /* FALLTHROUGH */ - default: - for(i = 0; i < base; ++i) - if(ASCII_DIGITS_LOWER[i] == *s - || ASCII_DIGITS_UPPER[i] == *s){ - retval = 1; - break; - } - if(i == base) - return 0; - ++s; - } - return retval; -} - -/* -int -strisb(enum Strtype t, char *s, int base){ - int n; - return !(strtonumb(s, t, &n, base) == NULL); -} -*/ - diff --git a/lib/libstr.h b/lib/libstr.h deleted file mode 100644 index 89376f4..0000000 --- a/lib/libstr.h +++ /dev/null @@ -1,10 +0,0 @@ -#include "ascii.h" - -enum Strtype{ - STRIS_TYPE_UINT = 1, - STRIS_TYPE_INT, - STRIS_TYPE_FLOAT -}; - -int strisb(enum Strtype t, char *str, int base); -int stris(enum Strtype t, char *str);