LCOV - code coverage report
Current view: directory - parser/xml/src - nsSAXAttributes.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 158 53 33.5 %
Date: 2012-06-02 Functions: 25 11 44.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Robert Sayre.
      18                 :  *
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "nsSAXAttributes.h"
      39                 : 
      40           47268 : NS_IMPL_ISUPPORTS2(nsSAXAttributes, nsISAXAttributes, nsISAXMutableAttributes)
      41                 : 
      42                 : NS_IMETHODIMP
      43            2883 : nsSAXAttributes::GetIndexFromName(const nsAString &aURI,
      44                 :                                   const nsAString &aLocalName,
      45                 :                                   PRInt32 *aResult)
      46                 : {
      47            2883 :   PRInt32 len = mAttrs.Length();
      48                 :   PRInt32 i;
      49            3721 :   for (i = 0; i < len; ++i) {
      50            1081 :     const SAXAttr &att = mAttrs[i];
      51            1081 :     if (att.localName.Equals(aLocalName) && att.uri.Equals(aURI)) {
      52             243 :       *aResult = i;
      53             243 :       return NS_OK;
      54                 :     }
      55                 :   }
      56            2640 :   *aResult = -1;
      57                 : 
      58            2640 :   return NS_OK;
      59                 : }
      60                 : 
      61                 : NS_IMETHODIMP
      62               0 : nsSAXAttributes::GetIndexFromQName(const nsAString &aQName, PRInt32 *aResult)
      63                 : {
      64               0 :   PRInt32 len = mAttrs.Length();
      65                 :   PRInt32 i;
      66               0 :   for (i = 0; i < len; ++i) {
      67               0 :     const SAXAttr &att = mAttrs[i];
      68               0 :     if (att.qName.Equals(aQName)) {
      69               0 :       *aResult = i;
      70               0 :       return NS_OK;
      71                 :     }
      72                 :   }
      73               0 :   *aResult = -1;
      74                 : 
      75               0 :   return NS_OK;
      76                 : }
      77                 : 
      78                 : NS_IMETHODIMP
      79            1688 : nsSAXAttributes::GetLength(PRInt32 *aResult)
      80                 : {
      81            1688 :   *aResult = mAttrs.Length();
      82            1688 :   return NS_OK;
      83                 : }
      84                 : 
      85                 : NS_IMETHODIMP
      86             711 : nsSAXAttributes::GetLocalName(PRUint32 aIndex, nsAString &aResult)
      87                 : {
      88             711 :   PRUint32 len = mAttrs.Length();
      89             711 :   if (aIndex >= len) {
      90               0 :     aResult.SetIsVoid(true);
      91                 :   } else {
      92             711 :     const SAXAttr &att = mAttrs[aIndex];
      93             711 :     aResult = att.localName;
      94                 :   }
      95                 : 
      96             711 :   return NS_OK;
      97                 : }
      98                 : 
      99                 : NS_IMETHODIMP
     100               2 : nsSAXAttributes::GetQName(PRUint32 aIndex, nsAString &aResult)
     101                 : {
     102               2 :   PRUint32 len = mAttrs.Length();
     103               2 :   if (aIndex >= len) {
     104               0 :     aResult.SetIsVoid(true);
     105                 :   } else {
     106               2 :     const SAXAttr &att = mAttrs[aIndex];
     107               2 :     aResult = att.qName;
     108                 :   }
     109                 : 
     110               2 :   return NS_OK;
     111                 : }
     112                 : 
     113                 : NS_IMETHODIMP
     114               0 : nsSAXAttributes::GetType(PRUint32 aIndex, nsAString &aResult)
     115                 : {
     116               0 :   PRUint32 len = mAttrs.Length();
     117               0 :   if (aIndex >= len) {
     118               0 :     aResult.SetIsVoid(true);
     119                 :   } else {
     120               0 :     const SAXAttr &att = mAttrs[aIndex];
     121               0 :     aResult = att.type;
     122                 :   }
     123                 : 
     124               0 :   return NS_OK;
     125                 : }
     126                 : 
     127                 : NS_IMETHODIMP
     128               0 : nsSAXAttributes::GetTypeFromName(const nsAString &aURI,
     129                 :                                  const nsAString &aLocalName,
     130                 :                                  nsAString &aResult)
     131                 : {
     132               0 :   PRInt32 index = -1;
     133               0 :   GetIndexFromName(aURI, aLocalName, &index);
     134               0 :   if (index >= 0) {
     135               0 :     aResult = mAttrs[index].type;
     136                 :   } else {
     137               0 :     aResult.SetIsVoid(true);
     138                 :   }
     139                 : 
     140               0 :   return NS_OK;
     141                 : }
     142                 : 
     143                 : NS_IMETHODIMP
     144               0 : nsSAXAttributes::GetTypeFromQName(const nsAString &aQName, nsAString &aResult)
     145                 : {
     146               0 :   PRInt32 index = -1;
     147               0 :   GetIndexFromQName(aQName, &index);
     148               0 :   if (index >= 0) {
     149               0 :     aResult = mAttrs[index].type;
     150                 :   } else {
     151               0 :     aResult.SetIsVoid(true);
     152                 :   }
     153                 : 
     154               0 :   return NS_OK;
     155                 : }
     156                 : 
     157                 : NS_IMETHODIMP
     158             693 : nsSAXAttributes::GetURI(PRUint32 aIndex, nsAString &aResult)
     159                 : {
     160             693 :   PRUint32 len = mAttrs.Length();
     161             693 :   if (aIndex >= len) {
     162               0 :     aResult.SetIsVoid(true);
     163                 :   } else {
     164             693 :     const SAXAttr &att = mAttrs[aIndex];
     165             693 :     aResult = att.uri;
     166                 :   }
     167                 : 
     168             693 :   return NS_OK;
     169                 : }
     170                 : 
     171                 : NS_IMETHODIMP
     172             691 : nsSAXAttributes::GetValue(PRUint32 aIndex, nsAString &aResult)
     173                 : {
     174             691 :   PRUint32 len = mAttrs.Length();
     175             691 :   if (aIndex >= len) {
     176               0 :     aResult.SetIsVoid(true);
     177                 :   } else {
     178             691 :     const SAXAttr &att = mAttrs[aIndex];
     179             691 :     aResult = att.value;
     180                 :   }
     181                 : 
     182             691 :   return NS_OK;
     183                 : }
     184                 : 
     185                 : NS_IMETHODIMP
     186            2883 : nsSAXAttributes::GetValueFromName(const nsAString &aURI,
     187                 :                                   const nsAString &aLocalName,
     188                 :                                   nsAString &aResult)
     189                 : {
     190            2883 :   PRInt32 index = -1;
     191            2883 :   GetIndexFromName(aURI, aLocalName, &index);
     192            2883 :   if (index >= 0) {
     193             243 :     aResult = mAttrs[index].value;
     194                 :   } else {
     195            2640 :     aResult.SetIsVoid(true);
     196                 :   }
     197                 : 
     198            2883 :   return NS_OK;
     199                 : }
     200                 : 
     201                 : NS_IMETHODIMP
     202               0 : nsSAXAttributes::GetValueFromQName(const nsAString &aQName,
     203                 :                                    nsAString &aResult)
     204                 : {
     205               0 :   PRInt32 index = -1;
     206               0 :   GetIndexFromQName(aQName, &index);
     207               0 :   if (index >= 0) {
     208               0 :     aResult = mAttrs[index].value;
     209                 :   } else {
     210               0 :     aResult.SetIsVoid(true);
     211                 :   }
     212                 : 
     213               0 :   return NS_OK;
     214                 : }
     215                 : 
     216                 : NS_IMETHODIMP
     217            1018 : nsSAXAttributes::AddAttribute(const nsAString &aURI,
     218                 :                               const nsAString &aLocalName,
     219                 :                               const nsAString &aQName,
     220                 :                               const nsAString &aType,
     221                 :                               const nsAString &aValue)
     222                 : {
     223            1018 :   SAXAttr *att = mAttrs.AppendElement();
     224            1018 :   if (!att) {
     225               0 :     return NS_ERROR_OUT_OF_MEMORY;
     226                 :   }
     227                 :   
     228            1018 :   att->uri = aURI;
     229            1018 :   att->localName = aLocalName;
     230            1018 :   att->qName = aQName;
     231            1018 :   att->type = aType;
     232            1018 :   att->value = aValue;
     233                 : 
     234            1018 :   return NS_OK;
     235                 : }
     236                 : 
     237                 : NS_IMETHODIMP
     238               0 : nsSAXAttributes::Clear()
     239                 : {
     240               0 :   mAttrs.Clear();
     241                 : 
     242               0 :   return NS_OK;
     243                 : }
     244                 : 
     245                 : NS_IMETHODIMP
     246               0 : nsSAXAttributes::RemoveAttribute(PRUint32 aIndex)
     247                 : {
     248               0 :   if (aIndex >= mAttrs.Length()) {
     249               0 :     return NS_ERROR_FAILURE;
     250                 :   }
     251               0 :   mAttrs.RemoveElementAt(aIndex);
     252                 : 
     253               0 :   return NS_OK;
     254                 : }
     255                 : 
     256                 : NS_IMETHODIMP
     257               0 : nsSAXAttributes::SetAttributes(nsISAXAttributes *aAttributes)
     258                 : {
     259               0 :   NS_ENSURE_ARG(aAttributes);
     260                 : 
     261                 :   nsresult rv;
     262                 :   PRInt32 len;
     263               0 :   rv = aAttributes->GetLength(&len);
     264               0 :   NS_ENSURE_SUCCESS(rv, rv);
     265                 : 
     266               0 :   mAttrs.Clear();
     267                 :   SAXAttr *att;
     268                 :   PRInt32 i;
     269               0 :   for (i = 0; i < len; ++i) {
     270               0 :     att = mAttrs.AppendElement();
     271               0 :     if (!att) {
     272               0 :       return NS_ERROR_OUT_OF_MEMORY;
     273                 :     }
     274               0 :     rv = aAttributes->GetURI(i, att->uri);
     275               0 :     NS_ENSURE_SUCCESS(rv, rv);
     276               0 :     rv = aAttributes->GetLocalName(i, att->localName);
     277               0 :     NS_ENSURE_SUCCESS(rv, rv);
     278               0 :     rv = aAttributes->GetQName(i, att->qName);
     279               0 :     NS_ENSURE_SUCCESS(rv, rv);
     280               0 :     rv = aAttributes->GetType(i, att->type);
     281               0 :     NS_ENSURE_SUCCESS(rv, rv);
     282               0 :     rv = aAttributes->GetValue(i, att->value);
     283               0 :     NS_ENSURE_SUCCESS(rv, rv);
     284                 :   }
     285                 : 
     286               0 :   return NS_OK;
     287                 : }
     288                 : 
     289                 : NS_IMETHODIMP
     290               0 : nsSAXAttributes::SetAttribute(PRUint32 aIndex,
     291                 :                               const nsAString &aURI,
     292                 :                               const nsAString &aLocalName,
     293                 :                               const nsAString &aQName,
     294                 :                               const nsAString &aType,
     295                 :                               const nsAString &aValue)
     296                 : {
     297               0 :   if (aIndex >= mAttrs.Length()) {
     298               0 :     return NS_ERROR_FAILURE;
     299                 :   }
     300                 : 
     301               0 :   SAXAttr &att = mAttrs[aIndex];
     302               0 :   att.uri = aURI;
     303               0 :   att.localName = aLocalName;
     304               0 :   att.qName = aQName;
     305               0 :   att.type = aType;
     306               0 :   att.value = aValue;
     307                 : 
     308               0 :   return NS_OK;
     309                 : }
     310                 : 
     311                 : NS_IMETHODIMP
     312               0 : nsSAXAttributes::SetLocalName(PRUint32 aIndex, const nsAString &aLocalName)
     313                 : {
     314               0 :   if (aIndex >= mAttrs.Length()) {
     315               0 :     return NS_ERROR_FAILURE;
     316                 :   }
     317               0 :   mAttrs[aIndex].localName = aLocalName;
     318                 : 
     319               0 :   return NS_OK;
     320                 : }
     321                 : 
     322                 : NS_IMETHODIMP
     323               0 : nsSAXAttributes::SetQName(PRUint32 aIndex, const nsAString &aQName)
     324                 : {
     325               0 :   if (aIndex >= mAttrs.Length()) {
     326               0 :     return NS_ERROR_FAILURE;
     327                 :   }
     328               0 :   mAttrs[aIndex].qName = aQName;
     329                 : 
     330               0 :   return NS_OK;
     331                 : }
     332                 : 
     333                 : NS_IMETHODIMP
     334               0 : nsSAXAttributes::SetType(PRUint32 aIndex, const nsAString &aType)
     335                 : {
     336               0 :   if (aIndex >= mAttrs.Length()) {
     337               0 :     return NS_ERROR_FAILURE;
     338                 :   }
     339               0 :   mAttrs[aIndex].type = aType;
     340                 : 
     341               0 :   return NS_OK;
     342                 : }
     343                 : 
     344                 : NS_IMETHODIMP
     345               0 : nsSAXAttributes::SetURI(PRUint32 aIndex, const nsAString &aURI)
     346                 : {
     347               0 :   if (aIndex >= mAttrs.Length()) {
     348               0 :     return NS_ERROR_FAILURE;
     349                 :   }
     350               0 :   mAttrs[aIndex].uri = aURI;
     351                 : 
     352               0 :   return NS_OK;
     353                 : }
     354                 : 
     355                 : NS_IMETHODIMP
     356               0 : nsSAXAttributes::SetValue(PRUint32 aIndex, const nsAString &aValue)
     357                 : {
     358               0 :   if (aIndex >= mAttrs.Length()) {
     359               0 :     return NS_ERROR_FAILURE;
     360                 :   }
     361               0 :   mAttrs[aIndex].value = aValue;
     362                 : 
     363               0 :   return NS_OK;
     364                 : }

Generated by: LCOV version 1.7