diff --git a/include/xml_internal.h b/include/xml_internal.h index 910705a..09f053a 100644 --- a/include/xml_internal.h +++ b/include/xml_internal.h @@ -11,4 +11,5 @@ void xml_fillclosing_br(char *buffer, const char *name); char *xml_getname(char **nodestr, bool *has_parameters, bool *has_childs); -dictionary *xml_getproperties(char **nodestr, bool *can_have_child); \ No newline at end of file +dictionary *xml_getproperties(char **nodestr, bool *can_have_child); +char *trimstr(char *str); \ No newline at end of file diff --git a/src/helper.c b/src/helper.c index e946bf6..7cb1157 100644 --- a/src/helper.c +++ b/src/helper.c @@ -6,6 +6,7 @@ */ #include "my.h" +#include void xml_fillclosing_br(char *buffer, const char *name) { @@ -17,4 +18,24 @@ void xml_fillclosing_br(char *buffer, const char *name) my_strcat(buffer, name); buffer[i] = '>'; buffer[i + 1] = '\0'; +} + +char *trimstr(char *str) +{ + int len = 0; + char *trimed; + + for (int i = 0; str[i]; i++) { + if (str[i] != '\t' && str[i] != '\n' && str[i] != '\r') + len++; + } + trimed = malloc(sizeof(char) * (len + 1)); + len = 0; + for(int i = 0; str[i]; i++) { + if (str[i] != '\t' && str[i] != '\n' && str[i] != '\r') { + trimed[len] = str[i]; + len++; + } + } + return (trimed); } \ No newline at end of file diff --git a/src/xmlparser.c b/src/xmlparser.c index f14f3d3..f1af649 100644 --- a/src/xmlparser.c +++ b/src/xmlparser.c @@ -7,6 +7,7 @@ #include "my.h" #include "xml.h" +#include "xml_internal.h" #include #include #include @@ -47,13 +48,7 @@ node *xml_parsestr(char *nodestr) if (nodestr[i] == ' ' && !is_space_usefull(nodestr, i)) nodestr[i] = '\t'; } - for (int i = 0; nodestr[i]; i++) { - if (nodestr[i] == '\t' || nodestr[i] == '\n' || nodestr[i] == '\r') { - nodestr[i] = nodestr[i + 1]; - nodestr[i + 1] = '\t'; - i = 0; - } - } + nodestr = trimstr(nodestr); n = xml_parsenode(&nodestr); free(strconst); return (n); diff --git a/tests/testprolog.txt b/tests/testprolog.txt index a62ab77..69e7354 100644 --- a/tests/testprolog.txt +++ b/tests/testprolog.txt @@ -1,2 +1,4 @@ - \ No newline at end of file + + + \ No newline at end of file