parser/xml/src/nsSAXAttributes.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     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)
    14 {
    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;
    22     }
    23   }
    24   *aResult = -1;
    26   return NS_OK;
    27 }
    29 NS_IMETHODIMP
    30 nsSAXAttributes::GetIndexFromQName(const nsAString &aQName, int32_t *aResult)
    31 {
    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;
    39     }
    40   }
    41   *aResult = -1;
    43   return NS_OK;
    44 }
    46 NS_IMETHODIMP
    47 nsSAXAttributes::GetLength(int32_t *aResult)
    48 {
    49   *aResult = mAttrs.Length();
    50   return NS_OK;
    51 }
    53 NS_IMETHODIMP
    54 nsSAXAttributes::GetLocalName(uint32_t aIndex, nsAString &aResult)
    55 {
    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;
    62   }
    64   return NS_OK;
    65 }
    67 NS_IMETHODIMP
    68 nsSAXAttributes::GetQName(uint32_t aIndex, nsAString &aResult)
    69 {
    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;
    76   }
    78   return NS_OK;
    79 }
    81 NS_IMETHODIMP
    82 nsSAXAttributes::GetType(uint32_t aIndex, nsAString &aResult)
    83 {
    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;
    90   }
    92   return NS_OK;
    93 }
    95 NS_IMETHODIMP
    96 nsSAXAttributes::GetTypeFromName(const nsAString &aURI,
    97                                  const nsAString &aLocalName,
    98                                  nsAString &aResult)
    99 {
   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);
   106   }
   108   return NS_OK;
   109 }
   111 NS_IMETHODIMP
   112 nsSAXAttributes::GetTypeFromQName(const nsAString &aQName, nsAString &aResult)
   113 {
   114   int32_t index = -1;
   115   GetIndexFromQName(aQName, &index);
   116   if (index >= 0) {
   117     aResult = mAttrs[index].type;
   118   } else {
   119     aResult.SetIsVoid(true);
   120   }
   122   return NS_OK;
   123 }
   125 NS_IMETHODIMP
   126 nsSAXAttributes::GetURI(uint32_t aIndex, nsAString &aResult)
   127 {
   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;
   134   }
   136   return NS_OK;
   137 }
   139 NS_IMETHODIMP
   140 nsSAXAttributes::GetValue(uint32_t aIndex, nsAString &aResult)
   141 {
   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;
   148   }
   150   return NS_OK;
   151 }
   153 NS_IMETHODIMP
   154 nsSAXAttributes::GetValueFromName(const nsAString &aURI,
   155                                   const nsAString &aLocalName,
   156                                   nsAString &aResult)
   157 {
   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);
   164   }
   166   return NS_OK;
   167 }
   169 NS_IMETHODIMP
   170 nsSAXAttributes::GetValueFromQName(const nsAString &aQName,
   171                                    nsAString &aResult)
   172 {
   173   int32_t index = -1;
   174   GetIndexFromQName(aQName, &index);
   175   if (index >= 0) {
   176     aResult = mAttrs[index].value;
   177   } else {
   178     aResult.SetIsVoid(true);
   179   }
   181   return NS_OK;
   182 }
   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)
   190 {
   191   SAXAttr *att = mAttrs.AppendElement();
   192   if (!att) {
   193     return NS_ERROR_OUT_OF_MEMORY;
   194   }
   196   att->uri = aURI;
   197   att->localName = aLocalName;
   198   att->qName = aQName;
   199   att->type = aType;
   200   att->value = aValue;
   202   return NS_OK;
   203 }
   205 NS_IMETHODIMP
   206 nsSAXAttributes::Clear()
   207 {
   208   mAttrs.Clear();
   210   return NS_OK;
   211 }
   213 NS_IMETHODIMP
   214 nsSAXAttributes::RemoveAttribute(uint32_t aIndex)
   215 {
   216   if (aIndex >= mAttrs.Length()) {
   217     return NS_ERROR_FAILURE;
   218   }
   219   mAttrs.RemoveElementAt(aIndex);
   221   return NS_OK;
   222 }
   224 NS_IMETHODIMP
   225 nsSAXAttributes::SetAttributes(nsISAXAttributes *aAttributes)
   226 {
   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;
   241     }
   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);
   252   }
   254   return NS_OK;
   255 }
   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)
   264 {
   265   if (aIndex >= mAttrs.Length()) {
   266     return NS_ERROR_FAILURE;
   267   }
   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;
   277 }
   279 NS_IMETHODIMP
   280 nsSAXAttributes::SetLocalName(uint32_t aIndex, const nsAString &aLocalName)
   281 {
   282   if (aIndex >= mAttrs.Length()) {
   283     return NS_ERROR_FAILURE;
   284   }
   285   mAttrs[aIndex].localName = aLocalName;
   287   return NS_OK;
   288 }
   290 NS_IMETHODIMP
   291 nsSAXAttributes::SetQName(uint32_t aIndex, const nsAString &aQName)
   292 {
   293   if (aIndex >= mAttrs.Length()) {
   294     return NS_ERROR_FAILURE;
   295   }
   296   mAttrs[aIndex].qName = aQName;
   298   return NS_OK;
   299 }
   301 NS_IMETHODIMP
   302 nsSAXAttributes::SetType(uint32_t aIndex, const nsAString &aType)
   303 {
   304   if (aIndex >= mAttrs.Length()) {
   305     return NS_ERROR_FAILURE;
   306   }
   307   mAttrs[aIndex].type = aType;
   309   return NS_OK;
   310 }
   312 NS_IMETHODIMP
   313 nsSAXAttributes::SetURI(uint32_t aIndex, const nsAString &aURI)
   314 {
   315   if (aIndex >= mAttrs.Length()) {
   316     return NS_ERROR_FAILURE;
   317   }
   318   mAttrs[aIndex].uri = aURI;
   320   return NS_OK;
   321 }
   323 NS_IMETHODIMP
   324 nsSAXAttributes::SetValue(uint32_t aIndex, const nsAString &aValue)
   325 {
   326   if (aIndex >= mAttrs.Length()) {
   327     return NS_ERROR_FAILURE;
   328   }
   329   mAttrs[aIndex].value = aValue;
   331   return NS_OK;
   332 }

mercurial