diff --git a/CoreLib/Makefile b/CoreLib/Makefile index 74159a8..cb74d68 100644 --- a/CoreLib/Makefile +++ b/CoreLib/Makefile @@ -5,7 +5,7 @@ BUILD_DIR = ../build/CoreLib OBJ_FOLDER = ../bin/CoreLib OUTPUTFILE = $(BUILD_DIR)/libCoreLib.a -OFILES = $(OBJ_FOLDER)/memory.o $(OBJ_FOLDER)/path.o $(OBJ_FOLDER)/stack.o $(OBJ_FOLDER)/string.o $(OBJ_FOLDER)/stringview.o +OFILES = $(OBJ_FOLDER)/ctype.o $(OBJ_FOLDER)/memory.o $(OBJ_FOLDER)/path.o $(OBJ_FOLDER)/stack.o $(OBJ_FOLDER)/string.o $(OBJ_FOLDER)/stringview.o .phony: all all: $(OUTPUTFILE) @@ -15,6 +15,11 @@ $(OUTPUTFILE): $(OFILES) pwd ar -rc $(OUTPUTFILE) $(OFILES) + + +$(OBJ_FOLDER)/ctype.o: ctype.cpp + $(CPP) -c ctype.cpp -o $(OBJ_FOLDER)/ctype.o $(CFLAGS) + $(OBJ_FOLDER)/memory.o: Memory.cpp $(CPP) -c Memory.cpp -o $(OBJ_FOLDER)/memory.o $(CFLAGS) diff --git a/CoreLib/ctype.cpp b/CoreLib/ctype.cpp new file mode 100644 index 0000000..2c81ade --- /dev/null +++ b/CoreLib/ctype.cpp @@ -0,0 +1,141 @@ +// +// Created by nigel on 25/02/23. +// +#include "ctype.h" + +int isupper (int ch){ + if( ch >= 'A' && ch <= 'Z'){ + return 1; + } + return 0; +} +int islower (int ch){ + if(ch >= 'a' && ch <= 'z'){ + return 1; + } + return 0; +} + +int isalpha (int ch) { + if(isupper(ch)){ + return 1; + } + if(islower(ch)){ + return 1; + } + return 0; +} +int isdigit (int ch){ + if(ch >= '0' && ch <= '9'){ + return 1; + } + return 0; +} + +int isxdigit (int ch){ + if(isdigit(ch)){ + return 1; + } + + if( ch >= 'a' && ch <= 'f'){ + return 1; + } + + if( ch >= 'A' && ch <= 'F'){ + return 1; + } + return 0; +} + +int iscntrl (int ch){ + if(ch >= 0x00 && ch <= 0x1f ) + return 1; + if(ch == 0x7f) + return 1; + return 0; +} + + +int isgraph (int ch){ + if(isdigit(ch)) + return 1; + if(isupper(ch)) + return 1; + if(islower(ch)) + return 1; + if(ispunct(ch)) + return 1; + return 0; +} + +int isspace(int ch){ + if (ch == 0x20) + return 1; + if(ch == 0x0c) + return 1; + if(ch == 0x0a) + return 1; + if(ch == 0x0d) + return 1; + if(ch == 0x09) + return 1; + if(ch == 0x0b) + return 1; + + return 0; +} + +int isblank (int ch){ + if( ch == 0x20 || ch == 0x09) + return 1; + return 0; +} + +int ispunct(int ch){ + if(ch >= '!' && ch <= '~') + return 1; + return 0; +} + +int isprint (int ch){ + if (isdigit(ch)) + return 1; + if(isupper(ch)) + return 1; + if(islower(ch)) + return 1; + if(ispunct(ch)) + return 1; + if(isspace(ch)) + return 1; + +} + + +int tolower(int ch){ + + if(islower(ch)) return ch; + int diff = 'a' - 'A'; + return ch + diff; +} + +int toupper(int ch){ + if(isupper(ch)) return ch; + int diff = 'a' - 'A'; + return ch - diff; +} + + + +int isalnum (int ch){ + if(isdigit(ch)){ + return 1; + } + + if(isalpha(ch)){ + return 1; + } + + return 0; + +} \ No newline at end of file diff --git a/CoreLib/ctype.h b/CoreLib/ctype.h new file mode 100644 index 0000000..43262d6 --- /dev/null +++ b/CoreLib/ctype.h @@ -0,0 +1,21 @@ +// +// Created by nigel on 25/02/23. +// +#pragma once + +//NOTE: Uses default locale +int isupper (int ch); +int islower (int ch); +int isalpha (int ch); +int isdigit (int ch); +int isxdigit (int ch); +int iscntrl (int ch); +int isgraph(int ch); +int isspace(int ch); +int isblank(int ch); +int ispunct(int ch); +int isprint(int ch); +int isalnum (int ch); +int tolower(int ch); +int toupper(int ch); +