diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /rdf/base/nsNameSpaceMap.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'rdf/base/nsNameSpaceMap.cpp')
-rw-r--r-- | rdf/base/nsNameSpaceMap.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/rdf/base/nsNameSpaceMap.cpp b/rdf/base/nsNameSpaceMap.cpp new file mode 100644 index 000000000..b486a233d --- /dev/null +++ b/rdf/base/nsNameSpaceMap.cpp @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsNameSpaceMap.h" +#include "nsReadableUtils.h" + +nsNameSpaceMap::nsNameSpaceMap() + : mEntries(nullptr) +{ + MOZ_COUNT_CTOR(nsNameSpaceMap); +} + +nsNameSpaceMap::~nsNameSpaceMap() +{ + MOZ_COUNT_DTOR(nsNameSpaceMap); + + while (mEntries) { + Entry* doomed = mEntries; + mEntries = mEntries->mNext; + delete doomed; + } +} + +nsresult +nsNameSpaceMap::Put(const nsAString& aURI, nsIAtom* aPrefix) +{ + nsCString uriUTF8; + AppendUTF16toUTF8(aURI, uriUTF8); + return Put(uriUTF8, aPrefix); +} + +nsresult +nsNameSpaceMap::Put(const nsCSubstring& aURI, nsIAtom* aPrefix) +{ + Entry* entry; + + // Make sure we're not adding a duplicate + for (entry = mEntries; entry != nullptr; entry = entry->mNext) { + if (entry->mURI == aURI || entry->mPrefix == aPrefix) + return NS_ERROR_FAILURE; + } + + entry = new Entry(aURI, aPrefix); + if (! entry) + return NS_ERROR_OUT_OF_MEMORY; + + entry->mNext = mEntries; + mEntries = entry; + return NS_OK; +} + +nsNameSpaceMap::const_iterator +nsNameSpaceMap::GetNameSpaceOf(const nsCSubstring& aURI) const +{ + for (Entry* entry = mEntries; entry != nullptr; entry = entry->mNext) { + if (StringBeginsWith(aURI, entry->mURI)) + return const_iterator(entry); + } + + return last(); +} |