8-9/10... inconsistent book tests persist
This commit is contained in:
@@ -17,4 +17,49 @@ typedef enum
|
||||
UNSUPPORTED,
|
||||
} TYPE;
|
||||
|
||||
char *sanitize_input(char *input){
|
||||
if(!input) return NULL;
|
||||
|
||||
int i = 0;
|
||||
|
||||
char *ret = malloc(sizeof(char));
|
||||
if(!ret){
|
||||
// perror("[MAIN - sanitize_input] Failed to allocate memory for ret");
|
||||
return NULL;
|
||||
}
|
||||
*ret = '\0';
|
||||
|
||||
char *it = input;
|
||||
while(*it && !isalpha(*it)) it++;
|
||||
|
||||
bool writeSpace = false;
|
||||
while(*it){
|
||||
if(isalpha(*it)){
|
||||
char *tmp = NULL;
|
||||
if(writeSpace){
|
||||
tmp = realloc(ret, i + 3);
|
||||
}
|
||||
else{
|
||||
tmp = realloc(ret, i + 2);
|
||||
}
|
||||
if(!tmp){
|
||||
// perror("[MAIN - sanitize_input] Failed to realloc memory for ret");
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
ret = tmp;
|
||||
if(writeSpace) ret[i++] = ' ';
|
||||
ret[i++] = tolower(*it++);
|
||||
writeSpace = false;
|
||||
}
|
||||
else{
|
||||
it++;
|
||||
writeSpace = true;
|
||||
}
|
||||
}
|
||||
ret[i] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#endif //TRANSFER_DEFINES_H
|
||||
|
||||
Reference in New Issue
Block a user