Bumping manifests a=b2g-bump
[gecko.git] / parser / xml / nsSAXAttributes.cpp
blob3984186e4ad52f63e43fd5a69e3b57b79122d6d1
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsSAXAttributes.h"
8 NS_IMPL_ISUPPORTS(nsSAXAttributes, nsISAXAttributes, nsISAXMutableAttributes)
10 NS_IMETHODIMP
11 nsSAXAttributes::GetIndexFromName(const nsAString &aURI,
12 const nsAString &aLocalName,
13 int32_t *aResult)
15 int32_t len = mAttrs.Length();
16 int32_t i;
17 for (i = 0; i < len; ++i) {
18 const SAXAttr &att = mAttrs[i];
19 if (att.localName.Equals(aLocalName) && att.uri.Equals(aURI)) {
20 *aResult = i;
21 return NS_OK;
24 *aResult = -1;
26 return NS_OK;
29 NS_IMETHODIMP
30 nsSAXAttributes::GetIndexFromQName(const nsAString &aQName, int32_t *aResult)
32 int32_t len = mAttrs.Length();
33 int32_t i;
34 for (i = 0; i < len; ++i) {
35 const SAXAttr &att = mAttrs[i];
36 if (att.qName.Equals(aQName)) {
37 *aResult = i;
38 return NS_OK;
41 *aResult = -1;
43 return NS_OK;
46 NS_IMETHODIMP
47 nsSAXAttributes::GetLength(int32_t *aResult)
49 *aResult = mAttrs.Length();
50 return NS_OK;
53 NS_IMETHODIMP
54 nsSAXAttributes::GetLocalName(uint32_t aIndex, nsAString &aResult)
56 uint32_t len = mAttrs.Length();
57 if (aIndex >= len) {
58 aResult.SetIsVoid(true);
59 } else {
60 const SAXAttr &att = mAttrs[aIndex];
61 aResult = att.localName;
64 return NS_OK;
67 NS_IMETHODIMP
68 nsSAXAttributes::GetQName(uint32_t aIndex, nsAString &aResult)
70 uint32_t len = mAttrs.Length();
71 if (aIndex >= len) {
72 aResult.SetIsVoid(true);
73 } else {
74 const SAXAttr &att = mAttrs[aIndex];
75 aResult = att.qName;
78 return NS_OK;
81 NS_IMETHODIMP
82 nsSAXAttributes::GetType(uint32_t aIndex, nsAString &aResult)
84 uint32_t len = mAttrs.Length();
85 if (aIndex >= len) {
86 aResult.SetIsVoid(true);
87 } else {
88 const SAXAttr &att = mAttrs[aIndex];
89 aResult = att.type;
92 return NS_OK;
95 NS_IMETHODIMP
96 nsSAXAttributes::GetTypeFromName(const nsAString &aURI,
97 const nsAString &aLocalName,
98 nsAString &aResult)
100 int32_t index = -1;
101 GetIndexFromName(aURI, aLocalName, &index);
102 if (index >= 0) {
103 aResult = mAttrs[index].type;
104 } else {
105 aResult.SetIsVoid(true);
108 return NS_OK;
111 NS_IMETHODIMP
112 nsSAXAttributes::GetTypeFromQName(const nsAString &aQName, nsAString &aResult)
114 int32_t index = -1;
115 GetIndexFromQName(aQName, &index);
116 if (index >= 0) {
117 aResult = mAttrs[index].type;
118 } else {
119 aResult.SetIsVoid(true);
122 return NS_OK;
125 NS_IMETHODIMP
126 nsSAXAttributes::GetURI(uint32_t aIndex, nsAString &aResult)
128 uint32_t len = mAttrs.Length();
129 if (aIndex >= len) {
130 aResult.SetIsVoid(true);
131 } else {
132 const SAXAttr &att = mAttrs[aIndex];
133 aResult = att.uri;
136 return NS_OK;
139 NS_IMETHODIMP
140 nsSAXAttributes::GetValue(uint32_t aIndex, nsAString &aResult)
142 uint32_t len = mAttrs.Length();
143 if (aIndex >= len) {
144 aResult.SetIsVoid(true);
145 } else {
146 const SAXAttr &att = mAttrs[aIndex];
147 aResult = att.value;
150 return NS_OK;
153 NS_IMETHODIMP
154 nsSAXAttributes::GetValueFromName(const nsAString &aURI,
155 const nsAString &aLocalName,
156 nsAString &aResult)
158 int32_t index = -1;
159 GetIndexFromName(aURI, aLocalName, &index);
160 if (index >= 0) {
161 aResult = mAttrs[index].value;
162 } else {
163 aResult.SetIsVoid(true);
166 return NS_OK;
169 NS_IMETHODIMP
170 nsSAXAttributes::GetValueFromQName(const nsAString &aQName,
171 nsAString &aResult)
173 int32_t index = -1;
174 GetIndexFromQName(aQName, &index);
175 if (index >= 0) {
176 aResult = mAttrs[index].value;
177 } else {
178 aResult.SetIsVoid(true);
181 return NS_OK;
184 NS_IMETHODIMP
185 nsSAXAttributes::AddAttribute(const nsAString &aURI,
186 const nsAString &aLocalName,
187 const nsAString &aQName,
188 const nsAString &aType,
189 const nsAString &aValue)
191 SAXAttr *att = mAttrs.AppendElement();
192 if (!att) {
193 return NS_ERROR_OUT_OF_MEMORY;
196 att->uri = aURI;
197 att->localName = aLocalName;
198 att->qName = aQName;
199 att->type = aType;
200 att->value = aValue;
202 return NS_OK;
205 NS_IMETHODIMP
206 nsSAXAttributes::Clear()
208 mAttrs.Clear();
210 return NS_OK;
213 NS_IMETHODIMP
214 nsSAXAttributes::RemoveAttribute(uint32_t aIndex)
216 if (aIndex >= mAttrs.Length()) {
217 return NS_ERROR_FAILURE;
219 mAttrs.RemoveElementAt(aIndex);
221 return NS_OK;
224 NS_IMETHODIMP
225 nsSAXAttributes::SetAttributes(nsISAXAttributes *aAttributes)
227 NS_ENSURE_ARG(aAttributes);
229 nsresult rv;
230 int32_t len;
231 rv = aAttributes->GetLength(&len);
232 NS_ENSURE_SUCCESS(rv, rv);
234 mAttrs.Clear();
235 SAXAttr *att;
236 int32_t i;
237 for (i = 0; i < len; ++i) {
238 att = mAttrs.AppendElement();
239 if (!att) {
240 return NS_ERROR_OUT_OF_MEMORY;
242 rv = aAttributes->GetURI(i, att->uri);
243 NS_ENSURE_SUCCESS(rv, rv);
244 rv = aAttributes->GetLocalName(i, att->localName);
245 NS_ENSURE_SUCCESS(rv, rv);
246 rv = aAttributes->GetQName(i, att->qName);
247 NS_ENSURE_SUCCESS(rv, rv);
248 rv = aAttributes->GetType(i, att->type);
249 NS_ENSURE_SUCCESS(rv, rv);
250 rv = aAttributes->GetValue(i, att->value);
251 NS_ENSURE_SUCCESS(rv, rv);
254 return NS_OK;
257 NS_IMETHODIMP
258 nsSAXAttributes::SetAttribute(uint32_t aIndex,
259 const nsAString &aURI,
260 const nsAString &aLocalName,
261 const nsAString &aQName,
262 const nsAString &aType,
263 const nsAString &aValue)
265 if (aIndex >= mAttrs.Length()) {
266 return NS_ERROR_FAILURE;
269 SAXAttr &att = mAttrs[aIndex];
270 att.uri = aURI;
271 att.localName = aLocalName;
272 att.qName = aQName;
273 att.type = aType;
274 att.value = aValue;
276 return NS_OK;
279 NS_IMETHODIMP
280 nsSAXAttributes::SetLocalName(uint32_t aIndex, const nsAString &aLocalName)
282 if (aIndex >= mAttrs.Length()) {
283 return NS_ERROR_FAILURE;
285 mAttrs[aIndex].localName = aLocalName;
287 return NS_OK;
290 NS_IMETHODIMP
291 nsSAXAttributes::SetQName(uint32_t aIndex, const nsAString &aQName)
293 if (aIndex >= mAttrs.Length()) {
294 return NS_ERROR_FAILURE;
296 mAttrs[aIndex].qName = aQName;
298 return NS_OK;
301 NS_IMETHODIMP
302 nsSAXAttributes::SetType(uint32_t aIndex, const nsAString &aType)
304 if (aIndex >= mAttrs.Length()) {
305 return NS_ERROR_FAILURE;
307 mAttrs[aIndex].type = aType;
309 return NS_OK;
312 NS_IMETHODIMP
313 nsSAXAttributes::SetURI(uint32_t aIndex, const nsAString &aURI)
315 if (aIndex >= mAttrs.Length()) {
316 return NS_ERROR_FAILURE;
318 mAttrs[aIndex].uri = aURI;
320 return NS_OK;
323 NS_IMETHODIMP
324 nsSAXAttributes::SetValue(uint32_t aIndex, const nsAString &aValue)
326 if (aIndex >= mAttrs.Length()) {
327 return NS_ERROR_FAILURE;
329 mAttrs[aIndex].value = aValue;
331 return NS_OK;