mirror of
https://github.com/zoriya/xmlParser.git
synced 2026-06-07 19:50:33 +00:00
Adding float suppotr
This commit is contained in:
@@ -12,7 +12,8 @@ SRC = src/xmlparser.c \
|
|||||||
src/xmlproperties.c \
|
src/xmlproperties.c \
|
||||||
src/rawnode.c \
|
src/rawnode.c \
|
||||||
src/xml_destroy.c \
|
src/xml_destroy.c \
|
||||||
src/xmlget.c
|
src/xmlget.c \
|
||||||
|
src/floatutils.c
|
||||||
|
|
||||||
OBJ = $(SRC:%.c=%.o)
|
OBJ = $(SRC:%.c=%.o)
|
||||||
|
|
||||||
@@ -60,8 +61,11 @@ fclean: clean
|
|||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
dbg: CFLAGS += -g
|
dbg: CFLAGS += -g
|
||||||
dbg: fclean
|
dbg: re
|
||||||
dbg: $(OBJ)
|
|
||||||
|
main-dbg: CFLAGS += -g
|
||||||
|
main-dbg: fclean
|
||||||
|
main-dbg: $(OBJ)
|
||||||
$(CC) -o $(FT) $(SRC) $(TEST_MAIN) $(CFLAGS) $(LDFLAGS)
|
$(CC) -o $(FT) $(SRC) $(TEST_MAIN) $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
.PHONY: all build clean fclean
|
.PHONY: all build clean fclean
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ int xml_getstringdata(node *n, char **nodestr);
|
|||||||
int xml_checkclosing(node *n, char **nodestr);
|
int xml_checkclosing(node *n, char **nodestr);
|
||||||
dictionary *property_add(dictionary *list, dictionary *property);
|
dictionary *property_add(dictionary *list, dictionary *property);
|
||||||
node *xml_parsenode(char **nodestr);
|
node *xml_parsenode(char **nodestr);
|
||||||
|
int get_int_size(int n);
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
** EPITECH PROJECT, 2019
|
||||||
|
** MUL_my_runner_2019
|
||||||
|
** File description:
|
||||||
|
** floatutils
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "my.h"
|
||||||
|
|
||||||
|
int get_int_size(int n)
|
||||||
|
{
|
||||||
|
int base_size = my_strlen("0123456789");
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
while (n >= base_size) {
|
||||||
|
n /= base_size;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
|
#include "xml_internal.h"
|
||||||
#include "my.h"
|
#include "my.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -30,9 +31,21 @@ int xml_getintprop(node *n, const char *key)
|
|||||||
float xml_getfloatprop(node *n, const char *key)
|
float xml_getfloatprop(node *n, const char *key)
|
||||||
{
|
{
|
||||||
char *prop = xml_getproperty(n, key);
|
char *prop = xml_getproperty(n, key);
|
||||||
|
float nbr;
|
||||||
|
int deci;
|
||||||
|
|
||||||
if (!prop)
|
if (!prop)
|
||||||
return (0);
|
return (0);
|
||||||
|
for (int i = 0; prop[i]; i++) {
|
||||||
|
if (!is_num(prop[i]))
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
nbr = (float)my_getnbr(prop);
|
||||||
|
prop += get_int_size(nbr);
|
||||||
|
if (*prop) {
|
||||||
|
deci = my_getnbr(prop + 1);
|
||||||
|
nbr += deci / (float)(get_int_size(deci) + 1);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user