Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DS_Store
.S_Store
.vagrant
build
Vagrantfile
Expand All @@ -12,3 +12,6 @@ xunit.xml
*._cpp
*.hpp_
*._hpp
libft.h
libft.a
objectif
51 changes: 51 additions & 0 deletions src/reactive/uri/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwells <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/11 14:09:44 by gwells #+# #+# */
/* Updated: 2015/11/11 14:29:51 by gwells ### ########.fr */
/* */
/* ************************************************************************** */

#include "query2.hpp"
#include <stdlib.h>
#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);
}
117 changes: 117 additions & 0 deletions src/reactive/uri/query2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* query2.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwells <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
#include <stdio.h>

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);
}
38 changes: 38 additions & 0 deletions src/reactive/uri/query2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* query2.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwells <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

};
Empty file.