backout 29799f914cab, Bug 917642 - [Helix] Please update the helix blobs
[gecko.git] / parser / html / nsHtml5Atom.cpp
blobbb8d062ad3d7f55b784b493fde439fba7ca08115
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsHtml5Atom.h"
6 #include "nsAutoPtr.h"
8 nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
10 mLength = aString.Length();
11 nsRefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
12 if (buf) {
13 mString = static_cast<PRUnichar*>(buf->Data());
14 } else {
15 buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(PRUnichar));
16 mString = static_cast<PRUnichar*>(buf->Data());
17 CopyUnicodeTo(aString, 0, mString, mLength);
18 mString[mLength] = PRUnichar(0);
21 NS_ASSERTION(mString[mLength] == PRUnichar(0), "null terminated");
22 NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(PRUnichar),
23 "enough storage");
24 NS_ASSERTION(Equals(aString), "correct data");
26 // Take ownership of buffer
27 buf.forget();
30 nsHtml5Atom::~nsHtml5Atom()
32 nsStringBuffer::FromData(mString)->Release();
35 NS_IMETHODIMP_(nsrefcnt)
36 nsHtml5Atom::AddRef()
38 NS_NOTREACHED("Attempt to AddRef an nsHtml5Atom.");
39 return 2;
42 NS_IMETHODIMP_(nsrefcnt)
43 nsHtml5Atom::Release()
45 NS_NOTREACHED("Attempt to Release an nsHtml5Atom.");
46 return 1;
49 NS_IMETHODIMP
50 nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr)
52 NS_NOTREACHED("Attempt to call QueryInterface an nsHtml5Atom.");
53 return NS_ERROR_UNEXPECTED;
56 NS_IMETHODIMP
57 nsHtml5Atom::ScriptableToString(nsAString& aBuf)
59 NS_NOTREACHED("Should not call ScriptableToString.");
60 return NS_ERROR_NOT_IMPLEMENTED;
63 NS_IMETHODIMP
64 nsHtml5Atom::ToUTF8String(nsACString& aReturn)
66 NS_NOTREACHED("Should not attempt to convert to an UTF-8 string.");
67 return NS_ERROR_NOT_IMPLEMENTED;
70 NS_IMETHODIMP_(bool)
71 nsHtml5Atom::IsStaticAtom()
73 return false;
76 NS_IMETHODIMP
77 nsHtml5Atom::ScriptableEquals(const nsAString& aString, bool* aResult)
79 NS_NOTREACHED("Should not call ScriptableEquals.");
80 return NS_ERROR_NOT_IMPLEMENTED;
83 NS_IMETHODIMP_(bool)
84 nsHtml5Atom::EqualsUTF8(const nsACString& aString)
86 NS_NOTREACHED("Should not attempt to compare with an UTF-8 string.");
87 return false;