X-Git-Url: https://git.llucax.com/z.facultad/75.42/calculadora.git/blobdiff_plain/0f0090fd999b6194842cbff05ee4f93d69c43000..8f5992a5811ef292022a3ca3ac293c231e2b065b:/strutil.c diff --git a/strutil.c b/strutil.c index 48ec6f2..8a84d43 100644 --- a/strutil.c +++ b/strutil.c @@ -15,6 +15,7 @@ */ #include "strutil.h" +#include "parser_common.h" #include #include @@ -28,7 +29,24 @@ char* strutil_copy_fragment(const char* orig, size_t start, size_t len) { strncpy(new, orig + start, len); /* Termino la cadena. */ new[len] = '\0'; - /* Si no pude reservar la memoria, devuelvo NULL. */ + } + return new; +} + +char* strutil_copy_stripspaces(const char* orig, size_t len) { + size_t i = 0; + size_t j = 0; + /* Reservo el espacio (incluyendo el caracter nulo). */ + char* new = malloc(sizeof(char) * (len + 1)); + if (new) { + /* Copio caracteres que no sean espacios. */ + for (i = 0; i < len; i++) { + if (!is_space(orig[i])) { + new[j++] = orig[i]; + } + } + /* Termino la cadena. */ + new[j] = '\0'; } return new; }