parser/xml/src/nsSAXAttributes.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsSAXAttributes.h"
michael@0 7
michael@0 8 NS_IMPL_ISUPPORTS(nsSAXAttributes, nsISAXAttributes, nsISAXMutableAttributes)
michael@0 9
michael@0 10 NS_IMETHODIMP
michael@0 11 nsSAXAttributes::GetIndexFromName(const nsAString &aURI,
michael@0 12 const nsAString &aLocalName,
michael@0 13 int32_t *aResult)
michael@0 14 {
michael@0 15 int32_t len = mAttrs.Length();
michael@0 16 int32_t i;
michael@0 17 for (i = 0; i < len; ++i) {
michael@0 18 const SAXAttr &att = mAttrs[i];
michael@0 19 if (att.localName.Equals(aLocalName) && att.uri.Equals(aURI)) {
michael@0 20 *aResult = i;
michael@0 21 return NS_OK;
michael@0 22 }
michael@0 23 }
michael@0 24 *aResult = -1;
michael@0 25
michael@0 26 return NS_OK;
michael@0 27 }
michael@0 28
michael@0 29 NS_IMETHODIMP
michael@0 30 nsSAXAttributes::GetIndexFromQName(const nsAString &aQName, int32_t *aResult)
michael@0 31 {
michael@0 32 int32_t len = mAttrs.Length();
michael@0 33 int32_t i;
michael@0 34 for (i = 0; i < len; ++i) {
michael@0 35 const SAXAttr &att = mAttrs[i];
michael@0 36 if (att.qName.Equals(aQName)) {
michael@0 37 *aResult = i;
michael@0 38 return NS_OK;
michael@0 39 }
michael@0 40 }
michael@0 41 *aResult = -1;
michael@0 42
michael@0 43 return NS_OK;
michael@0 44 }
michael@0 45
michael@0 46 NS_IMETHODIMP
michael@0 47 nsSAXAttributes::GetLength(int32_t *aResult)
michael@0 48 {
michael@0 49 *aResult = mAttrs.Length();
michael@0 50 return NS_OK;
michael@0 51 }
michael@0 52
michael@0 53 NS_IMETHODIMP
michael@0 54 nsSAXAttributes::GetLocalName(uint32_t aIndex, nsAString &aResult)
michael@0 55 {
michael@0 56 uint32_t len = mAttrs.Length();
michael@0 57 if (aIndex >= len) {
michael@0 58 aResult.SetIsVoid(true);
michael@0 59 } else {
michael@0 60 const SAXAttr &att = mAttrs[aIndex];
michael@0 61 aResult = att.localName;
michael@0 62 }
michael@0 63
michael@0 64 return NS_OK;
michael@0 65 }
michael@0 66
michael@0 67 NS_IMETHODIMP
michael@0 68 nsSAXAttributes::GetQName(uint32_t aIndex, nsAString &aResult)
michael@0 69 {
michael@0 70 uint32_t len = mAttrs.Length();
michael@0 71 if (aIndex >= len) {
michael@0 72 aResult.SetIsVoid(true);
michael@0 73 } else {
michael@0 74 const SAXAttr &att = mAttrs[aIndex];
michael@0 75 aResult = att.qName;
michael@0 76 }
michael@0 77
michael@0 78 return NS_OK;
michael@0 79 }
michael@0 80
michael@0 81 NS_IMETHODIMP
michael@0 82 nsSAXAttributes::GetType(uint32_t aIndex, nsAString &aResult)
michael@0 83 {
michael@0 84 uint32_t len = mAttrs.Length();
michael@0 85 if (aIndex >= len) {
michael@0 86 aResult.SetIsVoid(true);
michael@0 87 } else {
michael@0 88 const SAXAttr &att = mAttrs[aIndex];
michael@0 89 aResult = att.type;
michael@0 90 }
michael@0 91
michael@0 92 return NS_OK;
michael@0 93 }
michael@0 94
michael@0 95 NS_IMETHODIMP
michael@0 96 nsSAXAttributes::GetTypeFromName(const nsAString &aURI,
michael@0 97 const nsAString &aLocalName,
michael@0 98 nsAString &aResult)
michael@0 99 {
michael@0 100 int32_t index = -1;
michael@0 101 GetIndexFromName(aURI, aLocalName, &index);
michael@0 102 if (index >= 0) {
michael@0 103 aResult = mAttrs[index].type;
michael@0 104 } else {
michael@0 105 aResult.SetIsVoid(true);
michael@0 106 }
michael@0 107
michael@0 108 return NS_OK;
michael@0 109 }
michael@0 110
michael@0 111 NS_IMETHODIMP
michael@0 112 nsSAXAttributes::GetTypeFromQName(const nsAString &aQName, nsAString &aResult)
michael@0 113 {
michael@0 114 int32_t index = -1;
michael@0 115 GetIndexFromQName(aQName, &index);
michael@0 116 if (index >= 0) {
michael@0 117 aResult = mAttrs[index].type;
michael@0 118 } else {
michael@0 119 aResult.SetIsVoid(true);
michael@0 120 }
michael@0 121
michael@0 122 return NS_OK;
michael@0 123 }
michael@0 124
michael@0 125 NS_IMETHODIMP
michael@0 126 nsSAXAttributes::GetURI(uint32_t aIndex, nsAString &aResult)
michael@0 127 {
michael@0 128 uint32_t len = mAttrs.Length();
michael@0 129 if (aIndex >= len) {
michael@0 130 aResult.SetIsVoid(true);
michael@0 131 } else {
michael@0 132 const SAXAttr &att = mAttrs[aIndex];
michael@0 133 aResult = att.uri;
michael@0 134 }
michael@0 135
michael@0 136 return NS_OK;
michael@0 137 }
michael@0 138
michael@0 139 NS_IMETHODIMP
michael@0 140 nsSAXAttributes::GetValue(uint32_t aIndex, nsAString &aResult)
michael@0 141 {
michael@0 142 uint32_t len = mAttrs.Length();
michael@0 143 if (aIndex >= len) {
michael@0 144 aResult.SetIsVoid(true);
michael@0 145 } else {
michael@0 146 const SAXAttr &att = mAttrs[aIndex];
michael@0 147 aResult = att.value;
michael@0 148 }
michael@0 149
michael@0 150 return NS_OK;
michael@0 151 }
michael@0 152
michael@0 153 NS_IMETHODIMP
michael@0 154 nsSAXAttributes::GetValueFromName(const nsAString &aURI,
michael@0 155 const nsAString &aLocalName,
michael@0 156 nsAString &aResult)
michael@0 157 {
michael@0 158 int32_t index = -1;
michael@0 159 GetIndexFromName(aURI, aLocalName, &index);
michael@0 160 if (index >= 0) {
michael@0 161 aResult = mAttrs[index].value;
michael@0 162 } else {
michael@0 163 aResult.SetIsVoid(true);
michael@0 164 }
michael@0 165
michael@0 166 return NS_OK;
michael@0 167 }
michael@0 168
michael@0 169 NS_IMETHODIMP
michael@0 170 nsSAXAttributes::GetValueFromQName(const nsAString &aQName,
michael@0 171 nsAString &aResult)
michael@0 172 {
michael@0 173 int32_t index = -1;
michael@0 174 GetIndexFromQName(aQName, &index);
michael@0 175 if (index >= 0) {
michael@0 176 aResult = mAttrs[index].value;
michael@0 177 } else {
michael@0 178 aResult.SetIsVoid(true);
michael@0 179 }
michael@0 180
michael@0 181 return NS_OK;
michael@0 182 }
michael@0 183
michael@0 184 NS_IMETHODIMP
michael@0 185 nsSAXAttributes::AddAttribute(const nsAString &aURI,
michael@0 186 const nsAString &aLocalName,
michael@0 187 const nsAString &aQName,
michael@0 188 const nsAString &aType,
michael@0 189 const nsAString &aValue)
michael@0 190 {
michael@0 191 SAXAttr *att = mAttrs.AppendElement();
michael@0 192 if (!att) {
michael@0 193 return NS_ERROR_OUT_OF_MEMORY;
michael@0 194 }
michael@0 195
michael@0 196 att->uri = aURI;
michael@0 197 att->localName = aLocalName;
michael@0 198 att->qName = aQName;
michael@0 199 att->type = aType;
michael@0 200 att->value = aValue;
michael@0 201
michael@0 202 return NS_OK;
michael@0 203 }
michael@0 204
michael@0 205 NS_IMETHODIMP
michael@0 206 nsSAXAttributes::Clear()
michael@0 207 {
michael@0 208 mAttrs.Clear();
michael@0 209
michael@0 210 return NS_OK;
michael@0 211 }
michael@0 212
michael@0 213 NS_IMETHODIMP
michael@0 214 nsSAXAttributes::RemoveAttribute(uint32_t aIndex)
michael@0 215 {
michael@0 216 if (aIndex >= mAttrs.Length()) {
michael@0 217 return NS_ERROR_FAILURE;
michael@0 218 }
michael@0 219 mAttrs.RemoveElementAt(aIndex);
michael@0 220
michael@0 221 return NS_OK;
michael@0 222 }
michael@0 223
michael@0 224 NS_IMETHODIMP
michael@0 225 nsSAXAttributes::SetAttributes(nsISAXAttributes *aAttributes)
michael@0 226 {
michael@0 227 NS_ENSURE_ARG(aAttributes);
michael@0 228
michael@0 229 nsresult rv;
michael@0 230 int32_t len;
michael@0 231 rv = aAttributes->GetLength(&len);
michael@0 232 NS_ENSURE_SUCCESS(rv, rv);
michael@0 233
michael@0 234 mAttrs.Clear();
michael@0 235 SAXAttr *att;
michael@0 236 int32_t i;
michael@0 237 for (i = 0; i < len; ++i) {
michael@0 238 att = mAttrs.AppendElement();
michael@0 239 if (!att) {
michael@0 240 return NS_ERROR_OUT_OF_MEMORY;
michael@0 241 }
michael@0 242 rv = aAttributes->GetURI(i, att->uri);
michael@0 243 NS_ENSURE_SUCCESS(rv, rv);
michael@0 244 rv = aAttributes->GetLocalName(i, att->localName);
michael@0 245 NS_ENSURE_SUCCESS(rv, rv);
michael@0 246 rv = aAttributes->GetQName(i, att->qName);
michael@0 247 NS_ENSURE_SUCCESS(rv, rv);
michael@0 248 rv = aAttributes->GetType(i, att->type);
michael@0 249 NS_ENSURE_SUCCESS(rv, rv);
michael@0 250 rv = aAttributes->GetValue(i, att->value);
michael@0 251 NS_ENSURE_SUCCESS(rv, rv);
michael@0 252 }
michael@0 253
michael@0 254 return NS_OK;
michael@0 255 }
michael@0 256
michael@0 257 NS_IMETHODIMP
michael@0 258 nsSAXAttributes::SetAttribute(uint32_t aIndex,
michael@0 259 const nsAString &aURI,
michael@0 260 const nsAString &aLocalName,
michael@0 261 const nsAString &aQName,
michael@0 262 const nsAString &aType,
michael@0 263 const nsAString &aValue)
michael@0 264 {
michael@0 265 if (aIndex >= mAttrs.Length()) {
michael@0 266 return NS_ERROR_FAILURE;
michael@0 267 }
michael@0 268
michael@0 269 SAXAttr &att = mAttrs[aIndex];
michael@0 270 att.uri = aURI;
michael@0 271 att.localName = aLocalName;
michael@0 272 att.qName = aQName;
michael@0 273 att.type = aType;
michael@0 274 att.value = aValue;
michael@0 275
michael@0 276 return NS_OK;
michael@0 277 }
michael@0 278
michael@0 279 NS_IMETHODIMP
michael@0 280 nsSAXAttributes::SetLocalName(uint32_t aIndex, const nsAString &aLocalName)
michael@0 281 {
michael@0 282 if (aIndex >= mAttrs.Length()) {
michael@0 283 return NS_ERROR_FAILURE;
michael@0 284 }
michael@0 285 mAttrs[aIndex].localName = aLocalName;
michael@0 286
michael@0 287 return NS_OK;
michael@0 288 }
michael@0 289
michael@0 290 NS_IMETHODIMP
michael@0 291 nsSAXAttributes::SetQName(uint32_t aIndex, const nsAString &aQName)
michael@0 292 {
michael@0 293 if (aIndex >= mAttrs.Length()) {
michael@0 294 return NS_ERROR_FAILURE;
michael@0 295 }
michael@0 296 mAttrs[aIndex].qName = aQName;
michael@0 297
michael@0 298 return NS_OK;
michael@0 299 }
michael@0 300
michael@0 301 NS_IMETHODIMP
michael@0 302 nsSAXAttributes::SetType(uint32_t aIndex, const nsAString &aType)
michael@0 303 {
michael@0 304 if (aIndex >= mAttrs.Length()) {
michael@0 305 return NS_ERROR_FAILURE;
michael@0 306 }
michael@0 307 mAttrs[aIndex].type = aType;
michael@0 308
michael@0 309 return NS_OK;
michael@0 310 }
michael@0 311
michael@0 312 NS_IMETHODIMP
michael@0 313 nsSAXAttributes::SetURI(uint32_t aIndex, const nsAString &aURI)
michael@0 314 {
michael@0 315 if (aIndex >= mAttrs.Length()) {
michael@0 316 return NS_ERROR_FAILURE;
michael@0 317 }
michael@0 318 mAttrs[aIndex].uri = aURI;
michael@0 319
michael@0 320 return NS_OK;
michael@0 321 }
michael@0 322
michael@0 323 NS_IMETHODIMP
michael@0 324 nsSAXAttributes::SetValue(uint32_t aIndex, const nsAString &aValue)
michael@0 325 {
michael@0 326 if (aIndex >= mAttrs.Length()) {
michael@0 327 return NS_ERROR_FAILURE;
michael@0 328 }
michael@0 329 mAttrs[aIndex].value = aValue;
michael@0 330
michael@0 331 return NS_OK;
michael@0 332 }

mercurial