1 | /** |
---|
2 | * |
---|
3 | * @file attribute.c |
---|
4 | * @author Aleix Conchillo Flaque <aleix@member.fsf.org> |
---|
5 | * @date Mon Nov 25, 2002 00:41 |
---|
6 | * @brief SCEW attribute type implementation |
---|
7 | * |
---|
8 | * $Id: attribute.c,v 1.1 2004/01/28 00:43:21 aleix Exp $ |
---|
9 | * |
---|
10 | * @if copyright |
---|
11 | * |
---|
12 | * Copyright (C) 2002, 2003 Aleix Conchillo Flaque |
---|
13 | * |
---|
14 | * SCEW is free software; you can redistribute it and/or |
---|
15 | * modify it under the terms of the GNU Lesser General Public |
---|
16 | * License as published by the Free Software Foundation; either |
---|
17 | * version 2.1 of the License, or (at your option) any later version. |
---|
18 | * |
---|
19 | * SCEW is distributed in the hope that it will be useful, |
---|
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
22 | * Lesser General Public License for more details. |
---|
23 | * |
---|
24 | * You should have received a copy of the GNU Lesser General Public |
---|
25 | * License along with this library; if not, write to the Free Software |
---|
26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
27 | * |
---|
28 | * @endif |
---|
29 | */ |
---|
30 | |
---|
31 | #include "xattribute.h" |
---|
32 | |
---|
33 | #include "xerror.h" |
---|
34 | #include "xelement.h" |
---|
35 | |
---|
36 | #include "str.h" |
---|
37 | |
---|
38 | #include <assert.h> |
---|
39 | #include <string.h> |
---|
40 | |
---|
41 | |
---|
42 | scew_attribute* |
---|
43 | scew_attribute_create(XML_Char const* name, XML_Char const* value) |
---|
44 | { |
---|
45 | return attribute_create(name, value); |
---|
46 | } |
---|
47 | |
---|
48 | void |
---|
49 | scew_attribute_free(scew_attribute* attribute) |
---|
50 | { |
---|
51 | attribute_free(attribute); |
---|
52 | } |
---|
53 | |
---|
54 | unsigned int |
---|
55 | scew_attribute_count(scew_element const* element) |
---|
56 | { |
---|
57 | assert(element != NULL); |
---|
58 | |
---|
59 | return element->attributes->size; |
---|
60 | } |
---|
61 | |
---|
62 | scew_attribute* |
---|
63 | scew_attribute_next(scew_element const* element, |
---|
64 | scew_attribute const* attribute) |
---|
65 | { |
---|
66 | scew_attribute *next_attribute; |
---|
67 | |
---|
68 | if (attribute == NULL) |
---|
69 | { |
---|
70 | if (element == NULL) |
---|
71 | { |
---|
72 | return NULL; |
---|
73 | } |
---|
74 | next_attribute = element->attributes->first; |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | next_attribute = attribute->next; |
---|
79 | } |
---|
80 | |
---|
81 | return next_attribute; |
---|
82 | } |
---|
83 | |
---|
84 | scew_attribute* |
---|
85 | scew_attribute_by_index(scew_element const* element, unsigned int idx) |
---|
86 | { |
---|
87 | return attribute_by_index(element->attributes, idx); |
---|
88 | } |
---|
89 | |
---|
90 | scew_attribute* |
---|
91 | scew_attribute_by_name(scew_element const* element, XML_Char const* name) |
---|
92 | { |
---|
93 | return attribute_by_name(element->attributes, name); |
---|
94 | } |
---|
95 | |
---|
96 | XML_Char const* |
---|
97 | scew_attribute_name(scew_attribute const* attribute) |
---|
98 | { |
---|
99 | assert(attribute != NULL); |
---|
100 | |
---|
101 | return attribute->name; |
---|
102 | } |
---|
103 | |
---|
104 | XML_Char const* |
---|
105 | scew_attribute_value(scew_attribute const* attribute) |
---|
106 | { |
---|
107 | assert(attribute != NULL); |
---|
108 | |
---|
109 | return attribute->value; |
---|
110 | } |
---|
111 | |
---|
112 | XML_Char const* |
---|
113 | scew_attribute_set_name(scew_attribute* attribute, XML_Char const* name) |
---|
114 | { |
---|
115 | assert(attribute != NULL); |
---|
116 | assert(name != NULL); |
---|
117 | |
---|
118 | free(attribute->name); |
---|
119 | attribute->name = scew_strdup(name); |
---|
120 | |
---|
121 | return attribute->name; |
---|
122 | } |
---|
123 | |
---|
124 | XML_Char const* |
---|
125 | scew_attribute_set_value(scew_attribute* attribute, XML_Char const* value) |
---|
126 | { |
---|
127 | assert(attribute != NULL); |
---|
128 | assert(value != NULL); |
---|
129 | |
---|
130 | free(attribute->value); |
---|
131 | attribute->value = scew_strdup(value); |
---|
132 | |
---|
133 | return attribute->value; |
---|
134 | } |
---|