Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / dom / xslt / xslt / txOutputFormat.cpp
blobfe4d068f6e44d804fa8c179ca6850265db4d9484
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "txOutputFormat.h"
7 #include "txXMLUtils.h"
8 #include "txExpandedName.h"
10 txOutputFormat::txOutputFormat()
11 : mMethod(eMethodNotSet),
12 mOmitXMLDeclaration(eNotSet),
13 mStandalone(eNotSet),
14 mIndent(eNotSet) {}
16 txOutputFormat::~txOutputFormat() {
17 txListIterator iter(&mCDATASectionElements);
18 while (iter.hasNext()) delete (txExpandedName*)iter.next();
21 void txOutputFormat::reset() {
22 mMethod = eMethodNotSet;
23 mVersion.Truncate();
24 if (mEncoding.IsEmpty()) mOmitXMLDeclaration = eNotSet;
25 mStandalone = eNotSet;
26 mPublicId.Truncate();
27 mSystemId.Truncate();
28 txListIterator iter(&mCDATASectionElements);
29 while (iter.hasNext()) delete (txExpandedName*)iter.next();
30 mIndent = eNotSet;
31 mMediaType.Truncate();
34 void txOutputFormat::merge(txOutputFormat& aOutputFormat) {
35 if (mMethod == eMethodNotSet) mMethod = aOutputFormat.mMethod;
37 if (mVersion.IsEmpty()) mVersion = aOutputFormat.mVersion;
39 if (mEncoding.IsEmpty()) mEncoding = aOutputFormat.mEncoding;
41 if (mOmitXMLDeclaration == eNotSet)
42 mOmitXMLDeclaration = aOutputFormat.mOmitXMLDeclaration;
44 if (mStandalone == eNotSet) mStandalone = aOutputFormat.mStandalone;
46 if (mPublicId.IsEmpty()) mPublicId = aOutputFormat.mPublicId;
48 if (mSystemId.IsEmpty()) mSystemId = aOutputFormat.mSystemId;
50 txListIterator iter(&aOutputFormat.mCDATASectionElements);
51 txExpandedName* qName;
52 while ((qName = (txExpandedName*)iter.next())) {
53 mCDATASectionElements.add(qName);
54 // XXX We need txList.clear()
55 iter.remove();
58 if (mIndent == eNotSet) mIndent = aOutputFormat.mIndent;
60 if (mMediaType.IsEmpty()) mMediaType = aOutputFormat.mMediaType;
63 void txOutputFormat::setFromDefaults() {
64 switch (mMethod) {
65 case eMethodNotSet: {
66 mMethod = eXMLOutput;
67 [[fallthrough]];
69 case eXMLOutput: {
70 if (mVersion.IsEmpty()) mVersion.AppendLiteral("1.0");
72 if (mEncoding.IsEmpty()) mEncoding.AppendLiteral("UTF-8");
74 if (mOmitXMLDeclaration == eNotSet) mOmitXMLDeclaration = eFalse;
76 if (mIndent == eNotSet) mIndent = eFalse;
78 if (mMediaType.IsEmpty()) mMediaType.AppendLiteral("text/xml");
80 break;
82 case eHTMLOutput: {
83 if (mVersion.IsEmpty()) mVersion.AppendLiteral("4.0");
85 if (mEncoding.IsEmpty()) mEncoding.AppendLiteral("UTF-8");
87 if (mIndent == eNotSet) mIndent = eTrue;
89 if (mMediaType.IsEmpty()) mMediaType.AppendLiteral("text/html");
91 break;
93 case eTextOutput: {
94 if (mEncoding.IsEmpty()) mEncoding.AppendLiteral("UTF-8");
96 if (mMediaType.IsEmpty()) mMediaType.AppendLiteral("text/plain");
98 break;