diff --git a/.gitignore b/.gitignore index d4e0bd6..f2714f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.DS_Store +.S_Store .vagrant build Vagrantfile @@ -12,3 +12,6 @@ xunit.xml *._cpp *.hpp_ *._hpp +libft.h +libft.a +objectif diff --git a/src/reactive/uri/main.cpp b/src/reactive/uri/main.cpp new file mode 100644 index 0000000..ce809b2 --- /dev/null +++ b/src/reactive/uri/main.cpp @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwells +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2015/11/11 14:09:44 by gwells #+# #+# */ +/* Updated: 2015/11/11 14:29:51 by gwells ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "query2.hpp" +#include +#include "libft.h" + +typedef void (*ptrfunc)(void *, size_t); +void dellist(void *, size_t); + +typedef struct s_content +{ + char *path; + char *value; +} t_content; + +int main(int argc, char **argv) +{ + if (argc != 2) + ft_quit("Enter one argument Pls", 2, EXIT_FAILURE); + + query test; + t_list *lst; + + ptrfunc delfunc; + + delfunc = dellist; + + lst = test.parse(argv[1]); + ft_lstdel(&lst, delfunc); + return (0); +} + +void dellist(void* content, size_t size) +{ + t_content *tmp; + + tmp = (t_content*)content; + free(tmp->path); + free(tmp->value); + free(content); +} diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp new file mode 100644 index 0000000..a10c74c --- /dev/null +++ b/src/reactive/uri/query2.cpp @@ -0,0 +1,117 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* query2.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwells +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2015/11/11 12:40:21 by gwells #+# #+# */ +/* Updated: 2015/11/11 17:47:49 by gwells ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "query2.hpp" +#include +#include + +void query::printlist(t_list *lst) +{ + t_content *content; + + while(lst) + { + content = (t_content*)lst->content; + printf("Voici le path %s\n", content->path); + printf("Voici la value %s\n",content->value); + lst = lst->next; + } +} + +t_list *query::parse(const char *query) +{ + t_list *begin; + t_list *node; + char *path; + char *value; + const char *error; + bool flag; + bool count; + t_content content; + + + error = "Bad syntax"; + count = false; + begin = NULL; + path = ft_strdup(""); + value = ft_strdup(""); + + while (*query) + { + flag = false; + if (*query != '[' && *query != '=') + path = changeString(path, ft_append_char(path, *query)); + if (*query == '[') + { + if (*(query + 1) == ']') + { + path = changeString(path, ft_strjoin(path, ":index")); + query+=2; + if (*query != '=') + ft_quit(error, 2, EXIT_FAILURE); + } + else + { + if (*(query + 1) != '\'' && *(query + 1) != '\"') + ft_quit(error, 2, EXIT_FAILURE); + else + { + query+=2; + path = changeString(path, ft_append_char(path, ':')); + while (*query && *query != ']') + { + path = changeString(path, ft_append_char(path, *query)); + query++; + } + if (!*query || (*(query - 1) != '\'' && *(query - 1) != '\"') + || (*(query + 1) != '=' && *(query + 1) != '[' && *(query + 1))) + ft_quit(error, 2, EXIT_FAILURE); + path[ft_strlen(path) - 1] = '\0'; + path = changeString(path, ft_strdup(path)); + } + } + flag = true; + } + if (*query == '=') + { + query++; + while(*query && *query != '&') + { + value = changeString(value, ft_append_char(value, *query)); + query++; + } + content.path = ft_strdup(path); + content.value = ft_strdup(value); + node = ft_lstnew(&content, sizeof(content)); + ft_lstpushback(&begin, node); + ft_strdel(&path); + ft_strdel(&value); + path = ft_strdup(""); + value = ft_strdup(""); + } + if (*query && flag) + query++; + if (*query && !flag) + query++; + } + printlist(begin); + ft_strdel(&path); + ft_strdel(&value); + return (begin); +} + +char *query::changeString(char *old, char *ret) +{ + ft_strdel(&old); + return(ret); +} diff --git a/src/reactive/uri/query2.hpp b/src/reactive/uri/query2.hpp new file mode 100644 index 0000000..8d9f465 --- /dev/null +++ b/src/reactive/uri/query2.hpp @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* query2.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwells +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2015/11/11 12:41:45 by gwells #+# #+# */ +/* Updated: 2015/11/11 15:39:51 by gwells ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +class query +{ + private: + typedef struct s_content + { + char *path; + char *value; + } t_content; + + /** + * Debug function + */ + void printlist(t_list* lst); + char *changeString(char* old, char *ret); + + public: + + query() {} + /** + * Parse the content and put it in linked list + */ + t_list *parse(const char *query); + +}; diff --git a/test_suite/reactive/uri/iteratif.cpp b/test_suite/reactive/uri/iteratif.cpp new file mode 100644 index 0000000..e69de29