rdf/base/src/nsNameSpaceMap.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rdf/base/src/nsNameSpaceMap.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsNameSpaceMap.h"
    1.11 +#include "nsReadableUtils.h"
    1.12 +
    1.13 +nsNameSpaceMap::nsNameSpaceMap()
    1.14 +    : mEntries(nullptr)
    1.15 +{
    1.16 +    MOZ_COUNT_CTOR(nsNameSpaceMap);
    1.17 +}
    1.18 +
    1.19 +nsNameSpaceMap::~nsNameSpaceMap()
    1.20 +{
    1.21 +    MOZ_COUNT_DTOR(nsNameSpaceMap);
    1.22 +
    1.23 +    while (mEntries) {
    1.24 +        Entry* doomed = mEntries;
    1.25 +        mEntries = mEntries->mNext;
    1.26 +        delete doomed;
    1.27 +    }
    1.28 +}
    1.29 +
    1.30 +nsresult
    1.31 +nsNameSpaceMap::Put(const nsAString& aURI, nsIAtom* aPrefix)
    1.32 +{
    1.33 +    nsCString uriUTF8;
    1.34 +    AppendUTF16toUTF8(aURI, uriUTF8);
    1.35 +    return Put(uriUTF8, aPrefix);
    1.36 +}
    1.37 +
    1.38 +nsresult
    1.39 +nsNameSpaceMap::Put(const nsCSubstring& aURI, nsIAtom* aPrefix)
    1.40 +{
    1.41 +    Entry* entry;
    1.42 +
    1.43 +    // Make sure we're not adding a duplicate
    1.44 +    for (entry = mEntries; entry != nullptr; entry = entry->mNext) {
    1.45 +        if (entry->mURI == aURI || entry->mPrefix == aPrefix)
    1.46 +            return NS_ERROR_FAILURE;
    1.47 +    }
    1.48 +
    1.49 +    entry = new Entry(aURI, aPrefix);
    1.50 +    if (! entry)
    1.51 +        return NS_ERROR_OUT_OF_MEMORY;
    1.52 +
    1.53 +    entry->mNext = mEntries;
    1.54 +    mEntries = entry;
    1.55 +    return NS_OK;
    1.56 +}
    1.57 +
    1.58 +nsNameSpaceMap::const_iterator
    1.59 +nsNameSpaceMap::GetNameSpaceOf(const nsCSubstring& aURI) const
    1.60 +{
    1.61 +    for (Entry* entry = mEntries; entry != nullptr; entry = entry->mNext) {
    1.62 +        if (StringBeginsWith(aURI, entry->mURI))
    1.63 +            return const_iterator(entry);
    1.64 +    }
    1.65 +
    1.66 +    return last();
    1.67 +}

mercurial