rdf/base/src/nsNameSpaceMap.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.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  *
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "nsNameSpaceMap.h"
     8 #include "nsReadableUtils.h"
    10 nsNameSpaceMap::nsNameSpaceMap()
    11     : mEntries(nullptr)
    12 {
    13     MOZ_COUNT_CTOR(nsNameSpaceMap);
    14 }
    16 nsNameSpaceMap::~nsNameSpaceMap()
    17 {
    18     MOZ_COUNT_DTOR(nsNameSpaceMap);
    20     while (mEntries) {
    21         Entry* doomed = mEntries;
    22         mEntries = mEntries->mNext;
    23         delete doomed;
    24     }
    25 }
    27 nsresult
    28 nsNameSpaceMap::Put(const nsAString& aURI, nsIAtom* aPrefix)
    29 {
    30     nsCString uriUTF8;
    31     AppendUTF16toUTF8(aURI, uriUTF8);
    32     return Put(uriUTF8, aPrefix);
    33 }
    35 nsresult
    36 nsNameSpaceMap::Put(const nsCSubstring& aURI, nsIAtom* aPrefix)
    37 {
    38     Entry* entry;
    40     // Make sure we're not adding a duplicate
    41     for (entry = mEntries; entry != nullptr; entry = entry->mNext) {
    42         if (entry->mURI == aURI || entry->mPrefix == aPrefix)
    43             return NS_ERROR_FAILURE;
    44     }
    46     entry = new Entry(aURI, aPrefix);
    47     if (! entry)
    48         return NS_ERROR_OUT_OF_MEMORY;
    50     entry->mNext = mEntries;
    51     mEntries = entry;
    52     return NS_OK;
    53 }
    55 nsNameSpaceMap::const_iterator
    56 nsNameSpaceMap::GetNameSpaceOf(const nsCSubstring& aURI) const
    57 {
    58     for (Entry* entry = mEntries; entry != nullptr; entry = entry->mNext) {
    59         if (StringBeginsWith(aURI, entry->mURI))
    60             return const_iterator(entry);
    61     }
    63     return last();
    64 }

mercurial