diff --git a/Makefile b/Makefile index 58b24dd..5076871 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ SRC = src/xmlparser.c \ src/rawnode.c \ src/xml_destroy.c \ src/xmlget.c \ + src/strangeget.c \ src/floatutils.c \ src/child.c diff --git a/include/my.h b/include/my.h index ff846ba..dfd923f 100644 --- a/include/my.h +++ b/include/my.h @@ -6,6 +6,8 @@ */ #pragma once +int my_str_islower_or_num(const char *str); + int count_valid_queens_placements(int n); char *my_strchr(char *str, char c); diff --git a/include/xml.h b/include/xml.h index bb769dd..32c5bf5 100644 --- a/include/xml.h +++ b/include/xml.h @@ -31,6 +31,8 @@ node *xml_parse(const char *path); node *xml_getnode(node *parent, const char *name); char *xml_getproperty(node *n, const char *key); int xml_getintprop(node *n, const char *key); +int xml_getbinaprop(node *n, const char *key); +int xml_gethexaprop(node *n, const char *key); float xml_getfloatprop(node *n, const char *key); int xml_getchildcount(node *n); void xml_destroy(node *n); \ No newline at end of file diff --git a/src/strangeget.c b/src/strangeget.c new file mode 100644 index 0000000..7014a6a --- /dev/null +++ b/src/strangeget.c @@ -0,0 +1,34 @@ +/* +** EPITECH PROJECT, 2020 +** Twac +** File description: +** strangeget +*/ + +#include "xml.h" +#include "my.h" + +int xml_gethexaprop(node *n, const char *key) +{ + char *prop = xml_getproperty(n, key); + + if (!prop || my_strlen(prop) == 0) + return (0); + if (prop[0] == '0' && prop[1] == 'x') + prop += 2; + if (my_str_islower_or_num(prop)) + return (my_getnbr_base(prop, "0123456789abcdef")); + else + return (my_getnbr_base(prop, "0123456789ABCDEF")); +} + +int xml_getbinaprop(node *n, const char *key) +{ + char *prop = xml_getproperty(n, key); + + if (!prop || my_strlen(prop) == 0) + return (0); + if (prop[0] == '0' && prop[1] == 'b') + prop += 2; + return (my_getnbr_base(prop, "01")); +} \ No newline at end of file