Added ctype std lib functions

This commit is contained in:
Nigel Barink 2023-02-25 20:41:21 +01:00
parent 745656eb2d
commit 32b0d990df
3 changed files with 168 additions and 1 deletions

View File

@ -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)

141
CoreLib/ctype.cpp Normal file
View File

@ -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;
}

21
CoreLib/ctype.h Normal file
View File

@ -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);