Fixed some bugs in the string tokenizer.
This commit is contained in:
+23
-8
@@ -44,13 +44,14 @@ List* TokenizeLine(char *line) {
|
|||||||
if (line[0] == ';') return NULL;
|
if (line[0] == ';') return NULL;
|
||||||
|
|
||||||
char* token = SplitOnWhiteSpace(line);
|
char* token = SplitOnWhiteSpace(line);
|
||||||
|
|
||||||
while (strlen(token) != 0) {
|
while (strlen(token) != 0) {
|
||||||
printf("Token: '%s'\n", token);
|
printf("'%s' ", token);
|
||||||
//if (token[0] == '"') printf("String token: '%s'\n", token);
|
//if (token[0] == '"') printf("String token: '%s'\n", token);
|
||||||
free(token);
|
free(token);
|
||||||
token = SplitOnWhiteSpace(NULL);
|
token = SplitOnWhiteSpace(NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
//free(currentWord);
|
//free(currentWord);
|
||||||
free(token);
|
free(token);
|
||||||
|
|
||||||
@@ -70,16 +71,30 @@ char* SplitOnWhiteSpace(char* line) {
|
|||||||
int parsing_string = 0;
|
int parsing_string = 0;
|
||||||
|
|
||||||
for (int i = 0; position < strlen(string); i++, position++) {
|
for (int i = 0; position < strlen(string); i++, position++) {
|
||||||
|
|
||||||
|
if (parsing_string) {
|
||||||
|
if (string[position] == '\n') break;
|
||||||
|
|
||||||
|
token[i] = string[position];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string[position] == ';') break;
|
||||||
|
|
||||||
if (string[position] == '"') {
|
if (string[position] == '"') {
|
||||||
parsing_string = 1;
|
parsing_string = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string[position] == ' ' && !parsing_string) {
|
if (string[position] == ' ') {
|
||||||
position++;
|
while(string[position] == ' ') {
|
||||||
break;
|
position++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(token) != 0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string[position] == ',' && !parsing_string) {
|
if (string[position] == ',') {
|
||||||
if (strlen(token) == 0) {
|
if (strlen(token) == 0) {
|
||||||
token[0] = string[position];
|
token[0] = string[position];
|
||||||
position++;
|
position++;
|
||||||
@@ -87,11 +102,11 @@ char* SplitOnWhiteSpace(char* line) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string[position] != '\n') token[i] = string[position];
|
if (string[position] != '\n') token[i] = string[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
token[strlen(token)] = '\0';
|
//token[strlen(token)] = '\0';
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user