mirror of
https://github.com/bigsketti/cshell.git
synced 2025-06-07 05:14:47 +00:00
added number tokenizer function
This commit is contained in:
parent
3e1957abb1
commit
efa8fe907a
38
handleJSON.c
38
handleJSON.c
@ -26,22 +26,44 @@ typedef struct Token {
|
|||||||
char value[100];
|
char value[100];
|
||||||
} Token;
|
} Token;
|
||||||
|
|
||||||
void advancePosition(int *pos, char *currentChar, char *input[]) {
|
void advancePosition(int *pos, char **currentChar, char *input[]) {
|
||||||
if(pos < sizeof(input)) {
|
(*pos++);
|
||||||
currentChar = input[*pos];
|
if(*pos < sizeof(input)) {
|
||||||
printf("Advancing to %s at position %s", currentChar, *pos);
|
*currentChar = &input[*pos];
|
||||||
|
printf("Advancing to %s at position %s", **currentChar, *pos);
|
||||||
} else {
|
} else {
|
||||||
currentChar = "\0";
|
*currentChar = "\0";
|
||||||
printf("End of Input");
|
printf("End of Input");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void skipWhiteSpace(int *pos, char currentChar) {
|
void skipWhiteSpace(int *pos, char **currentChar, char *input) {
|
||||||
if (currentChar != "\0" && is_space(currentChar) == true) {
|
if (**currentChar != "\0" && is_space(**currentChar)) {
|
||||||
pos++;
|
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() {
|
void tokenizeJSON() {
|
||||||
// TODO: finish this after token type functions
|
// TODO: finish this after token type functions
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user