2001-05-15 22:48:17 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2001-05-15 22:48:17 +04:00
|
|
|
|
|
|
|
#include "nsNameSpaceMap.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
|
|
|
|
nsNameSpaceMap::nsNameSpaceMap()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mEntries(nullptr)
|
2001-05-15 22:48:17 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsNameSpaceMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNameSpaceMap::~nsNameSpaceMap()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsNameSpaceMap);
|
|
|
|
|
|
|
|
while (mEntries) {
|
|
|
|
Entry* doomed = mEntries;
|
|
|
|
mEntries = mEntries->mNext;
|
|
|
|
delete doomed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-10-03 01:05:19 +03:00
|
|
|
nsNameSpaceMap::Put(const nsAString& aURI, nsAtom* aPrefix)
|
2004-09-10 00:17:36 +04:00
|
|
|
{
|
|
|
|
nsCString uriUTF8;
|
|
|
|
AppendUTF16toUTF8(aURI, uriUTF8);
|
|
|
|
return Put(uriUTF8, aPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-10-03 01:05:19 +03:00
|
|
|
nsNameSpaceMap::Put(const nsACString& aURI, nsAtom* aPrefix)
|
2001-05-15 22:48:17 +04:00
|
|
|
{
|
|
|
|
Entry* entry;
|
|
|
|
|
|
|
|
// Make sure we're not adding a duplicate
|
2012-07-30 18:20:58 +04:00
|
|
|
for (entry = mEntries; entry != nullptr; entry = entry->mNext) {
|
2001-05-15 22:48:17 +04:00
|
|
|
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
|
2017-06-20 12:19:52 +03:00
|
|
|
nsNameSpaceMap::GetNameSpaceOf(const nsACString& aURI) const
|
2001-05-15 22:48:17 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
for (Entry* entry = mEntries; entry != nullptr; entry = entry->mNext) {
|
2003-07-14 11:37:39 +04:00
|
|
|
if (StringBeginsWith(aURI, entry->mURI))
|
2001-05-15 22:48:17 +04:00
|
|
|
return const_iterator(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return last();
|
|
|
|
}
|