2012-05-29 08:52:43 -07: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/. */
|
2009-09-18 08:13:10 -07:00
|
|
|
|
|
|
|
#include "nsHtml5Atom.h"
|
2013-04-22 04:13:22 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2009-09-18 08:13:10 -07:00
|
|
|
|
|
|
|
nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
|
|
|
|
{
|
2010-03-08 07:45:00 -08:00
|
|
|
mLength = aString.Length();
|
2013-04-22 04:13:22 -07:00
|
|
|
nsRefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
|
2010-03-08 07:45:00 -08:00
|
|
|
if (buf) {
|
|
|
|
mString = static_cast<PRUnichar*>(buf->Data());
|
2013-04-22 04:13:22 -07:00
|
|
|
} else {
|
2010-03-08 07:45:00 -08:00
|
|
|
buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(PRUnichar));
|
|
|
|
mString = static_cast<PRUnichar*>(buf->Data());
|
|
|
|
CopyUnicodeTo(aString, 0, mString, mLength);
|
|
|
|
mString[mLength] = PRUnichar(0);
|
|
|
|
}
|
2010-03-08 08:03:55 -08:00
|
|
|
|
|
|
|
NS_ASSERTION(mString[mLength] == PRUnichar(0), "null terminated");
|
|
|
|
NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(PRUnichar),
|
|
|
|
"enough storage");
|
|
|
|
NS_ASSERTION(Equals(aString), "correct data");
|
2013-04-22 04:13:22 -07:00
|
|
|
|
|
|
|
// Take ownership of buffer
|
|
|
|
buf.forget();
|
2009-09-18 08:13:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5Atom::~nsHtml5Atom()
|
|
|
|
{
|
2010-03-08 07:45:00 -08:00
|
|
|
nsStringBuffer::FromData(mString)->Release();
|
2009-09-18 08:13:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsHtml5Atom::AddRef()
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to AddRef an nsHtml5Atom.");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsHtml5Atom::Release()
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to Release an nsHtml5Atom.");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to call QueryInterface an nsHtml5Atom.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2010-03-08 07:45:00 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHtml5Atom::ScriptableToString(nsAString& aBuf)
|
2009-09-18 08:13:10 -07:00
|
|
|
{
|
2010-03-08 07:45:00 -08:00
|
|
|
NS_NOTREACHED("Should not call ScriptableToString.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2009-09-18 08:13:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHtml5Atom::ToUTF8String(nsACString& aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Should not attempt to convert to an UTF-8 string.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2009-09-18 08:13:10 -07:00
|
|
|
nsHtml5Atom::IsStaticAtom()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-09-18 08:13:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHtml5Atom::ScriptableEquals(const nsAString& aString, bool* aResult)
|
2009-09-18 08:13:10 -07:00
|
|
|
{
|
2010-03-08 07:45:00 -08:00
|
|
|
NS_NOTREACHED("Should not call ScriptableEquals.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2009-09-18 08:13:10 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2010-03-08 07:45:00 -08:00
|
|
|
nsHtml5Atom::EqualsUTF8(const nsACString& aString)
|
2009-09-18 08:13:10 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("Should not attempt to compare with an UTF-8 string.");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-09-18 08:13:10 -07:00
|
|
|
}
|