mirror of
https://github.com/zoriya/xmlParser.git
synced 2026-06-05 10:59:27 +00:00
Helping the user to free
This commit is contained in:
@@ -10,6 +10,9 @@ typedef struct dictionary dictionary;
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct dictionary
|
struct dictionary
|
||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
@@ -29,7 +32,9 @@ struct node
|
|||||||
|
|
||||||
node *xml_parse(const char *path);
|
node *xml_parse(const char *path);
|
||||||
node *xml_getnode(node *parent, const char *name);
|
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_getproperty(node *n, const char *key);
|
||||||
|
char *xml_gettempprop(node *n, const char *key);
|
||||||
int xml_getintprop(node *n, const char *key);
|
int xml_getintprop(node *n, const char *key);
|
||||||
int xml_getbinaprop(node *n, const char *key);
|
int xml_getbinaprop(node *n, const char *key);
|
||||||
int xml_gethexaprop(node *n, const char *key);
|
int xml_gethexaprop(node *n, const char *key);
|
||||||
|
|||||||
+9
-2
@@ -6,11 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
|
#include "xml_internal.h"
|
||||||
#include "my.h"
|
#include "my.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
int xml_gethexaprop(node *n, const char *key)
|
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)
|
if (!prop || my_strlen(prop) == 0)
|
||||||
return (0);
|
return (0);
|
||||||
@@ -24,11 +26,16 @@ int xml_gethexaprop(node *n, const char *key)
|
|||||||
|
|
||||||
int xml_getbinaprop(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)
|
if (!prop || my_strlen(prop) == 0)
|
||||||
return (0);
|
return (0);
|
||||||
if (prop[0] == '0' && prop[1] == 'b')
|
if (prop[0] == '0' && prop[1] == 'b')
|
||||||
prop += 2;
|
prop += 2;
|
||||||
return (my_getnbr_base(prop, "01"));
|
return (my_getnbr_base(prop, "01"));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool xml_hasproperty(node *n, const char *key)
|
||||||
|
{
|
||||||
|
return (xml_gettempprop(n, key) != NULL);
|
||||||
}
|
}
|
||||||
+15
-4
@@ -11,18 +11,29 @@
|
|||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include <stddef.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) {
|
for (dictionary *prop = n->properties; prop; prop = prop->next) {
|
||||||
if (!my_strcmp(key, prop->key))
|
if (!my_strcmp(key, prop->key))
|
||||||
return (my_strdup(prop->value));
|
return (prop->value);
|
||||||
}
|
}
|
||||||
return (NULL);
|
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)
|
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)
|
if (!prop || my_strlen(prop) == 0)
|
||||||
return (0);
|
return (0);
|
||||||
@@ -31,7 +42,7 @@ 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_gettempprop(n, key);
|
||||||
float nbr;
|
float nbr;
|
||||||
int deci;
|
int deci;
|
||||||
|
|
||||||
|
|||||||
+15
-2
@@ -29,11 +29,24 @@ int xml_handle_prolog(char **nodestr)
|
|||||||
return (0);
|
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)
|
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);
|
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 (false);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user