From efa8fe907aea24af74f30e0f5739a35d70da130e Mon Sep 17 00:00:00 2001 From: bigsketti Date: Sat, 30 Nov 2024 17:00:26 -0500 Subject: [PATCH] added number tokenizer function --- handleJSON.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/handleJSON.c b/handleJSON.c index 533c085..833afab 100644 --- a/handleJSON.c +++ b/handleJSON.c @@ -26,22 +26,44 @@ typedef struct Token { char value[100]; } Token; -void advancePosition(int *pos, char *currentChar, char *input[]) { - if(pos < sizeof(input)) { - currentChar = input[*pos]; - printf("Advancing to %s at position %s", currentChar, *pos); +void advancePosition(int *pos, char **currentChar, char *input[]) { + (*pos++); + if(*pos < sizeof(input)) { + *currentChar = &input[*pos]; + printf("Advancing to %s at position %s", **currentChar, *pos); } else { - currentChar = "\0"; + *currentChar = "\0"; printf("End of Input"); } } -void skipWhiteSpace(int *pos, char currentChar) { - if (currentChar != "\0" && is_space(currentChar) == true) { - pos++; +void skipWhiteSpace(int *pos, char **currentChar, char *input) { + if (**currentChar != "\0" && is_space(**currentChar)) { + advancePosition(pos, currentChar, input); } } +Token number(int *pos, char **currentChar, char *input) { + char value[100] = ""; + int i = 0; + + while (**currentChar != '\0' && isdigit(**currentChar)) { + if (i < sizeof(value) -1) { + value[i++] = **currentChar; + } + advancePosition(pos, currentChar, input); + } + value[i] = '\0'; + + Token token; + token.type = INTEGER; + strcpy(token.value, value, sizeof(value) - 1); + token.value[sizeof(token.value) -1] = '\0'; + + return token; + +} + void tokenizeJSON() { // TODO: finish this after token type functions }