From ee923fa82cf60f5287c63e9bcc484a89f50e81ca Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Fri, 9 Dec 2011 23:49:00 +0000 Subject: [PATCH] Make mxmlSet* work like mxmlGet*. --- doc/reference.html | 14 +++++++------- mxml-set.c | 44 +++++++++++++++++++++++++++++++++++++------- mxml.xml | 14 +++++++------- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/doc/reference.html b/doc/reference.html index 4a600ba..907cbff 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -1438,7 +1438,7 @@ int mxmlSetCDATA (

Return Value

0 on success, -1 on failure

Discussion

-

The node is not changed if it is not a CDATA element node. +

The node is not changed if it (or its first child) is not a CDATA element node.

 Mini-XML 2.1 mxmlSetCustom

@@ -1461,7 +1461,7 @@ int mxmlSetCustom (

Return Value

0 on success, -1 on failure

Discussion

-

The node is not changed if it is not a custom node. +

The node is not changed if it (or its first child) is not a custom node.

mxmlSetCustomHandlers

@@ -1530,7 +1530,7 @@ int mxmlSetInteger (

Return Value

0 on success, -1 on failure

Discussion

-

The node is not changed if it is not an integer node.

+

The node is not changed if it (or its first child) is not an integer node.

mxmlSetOpaque

Set the value of an opaque node.

@@ -1548,7 +1548,7 @@ int mxmlSetOpaque (

Return Value

0 on success, -1 on failure

Discussion

-

The node is not changed if it is not an opaque node.

+

The node is not changed if it (or its first child) is not an opaque node.

mxmlSetReal

Set the value of a real number node.

@@ -1566,7 +1566,7 @@ int mxmlSetReal (

Return Value

0 on success, -1 on failure

Discussion

-

The node is not changed if it is not a real number node.

+

The node is not changed if it (or its first child) is not a real number node.

mxmlSetText

Set the value of a text node.

@@ -1587,7 +1587,7 @@ int mxmlSetText (

Return Value

0 on success, -1 on failure

Discussion

-

The node is not changed if it is not a text node.

+

The node is not changed if it (or its first child) is not a text node.

mxmlSetTextf

Set the value of a text node to a formatted string.

@@ -1611,7 +1611,7 @@ int mxmlSetTextf (

Return Value

0 on success, -1 on failure

Discussion

-

The node is not changed if it is not a text node.

+

The node is not changed if it (or its first child) is not a text node.

 Mini-XML 2.7 mxmlSetUserData

Set the user data pointer for a node.

diff --git a/mxml-set.c b/mxml-set.c index a3f040c..9a17b1a 100644 --- a/mxml-set.c +++ b/mxml-set.c @@ -37,7 +37,7 @@ /* * 'mxmlSetCDATA()' - Set the element name of a CDATA node. * - * The node is not changed if it is not a CDATA element node. + * The node is not changed if it (or its first child) is not a CDATA element node. * * @since Mini-XML 2.3@ */ @@ -50,6 +50,12 @@ mxmlSetCDATA(mxml_node_t *node, /* I - Node to set */ * Range check input... */ + if (node && node->type == MXML_ELEMENT && + strncmp(node->value.element.name, "![CDATA[", 8) && + node->child && node->child->type == MXML_ELEMENT && + !strncmp(node->child->value.element.name, "![CDATA[", 8)) + node = node->child; + if (!node || node->type != MXML_ELEMENT || !data || strncmp(node->value.element.name, "![CDATA[", 8)) return (-1); @@ -70,7 +76,7 @@ mxmlSetCDATA(mxml_node_t *node, /* I - Node to set */ /* * 'mxmlSetCustom()' - Set the data and destructor of a custom data node. * - * The node is not changed if it is not a custom node. + * The node is not changed if it (or its first child) is not a custom node. * * @since Mini-XML 2.1@ */ @@ -85,6 +91,10 @@ mxmlSetCustom( * Range check input... */ + if (node && node->type == MXML_ELEMENT && + node->child && node->child->type == MXML_CUSTOM) + node = node->child; + if (!node || node->type != MXML_CUSTOM) return (-1); @@ -135,7 +145,7 @@ mxmlSetElement(mxml_node_t *node, /* I - Node to set */ /* * 'mxmlSetInteger()' - Set the value of an integer node. * - * The node is not changed if it is not an integer node. + * The node is not changed if it (or its first child) is not an integer node. */ int /* O - 0 on success, -1 on failure */ @@ -146,6 +156,10 @@ mxmlSetInteger(mxml_node_t *node, /* I - Node to set */ * Range check input... */ + if (node && node->type == MXML_ELEMENT && + node->child && node->child->type == MXML_INTEGER) + node = node->child; + if (!node || node->type != MXML_INTEGER) return (-1); @@ -162,7 +176,7 @@ mxmlSetInteger(mxml_node_t *node, /* I - Node to set */ /* * 'mxmlSetOpaque()' - Set the value of an opaque node. * - * The node is not changed if it is not an opaque node. + * The node is not changed if it (or its first child) is not an opaque node. */ int /* O - 0 on success, -1 on failure */ @@ -173,6 +187,10 @@ mxmlSetOpaque(mxml_node_t *node, /* I - Node to set */ * Range check input... */ + if (node && node->type == MXML_ELEMENT && + node->child && node->child->type == MXML_OPAQUE) + node = node->child; + if (!node || node->type != MXML_OPAQUE || !opaque) return (-1); @@ -192,7 +210,7 @@ mxmlSetOpaque(mxml_node_t *node, /* I - Node to set */ /* * 'mxmlSetReal()' - Set the value of a real number node. * - * The node is not changed if it is not a real number node. + * The node is not changed if it (or its first child) is not a real number node. */ int /* O - 0 on success, -1 on failure */ @@ -203,6 +221,10 @@ mxmlSetReal(mxml_node_t *node, /* I - Node to set */ * Range check input... */ + if (node && node->type == MXML_ELEMENT && + node->child && node->child->type == MXML_REAL) + node = node->child; + if (!node || node->type != MXML_REAL) return (-1); @@ -219,7 +241,7 @@ mxmlSetReal(mxml_node_t *node, /* I - Node to set */ /* * 'mxmlSetText()' - Set the value of a text node. * - * The node is not changed if it is not a text node. + * The node is not changed if it (or its first child) is not a text node. */ int /* O - 0 on success, -1 on failure */ @@ -231,6 +253,10 @@ mxmlSetText(mxml_node_t *node, /* I - Node to set */ * Range check input... */ + if (node && node->type == MXML_ELEMENT && + node->child && node->child->type == MXML_TEXT) + node = node->child; + if (!node || node->type != MXML_TEXT || !string) return (-1); @@ -251,7 +277,7 @@ mxmlSetText(mxml_node_t *node, /* I - Node to set */ /* * 'mxmlSetTextf()' - Set the value of a text node to a formatted string. * - * The node is not changed if it is not a text node. + * The node is not changed if it (or its first child) is not a text node. */ int /* O - 0 on success, -1 on failure */ @@ -267,6 +293,10 @@ mxmlSetTextf(mxml_node_t *node, /* I - Node to set */ * Range check input... */ + if (node && node->type == MXML_ELEMENT && + node->child && node->child->type == MXML_TEXT) + node = node->child; + if (!node || node->type != MXML_TEXT || !format) return (-1); diff --git a/mxml.xml b/mxml.xml index f5950fd..bf6b520 100644 --- a/mxml.xml +++ b/mxml.xml @@ -1128,7 +1128,7 @@ element tags. Set the element name of a CDATA node. -The node is not changed if it is not a CDATA element node. +The node is not changed if it (or its first child) is not a CDATA element node. @since Mini-XML 2.3@ @@ -1147,7 +1147,7 @@ The node is not changed if it is not a CDATA element node. Set the data and destructor of a custom data node. -The node is not changed if it is not a custom node. +The node is not changed if it (or its first child) is not a custom node. @since Mini-XML 2.1@ @@ -1211,7 +1211,7 @@ The node is not changed if it is not an element node. Set the value of an integer node. -The node is not changed if it is not an integer node. +The node is not changed if it (or its first child) is not an integer node. mxml_node_t * Node to set @@ -1228,7 +1228,7 @@ The node is not changed if it is not an integer node. Set the value of an opaque node. -The node is not changed if it is not an opaque node. +The node is not changed if it (or its first child) is not an opaque node. mxml_node_t * Node to set @@ -1245,7 +1245,7 @@ The node is not changed if it is not an opaque node. Set the value of a real number node. -The node is not changed if it is not a real number node. +The node is not changed if it (or its first child) is not a real number node. mxml_node_t * Node to set @@ -1262,7 +1262,7 @@ The node is not changed if it is not a real number node. Set the value of a text node. -The node is not changed if it is not a text node. +The node is not changed if it (or its first child) is not a text node. mxml_node_t * Node to set @@ -1283,7 +1283,7 @@ The node is not changed if it is not a text node. Set the value of a text node to a formatted string. -The node is not changed if it is not a text node. +The node is not changed if it (or its first child) is not a text node. mxml_node_t * Node to set