Helping the user to free

This commit is contained in:
Anonymus Raccoon
2020-01-11 17:53:14 +01:00
parent 29f8d8b910
commit e060848bef
4 changed files with 44 additions and 8 deletions
+5
View File
@@ -10,6 +10,9 @@ typedef struct dictionary dictionary;
#pragma once
#include <stddef.h>
#include <stdbool.h>
struct dictionary
{
char *key;
@@ -29,7 +32,9 @@ struct node
node *xml_parse(const char *path);
node *xml_getnode(node *parent, const char *name);
bool xml_hasproperty(node *n, const char *key);
char *xml_getproperty(node *n, const char *key);
char *xml_gettempprop(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);
+9 -2
View File
@@ -6,11 +6,13 @@
*/
#include "xml.h"
#include "xml_internal.h"
#include "my.h"
#include <stddef.h>
int xml_gethexaprop(node *n, const char *key)
{
char *prop = xml_getproperty(n, key);
char *prop = xml_gettempprop(n, key);
if (!prop || my_strlen(prop) == 0)
return (0);
@@ -24,11 +26,16 @@ int xml_gethexaprop(node *n, const char *key)
int xml_getbinaprop(node *n, const char *key)
{
char *prop = xml_getproperty(n, key);
char *prop = xml_gettempprop(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"));
}
bool xml_hasproperty(node *n, const char *key)
{
return (xml_gettempprop(n, key) != NULL);
}
+15 -4
View File
@@ -11,18 +11,29 @@
#include "math.h"
#include <stddef.h>
char *xml_getproperty(node *n, const char *key)
char *xml_gettempprop(node *n, const char *key)
{
if (!n)
return (NULL);
for (dictionary *prop = n->properties; prop; prop = prop->next) {
if (!my_strcmp(key, prop->key))
return (my_strdup(prop->value));
return (prop->value);
}
return (NULL);
}
char *xml_getproperty(node *n, const char *key)
{
char *prop = xml_gettempprop(n, key);
if (prop)
return (my_strdup(prop));
return (NULL);
}
int xml_getintprop(node *n, const char *key)
{
char *prop = xml_getproperty(n, key);
char *prop = xml_gettempprop(n, key);
if (!prop || my_strlen(prop) == 0)
return (0);
@@ -31,7 +42,7 @@ int xml_getintprop(node *n, const char *key)
float xml_getfloatprop(node *n, const char *key)
{
char *prop = xml_getproperty(n, key);
char *prop = xml_gettempprop(n, key);
float nbr;
int deci;
+15 -2
View File
@@ -29,11 +29,24 @@ int xml_handle_prolog(char **nodestr)
return (0);
}
bool is_charvalid(char c)
{
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
return (false);
if (c == '"' || c == '\'')
return (false);
if (c == '=')
return (false);
if (c == '>' || c == '<' || c == '/')
return (false);
return (true);
}
bool is_space_usefull(char *nodestr, int i)
{
if (i == 0 || (!is_alphanum(nodestr[i - 1]) && nodestr[i - 1] != '"'))
if (i == 0 || (!is_charvalid(nodestr[i - 1]) && nodestr[i - 1] != '"'))
return (false);
if (i + 1 == my_strlen(nodestr) || !is_alphanum(nodestr[i + 1]))
if (i + 1 == my_strlen(nodestr) || !is_charvalid(nodestr[i + 1]))
return (false);
return (true);
}