OpenShot Audio Library | OpenShotAudio  0.6.0
juce_XmlDocument.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  The code included in this file is provided under the terms of the ISC license
11  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12  To use, copy, modify, and/or distribute this software for any purpose with or
13  without fee is hereby granted provided that the above copyright notice and
14  this permission notice appear in all copies.
15 
16  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18  DISCLAIMED.
19 
20  ==============================================================================
21 */
22 
23 namespace juce
24 {
25 
26 //==============================================================================
63 class JUCE_API XmlDocument
64 {
65 public:
66  //==============================================================================
70  XmlDocument (const String& documentText);
71 
75  XmlDocument (const File& file);
76 
78  ~XmlDocument();
79 
80  //==============================================================================
99  std::unique_ptr<XmlElement> getDocumentElement (bool onlyReadOuterDocumentElement = false);
100 
105  std::unique_ptr<XmlElement> getDocumentElementIfTagMatches (StringRef requiredTag);
106 
110  const String& getLastParseError() const noexcept;
111 
123  void setInputSource (InputSource* newSource) noexcept;
124 
132  void setEmptyTextElementsIgnored (bool shouldBeIgnored) noexcept;
133 
134  //==============================================================================
139  static std::unique_ptr<XmlElement> parse (const File& file);
140 
145  static std::unique_ptr<XmlElement> parse (const String& xmlData);
146 
147 
148  //==============================================================================
149 private:
150  String originalText;
151  String::CharPointerType input { nullptr };
152  bool outOfData = false, errorOccurred = false;
153  String lastError, dtdText;
154  StringArray tokenisedDTD;
155  bool needToLoadDTD = false, ignoreEmptyTextElements = true;
156  std::unique_ptr<InputSource> inputSource;
157 
158  std::unique_ptr<XmlElement> parseDocumentElement (String::CharPointerType, bool outer);
159  void setLastError (const String&, bool carryOn);
160  bool parseHeader();
161  bool parseDTD();
162  void skipNextWhiteSpace();
163  juce_wchar readNextChar() noexcept;
164  XmlElement* readNextElement (bool alsoParseSubElements);
165  void readChildElements (XmlElement&);
166  void readQuotedString (String&);
167  void readEntity (String&);
168 
169  String getFileContents (const String&) const;
170  String expandEntity (const String&);
171  String expandExternalEntity (const String&);
172  String getParameterEntity (const String&);
173 
174  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (XmlDocument)
175 };
176 
177 //==============================================================================
183 std::unique_ptr<XmlElement> parseXML (const String& textToParse);
184 
190 std::unique_ptr<XmlElement> parseXML (const File& fileToParse);
191 
197 std::unique_ptr<XmlElement> parseXMLIfTagMatches (const String& textToParse, StringRef requiredTag);
198 
204 std::unique_ptr<XmlElement> parseXMLIfTagMatches (const File& fileToParse, StringRef requiredTag);
205 
206 
207 } // namespace juce