LCOV - code coverage report
Current view: directory - rdf/base/src - nsNameSpaceMap.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 30 27 90.0 %
Date: 2012-06-02 Functions: 5 5 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org Code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications Corporation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1999
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Chris Waterson <waterson@netscape.com>
      25                 :  *   Robert John Churchill <rjc@netscape.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      29                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #include "nsNameSpaceMap.h"
      42                 : #include "nsReadableUtils.h"
      43                 : 
      44              29 : nsNameSpaceMap::nsNameSpaceMap()
      45              29 :     : mEntries(nsnull)
      46                 : {
      47              29 :     MOZ_COUNT_CTOR(nsNameSpaceMap);
      48              29 : }
      49                 : 
      50              29 : nsNameSpaceMap::~nsNameSpaceMap()
      51                 : {
      52              29 :     MOZ_COUNT_DTOR(nsNameSpaceMap);
      53                 : 
      54             114 :     while (mEntries) {
      55              56 :         Entry* doomed = mEntries;
      56              56 :         mEntries = mEntries->mNext;
      57              56 :         delete doomed;
      58                 :     }
      59              29 : }
      60                 : 
      61                 : nsresult
      62              56 : nsNameSpaceMap::Put(const nsAString& aURI, nsIAtom* aPrefix)
      63                 : {
      64             112 :     nsCString uriUTF8;
      65              56 :     AppendUTF16toUTF8(aURI, uriUTF8);
      66              56 :     return Put(uriUTF8, aPrefix);
      67                 : }
      68                 : 
      69                 : nsresult
      70              56 : nsNameSpaceMap::Put(const nsCSubstring& aURI, nsIAtom* aPrefix)
      71                 : {
      72                 :     Entry* entry;
      73                 : 
      74                 :     // Make sure we're not adding a duplicate
      75              90 :     for (entry = mEntries; entry != nsnull; entry = entry->mNext) {
      76              34 :         if (entry->mURI == aURI || entry->mPrefix == aPrefix)
      77               0 :             return NS_ERROR_FAILURE;
      78                 :     }
      79                 : 
      80              56 :     entry = new Entry(aURI, aPrefix);
      81              56 :     if (! entry)
      82               0 :         return NS_ERROR_OUT_OF_MEMORY;
      83                 : 
      84              56 :     entry->mNext = mEntries;
      85              56 :     mEntries = entry;
      86              56 :     return NS_OK;
      87                 : }
      88                 : 
      89                 : nsNameSpaceMap::const_iterator
      90             205 : nsNameSpaceMap::GetNameSpaceOf(const nsCSubstring& aURI) const
      91                 : {
      92             205 :     for (Entry* entry = mEntries; entry != nsnull; entry = entry->mNext) {
      93             205 :         if (StringBeginsWith(aURI, entry->mURI))
      94             205 :             return const_iterator(entry);
      95                 :     }
      96                 : 
      97               0 :     return last();
      98                 : }

Generated by: LCOV version 1.7