/src/mozilla-central/parser/xml/nsSAXAttributes.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #include "nsSAXAttributes.h" |
7 | | |
8 | | NS_IMPL_ISUPPORTS(nsSAXAttributes, nsISAXAttributes) |
9 | | |
10 | | NS_IMETHODIMP |
11 | | nsSAXAttributes::GetIndexFromName(const nsAString &aURI, |
12 | | const nsAString &aLocalName, |
13 | | int32_t *aResult) |
14 | 0 | { |
15 | 0 | int32_t len = mAttrs.Length(); |
16 | 0 | int32_t i; |
17 | 0 | for (i = 0; i < len; ++i) { |
18 | 0 | const SAXAttr &att = mAttrs[i]; |
19 | 0 | if (att.localName.Equals(aLocalName) && att.uri.Equals(aURI)) { |
20 | 0 | *aResult = i; |
21 | 0 | return NS_OK; |
22 | 0 | } |
23 | 0 | } |
24 | 0 | *aResult = -1; |
25 | 0 |
|
26 | 0 | return NS_OK; |
27 | 0 | } |
28 | | |
29 | | NS_IMETHODIMP |
30 | | nsSAXAttributes::GetIndexFromQName(const nsAString &aQName, int32_t *aResult) |
31 | 0 | { |
32 | 0 | int32_t len = mAttrs.Length(); |
33 | 0 | int32_t i; |
34 | 0 | for (i = 0; i < len; ++i) { |
35 | 0 | const SAXAttr &att = mAttrs[i]; |
36 | 0 | if (att.qName.Equals(aQName)) { |
37 | 0 | *aResult = i; |
38 | 0 | return NS_OK; |
39 | 0 | } |
40 | 0 | } |
41 | 0 | *aResult = -1; |
42 | 0 |
|
43 | 0 | return NS_OK; |
44 | 0 | } |
45 | | |
46 | | NS_IMETHODIMP |
47 | | nsSAXAttributes::GetLength(int32_t *aResult) |
48 | 0 | { |
49 | 0 | *aResult = mAttrs.Length(); |
50 | 0 | return NS_OK; |
51 | 0 | } |
52 | | |
53 | | NS_IMETHODIMP |
54 | | nsSAXAttributes::GetLocalName(uint32_t aIndex, nsAString &aResult) |
55 | 0 | { |
56 | 0 | uint32_t len = mAttrs.Length(); |
57 | 0 | if (aIndex >= len) { |
58 | 0 | aResult.SetIsVoid(true); |
59 | 0 | } else { |
60 | 0 | const SAXAttr &att = mAttrs[aIndex]; |
61 | 0 | aResult = att.localName; |
62 | 0 | } |
63 | 0 |
|
64 | 0 | return NS_OK; |
65 | 0 | } |
66 | | |
67 | | NS_IMETHODIMP |
68 | | nsSAXAttributes::GetQName(uint32_t aIndex, nsAString &aResult) |
69 | 0 | { |
70 | 0 | uint32_t len = mAttrs.Length(); |
71 | 0 | if (aIndex >= len) { |
72 | 0 | aResult.SetIsVoid(true); |
73 | 0 | } else { |
74 | 0 | const SAXAttr &att = mAttrs[aIndex]; |
75 | 0 | aResult = att.qName; |
76 | 0 | } |
77 | 0 |
|
78 | 0 | return NS_OK; |
79 | 0 | } |
80 | | |
81 | | NS_IMETHODIMP |
82 | | nsSAXAttributes::GetType(uint32_t aIndex, nsAString &aResult) |
83 | 0 | { |
84 | 0 | uint32_t len = mAttrs.Length(); |
85 | 0 | if (aIndex >= len) { |
86 | 0 | aResult.SetIsVoid(true); |
87 | 0 | } else { |
88 | 0 | const SAXAttr &att = mAttrs[aIndex]; |
89 | 0 | aResult = att.type; |
90 | 0 | } |
91 | 0 |
|
92 | 0 | return NS_OK; |
93 | 0 | } |
94 | | |
95 | | NS_IMETHODIMP |
96 | | nsSAXAttributes::GetTypeFromName(const nsAString &aURI, |
97 | | const nsAString &aLocalName, |
98 | | nsAString &aResult) |
99 | 0 | { |
100 | 0 | int32_t index = -1; |
101 | 0 | GetIndexFromName(aURI, aLocalName, &index); |
102 | 0 | if (index >= 0) { |
103 | 0 | aResult = mAttrs[index].type; |
104 | 0 | } else { |
105 | 0 | aResult.SetIsVoid(true); |
106 | 0 | } |
107 | 0 |
|
108 | 0 | return NS_OK; |
109 | 0 | } |
110 | | |
111 | | NS_IMETHODIMP |
112 | | nsSAXAttributes::GetTypeFromQName(const nsAString &aQName, nsAString &aResult) |
113 | 0 | { |
114 | 0 | int32_t index = -1; |
115 | 0 | GetIndexFromQName(aQName, &index); |
116 | 0 | if (index >= 0) { |
117 | 0 | aResult = mAttrs[index].type; |
118 | 0 | } else { |
119 | 0 | aResult.SetIsVoid(true); |
120 | 0 | } |
121 | 0 |
|
122 | 0 | return NS_OK; |
123 | 0 | } |
124 | | |
125 | | NS_IMETHODIMP |
126 | | nsSAXAttributes::GetURI(uint32_t aIndex, nsAString &aResult) |
127 | 0 | { |
128 | 0 | uint32_t len = mAttrs.Length(); |
129 | 0 | if (aIndex >= len) { |
130 | 0 | aResult.SetIsVoid(true); |
131 | 0 | } else { |
132 | 0 | const SAXAttr &att = mAttrs[aIndex]; |
133 | 0 | aResult = att.uri; |
134 | 0 | } |
135 | 0 |
|
136 | 0 | return NS_OK; |
137 | 0 | } |
138 | | |
139 | | NS_IMETHODIMP |
140 | | nsSAXAttributes::GetValue(uint32_t aIndex, nsAString &aResult) |
141 | 0 | { |
142 | 0 | uint32_t len = mAttrs.Length(); |
143 | 0 | if (aIndex >= len) { |
144 | 0 | aResult.SetIsVoid(true); |
145 | 0 | } else { |
146 | 0 | const SAXAttr &att = mAttrs[aIndex]; |
147 | 0 | aResult = att.value; |
148 | 0 | } |
149 | 0 |
|
150 | 0 | return NS_OK; |
151 | 0 | } |
152 | | |
153 | | NS_IMETHODIMP |
154 | | nsSAXAttributes::GetValueFromName(const nsAString &aURI, |
155 | | const nsAString &aLocalName, |
156 | | nsAString &aResult) |
157 | 0 | { |
158 | 0 | int32_t index = -1; |
159 | 0 | GetIndexFromName(aURI, aLocalName, &index); |
160 | 0 | if (index >= 0) { |
161 | 0 | aResult = mAttrs[index].value; |
162 | 0 | } else { |
163 | 0 | aResult.SetIsVoid(true); |
164 | 0 | } |
165 | 0 |
|
166 | 0 | return NS_OK; |
167 | 0 | } |
168 | | |
169 | | NS_IMETHODIMP |
170 | | nsSAXAttributes::GetValueFromQName(const nsAString &aQName, |
171 | | nsAString &aResult) |
172 | 0 | { |
173 | 0 | int32_t index = -1; |
174 | 0 | GetIndexFromQName(aQName, &index); |
175 | 0 | if (index >= 0) { |
176 | 0 | aResult = mAttrs[index].value; |
177 | 0 | } else { |
178 | 0 | aResult.SetIsVoid(true); |
179 | 0 | } |
180 | 0 |
|
181 | 0 | return NS_OK; |
182 | 0 | } |
183 | | |
184 | | nsresult |
185 | | nsSAXAttributes::AddAttribute(const nsAString &aURI, |
186 | | const nsAString &aLocalName, |
187 | | const nsAString &aQName, |
188 | | const nsAString &aType, |
189 | | const nsAString &aValue) |
190 | 0 | { |
191 | 0 | SAXAttr *att = mAttrs.AppendElement(); |
192 | 0 | if (!att) { |
193 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
194 | 0 | } |
195 | 0 | |
196 | 0 | att->uri = aURI; |
197 | 0 | att->localName = aLocalName; |
198 | 0 | att->qName = aQName; |
199 | 0 | att->type = aType; |
200 | 0 | att->value = aValue; |
201 | 0 |
|
202 | 0 | return NS_OK; |
203 | 0 | } |
204 | | |