From 768139a298254bfdb01b871e4b061664ad22f21c Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 15 Oct 2018 16:08:25 +0100 Subject: [PATCH] Added some free functions to help make XML parsing less verbose: parseXML() --- examples/GUI/WidgetsDemo.h | 2 +- extras/NetworkGraphicsDemo/Source/Demos.h | 3 +- .../jucer_SVGPathDataWindowComponent.h | 4 +- .../Source/Application/jucer_CommandLine.cpp | 2 +- .../CodeEditor/jucer_ItemPreviewComponent.h | 6 +-- .../UI/jucer_JucerDocumentEditor.cpp | 8 +--- .../jucer_CompileEngineClient.cpp | 2 +- .../UI/jucer_ProjectContentComponent.cpp | 6 ++- .../Projucer/Source/Project/jucer_Project.cpp | 2 +- .../jucer_ProjectExport_Android.h | 15 ++++--- .../ProjectSaving/jucer_ProjectExport_Xcode.h | 6 +-- .../Settings/jucer_AppearanceSettings.cpp | 12 +++--- .../jucer_TemplateThumbnailsComponent.h | 6 +-- .../codecs/juce_WavAudioFormat.cpp | 19 ++++----- .../format_types/juce_VSTPluginFormat.cpp | 6 +-- modules/juce_core/xml/juce_XmlDocument.cpp | 10 +++++ modules/juce_core/xml/juce_XmlDocument.h | 30 +++++++++++--- .../native/juce_win32_Messaging.cpp | 8 ++-- .../juce_graphics/native/juce_linux_Fonts.cpp | 10 ++--- .../lookandfeel/juce_LookAndFeel_V2.cpp | 2 +- .../misc/juce_JUCESplashScreen.cpp | 3 +- .../widgets/juce_TableHeaderComponent.cpp | 40 ++++++++++--------- .../marketplace/juce_OnlineUnlockStatus.cpp | 8 ++-- 23 files changed, 116 insertions(+), 94 deletions(-) diff --git a/examples/GUI/WidgetsDemo.h b/examples/GUI/WidgetsDemo.h index 87ab0453b3..a3dfe9dbd4 100644 --- a/examples/GUI/WidgetsDemo.h +++ b/examples/GUI/WidgetsDemo.h @@ -1030,7 +1030,7 @@ private: // this loads the embedded database XML file into memory void loadData() { - demoData.reset (XmlDocument::parse (loadEntireAssetIntoString ("demo table data.xml"))); + demoData = parseXML (loadEntireAssetIntoString ("demo table data.xml")); dataList = demoData->getChildByName ("DATA"); columnList = demoData->getChildByName ("COLUMNS"); diff --git a/extras/NetworkGraphicsDemo/Source/Demos.h b/extras/NetworkGraphicsDemo/Source/Demos.h index 24517755e7..505e50f1d2 100644 --- a/extras/NetworkGraphicsDemo/Source/Demos.h +++ b/extras/NetworkGraphicsDemo/Source/Demos.h @@ -84,8 +84,7 @@ struct BackgroundLogo : public AnimatedContent )blahblah"; - std::unique_ptr svg (XmlDocument::parse (logoData)); - logo.reset (Drawable::createFromSVG (*svg)); + logo.reset (Drawable::createFromSVG (*parseXML (logoData))); } String getName() const override { return "Background Image"; } diff --git a/extras/Projucer/Source/Application/Windows/jucer_SVGPathDataWindowComponent.h b/extras/Projucer/Source/Application/Windows/jucer_SVGPathDataWindowComponent.h index fed80a62aa..a3cc6ba703 100644 --- a/extras/Projucer/Source/Application/Windows/jucer_SVGPathDataWindowComponent.h +++ b/extras/Projucer/Source/Application/Windows/jucer_SVGPathDataWindowComponent.h @@ -163,9 +163,7 @@ public: dragOver = false; repaint(); - std::unique_ptr element (XmlDocument::parse (File (files[0]))); - - if (element != nullptr) + if (auto element = parseXML (File (files[0]))) { if (auto* ePath = element->getChildByName ("path")) userText.setText (ePath->getStringAttribute ("d"), true); diff --git a/extras/Projucer/Source/Application/jucer_CommandLine.cpp b/extras/Projucer/Source/Application/jucer_CommandLine.cpp index d498a83d33..a97de85799 100644 --- a/extras/Projucer/Source/Application/jucer_CommandLine.cpp +++ b/extras/Projucer/Source/Application/jucer_CommandLine.cpp @@ -713,7 +713,7 @@ namespace #endif auto settingsFile = userAppData.getChildFile ("Projucer").getChildFile ("Projucer.settings"); - std::unique_ptr xml (XmlDocument::parse (settingsFile)); + auto xml = parseXML (settingsFile); if (xml == nullptr) ConsoleApplication::fail ("Settings file not valid!"); diff --git a/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h b/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h index 0cfc8e7935..e2133316be 100644 --- a/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h +++ b/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h @@ -108,12 +108,8 @@ private: } if (drawable == nullptr) - { - std::unique_ptr svg (XmlDocument::parse (file)); - - if (svg != nullptr) + if (auto svg = parseXML (file)) drawable.reset (Drawable::createFromSVG (*svg)); - } facts.removeEmptyStrings (true); } diff --git a/extras/Projucer/Source/ComponentEditor/UI/jucer_JucerDocumentEditor.cpp b/extras/Projucer/Source/ComponentEditor/UI/jucer_JucerDocumentEditor.cpp index b75b38d52c..da36ea9e9f 100644 --- a/extras/Projucer/Source/ComponentEditor/UI/jucer_JucerDocumentEditor.cpp +++ b/extras/Projucer/Source/ComponentEditor/UI/jucer_JucerDocumentEditor.cpp @@ -938,9 +938,7 @@ void JucerDocumentEditor::getCommandInfo (const CommandID commandID, Application bool canPaste = false; - std::unique_ptr doc (XmlDocument::parse (SystemClipboard::getTextFromClipboard())); - - if (doc != nullptr) + if (auto doc = parseXML (SystemClipboard::getTextFromClipboard())) { if (doc->hasTagName (ComponentLayout::clipboardXmlTag)) canPaste = (currentLayout != nullptr); @@ -1156,9 +1154,7 @@ bool JucerDocumentEditor::perform (const InvocationInfo& info) case StandardApplicationCommandIDs::paste: { - std::unique_ptr doc (XmlDocument::parse (SystemClipboard::getTextFromClipboard())); - - if (doc != nullptr) + if (auto doc = parseXML (SystemClipboard::getTextFromClipboard())) { if (doc->hasTagName (ComponentLayout::clipboardXmlTag)) { diff --git a/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp b/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp index 042aa71bfe..93e0e55df6 100644 --- a/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp +++ b/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp @@ -422,7 +422,7 @@ private: { auto liveModules = project.getProjectRoot().getChildWithName (Ids::MODULES); - std::unique_ptr xml (XmlDocument::parse (project.getFile())); + auto xml = parseXML (project.getFile()); if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString())) return false; diff --git a/extras/Projucer/Source/Project/UI/jucer_ProjectContentComponent.cpp b/extras/Projucer/Source/Project/UI/jucer_ProjectContentComponent.cpp index 8e208d6167..4896430cc7 100644 --- a/extras/Projucer/Source/Project/UI/jucer_ProjectContentComponent.cpp +++ b/extras/Projucer/Source/Project/UI/jucer_ProjectContentComponent.cpp @@ -39,8 +39,10 @@ struct LogoComponent : public Component { LogoComponent() { - std::unique_ptr svg (XmlDocument::parse (BinaryData::background_logo_svg)); - logo.reset (Drawable::createFromSVG (*svg)); + if (auto svg = parseXML (BinaryData::background_logo_svg)) + logo.reset (Drawable::createFromSVG (*svg)); + else + jassertfalse; } void paint (Graphics& g) override diff --git a/extras/Projucer/Source/Project/jucer_Project.cpp b/extras/Projucer/Source/Project/jucer_Project.cpp index fe23945a41..ac8394a2f7 100644 --- a/extras/Projucer/Source/Project/jucer_Project.cpp +++ b/extras/Projucer/Source/Project/jucer_Project.cpp @@ -552,7 +552,7 @@ static void forgetRecentFile (const File& file) //============================================================================== Result Project::loadDocument (const File& file) { - std::unique_ptr xml (XmlDocument::parse (file)); + auto xml = parseXML (file); if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString())) return Result::fail ("Not a valid Jucer project!"); diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h index 2275ebc377..afa53759c7 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h @@ -1404,12 +1404,17 @@ private: customStringsXmlContent << cfg.getCustomStringsXml(); customStringsXmlContent << "\n"; - std::unique_ptr strings (XmlDocument::parse (customStringsXmlContent)); - - String dir = cfg.isDebug() ? "debug" : "release"; - String subPath = "app/src/" + dir + "/res/values/string.xml"; + if (auto strings = parseXML (customStringsXmlContent)) + { + String dir = cfg.isDebug() ? "debug" : "release"; + String subPath = "app/src/" + dir + "/res/values/string.xml"; - writeXmlOrThrow (*strings, folder.getChildFile (subPath), "utf-8", 100, true); + writeXmlOrThrow (*strings, folder.getChildFile (subPath), "utf-8", 100, true); + } + else + { + jassertfalse; // needs handling? + } } } diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h index 009eab2b16..4f50386851 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h @@ -1345,7 +1345,7 @@ public: if (! shouldCreatePList()) return; - std::unique_ptr plist (XmlDocument::parse (owner.getPListToMergeString())); + auto plist = parseXML (owner.getPListToMergeString()); if (plist == nullptr || ! plist->hasTagName ("plist")) plist.reset (new XmlElement ("plist")); @@ -3195,9 +3195,7 @@ private: bool xcschemeManagementPlistMatchesTargets (const File& plist) const { - std::unique_ptr xml (XmlDocument::parse (plist)); - - if (xml != nullptr) + if (auto xml = parseXML (plist)) if (auto* dict = xml->getChildByName ("dict")) return parseNamesOfTargetsFromPlist (*dict) == getNamesOfTargets(); diff --git a/extras/Projucer/Source/Settings/jucer_AppearanceSettings.cpp b/extras/Projucer/Source/Settings/jucer_AppearanceSettings.cpp index d195a7f4a2..e43d035125 100644 --- a/extras/Projucer/Source/Settings/jucer_AppearanceSettings.cpp +++ b/extras/Projucer/Source/Settings/jucer_AppearanceSettings.cpp @@ -64,13 +64,11 @@ File AppearanceSettings::getSchemesFolder() void AppearanceSettings::writeDefaultSchemeFile (const String& xmlString, const String& name) { - const File file (getSchemesFolder().getChildFile (name).withFileExtension (getSchemeFileSuffix())); + auto file = getSchemesFolder().getChildFile (name).withFileExtension (getSchemeFileSuffix()); AppearanceSettings settings (false); - std::unique_ptr xml (XmlDocument::parse (xmlString)); - - if (xml != nullptr) + if (auto xml = parseXML (xmlString)) settings.readFromXML (*xml); settings.writeToFile (file); @@ -132,8 +130,10 @@ bool AppearanceSettings::readFromXML (const XmlElement& xml) bool AppearanceSettings::readFromFile (const File& file) { - const std::unique_ptr xml (XmlDocument::parse (file)); - return xml != nullptr && readFromXML (*xml); + if (auto xml = parseXML (file)) + return readFromXML (*xml); + + return false; } bool AppearanceSettings::writeToFile (const File& file) const diff --git a/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h b/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h index f7e1d174eb..3ae5142dd1 100644 --- a/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h +++ b/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h @@ -39,15 +39,13 @@ public: : DrawableButton (buttonName, buttonStyle) { // svg for thumbnail icon - std::unique_ptr svg (XmlDocument::parse (thumbSvg)); + auto svg = parseXML (thumbSvg); jassert (svg != nullptr); - thumb.reset (Drawable::createFromSVG (*svg)); // svg for thumbnail background highlight - std::unique_ptr backSvg (XmlDocument::parse (BinaryData::wizard_Highlight_svg)); + auto backSvg = parseXML (BinaryData::wizard_Highlight_svg); jassert (backSvg != nullptr); - hoverBackground.reset (Drawable::createFromSVG (*backSvg)); name = buttonName; diff --git a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp index 975e86daaf..bd44388f72 100644 --- a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp @@ -849,20 +849,21 @@ namespace WavFileHelpers { static void addToMetadata (StringPairArray& destValues, const String& source) { - std::unique_ptr xml (XmlDocument::parse (source)); - - if (xml != nullptr && xml->hasTagName ("ebucore:ebuCoreMain")) + if (auto xml = parseXML (source)) { - if (auto* xml2 = xml->getChildByName ("ebucore:coreMetadata")) + if (xml->hasTagName ("ebucore:ebuCoreMain")) { - if (auto* xml3 = xml2->getChildByName ("ebucore:identifier")) + if (auto xml2 = xml->getChildByName ("ebucore:coreMetadata")) { - if (auto* xml4 = xml3->getChildByName ("dc:identifier")) + if (auto xml3 = xml2->getChildByName ("ebucore:identifier")) { - auto ISRCCode = xml4->getAllSubText().fromFirstOccurrenceOf ("ISRC:", false, true); + if (auto xml4 = xml3->getChildByName ("dc:identifier")) + { + auto ISRCCode = xml4->getAllSubText().fromFirstOccurrenceOf ("ISRC:", false, true); - if (ISRCCode.isNotEmpty()) - destValues.set (WavAudioFormat::ISRC, ISRCCode); + if (ISRCCode.isNotEmpty()) + destValues.set (WavAudioFormat::ISRC, ISRCCode); + } } } } diff --git a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp index 7259a3f03f..c61d6a15f7 100644 --- a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp @@ -661,11 +661,11 @@ struct ModuleHandle : public ReferenceCountedObject if (moduleMain != nullptr) { - vstXml.reset (XmlDocument::parse (file.withFileExtension ("vstxml"))); + vstXml = parseXML (file.withFileExtension ("vstxml")); #if JUCE_WINDOWS if (vstXml == nullptr) - vstXml.reset (XmlDocument::parse (getDLLResource (file, "VSTXML", 1))); + vstXml = parseXML (getDLLResource (file, "VSTXML", 1)); #endif } @@ -772,7 +772,7 @@ struct ModuleHandle : public ReferenceCountedObject .findChildFiles (File::findFiles, false, "*.vstxml"); if (! vstXmlFiles.isEmpty()) - vstXml.reset (XmlDocument::parse (vstXmlFiles.getReference(0))); + vstXml = parseXML (vstXmlFiles.getReference(0)); } } diff --git a/modules/juce_core/xml/juce_XmlDocument.cpp b/modules/juce_core/xml/juce_XmlDocument.cpp index 6dcd518fc6..3132841587 100644 --- a/modules/juce_core/xml/juce_XmlDocument.cpp +++ b/modules/juce_core/xml/juce_XmlDocument.cpp @@ -40,6 +40,16 @@ XmlElement* XmlDocument::parse (const String& xmlData) return doc.getDocumentElement(); } +std::unique_ptr parseXML (const String& textToParse) +{ + return std::unique_ptr (XmlDocument::parse (textToParse)); +} + +std::unique_ptr parseXML (const File& fileToParse) +{ + return std::unique_ptr (XmlDocument::parse (fileToParse)); +} + void XmlDocument::setInputSource (InputSource* newSource) noexcept { inputSource.reset (newSource); diff --git a/modules/juce_core/xml/juce_XmlDocument.h b/modules/juce_core/xml/juce_XmlDocument.h index 997e16fa39..267d565c3f 100644 --- a/modules/juce_core/xml/juce_XmlDocument.h +++ b/modules/juce_core/xml/juce_XmlDocument.h @@ -47,14 +47,15 @@ namespace juce @endcode - Or you can use the static helper methods for quick parsing.. + Or you can use the helper functions for much less verbose parsing.. @code - std::unique_ptr xml (XmlDocument::parse (myXmlFile)); - - if (xml != nullptr && xml->hasTagName ("foobar")) + if (auto xml = parseXML (myXmlFile)) { - ...etc + if (xml->hasTagName ("foobar")) + { + ...etc + } } @endcode @@ -132,12 +133,14 @@ public: //============================================================================== /** A handy static method that parses a file. This is a shortcut for creating an XmlDocument object and calling getDocumentElement() on it. + An even better shortcut is the juce::parseXML() function, which returns a std::unique_ptr! @returns a new XmlElement which the caller will need to delete, or null if there was an error. */ static XmlElement* parse (const File& file); /** A handy static method that parses some XML data. This is a shortcut for creating an XmlDocument object and calling getDocumentElement() on it. + An even better shortcut is the juce::parseXML() function, which returns a std::unique_ptr! @returns a new XmlElement which the caller will need to delete, or null if there was an error. */ static XmlElement* parse (const String& xmlData); @@ -172,4 +175,21 @@ private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (XmlDocument) }; +//============================================================================== +/** Attempts to parse some XML text, returning a new XmlElement if it was valid. + If the parse fails, this will return a nullptr - if you need more information about + errors or more parsing options, see the XmlDocument instead. + @see XmlDocument +*/ +std::unique_ptr parseXML (const String& textToParse); + +/** Attempts to parse some XML text, returning a new XmlElement if it was valid. + If the parse fails, this will return a nullptr - if you need more information about + errors or more parsing options, see the XmlDocument instead. + @see XmlDocument +*/ +std::unique_ptr parseXML (const File& fileToParse); + + + } // namespace juce diff --git a/modules/juce_events/native/juce_win32_Messaging.cpp b/modules/juce_events/native/juce_win32_Messaging.cpp index ace74804f1..d9eabdf5cd 100644 --- a/modules/juce_events/native/juce_win32_Messaging.cpp +++ b/modules/juce_events/native/juce_win32_Messaging.cpp @@ -46,7 +46,7 @@ namespace WindowsMessageHelpers void dispatchMessageFromLParam (LPARAM lParam) { - if (MessageManager::MessageBase* message = reinterpret_cast (lParam)) + if (auto message = reinterpret_cast (lParam)) { JUCE_TRY { @@ -154,7 +154,7 @@ bool MessageManager::dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMes { // if it's someone else's window being clicked on, and the focus is // currently on a juce window, pass the kb focus over.. - HWND currentFocus = GetFocus(); + auto currentFocus = GetFocus(); if (currentFocus == 0 || JuceWindowIdentifier::isJUCEWindow (currentFocus)) SetFocus (m.hwnd); @@ -175,14 +175,14 @@ bool MessageManager::postMessageToSystemQueue (MessageManager::MessageBase* cons #if JUCE_MODULE_AVAILABLE_juce_audio_plugin_client && JucePlugin_Build_Unity if (juce_isRunningInUnity()) return SendNotifyMessage (juce_messageWindowHandle, WindowsMessageHelpers::customMessageID, 0, (LPARAM) message) != 0; - else #endif + return PostMessage (juce_messageWindowHandle, WindowsMessageHelpers::customMessageID, 0, (LPARAM) message) != 0; } void MessageManager::broadcastMessage (const String& value) { - const String localCopy (value); + auto localCopy = value; Array windows; EnumWindows (&WindowsMessageHelpers::broadcastEnumWindowProc, (LPARAM) &windows); diff --git a/modules/juce_graphics/native/juce_linux_Fonts.cpp b/modules/juce_graphics/native/juce_linux_Fonts.cpp index 3b356ec53e..bff6dfac10 100644 --- a/modules/juce_graphics/native/juce_linux_Fonts.cpp +++ b/modules/juce_graphics/native/juce_linux_Fonts.cpp @@ -27,16 +27,16 @@ namespace juce { -static XmlElement* findFontsConfFile() +static std::unique_ptr findFontsConfFile() { static const char* pathsToSearch[] = { "/etc/fonts/fonts.conf", "/usr/share/fonts/fonts.conf" }; for (auto* path : pathsToSearch) - if (auto* xml = XmlDocument::parse (File (path))) + if (auto xml = parseXML (File (path))) return xml; - return nullptr; + return {}; } StringArray FTTypefaceList::getDefaultFontDirectories() @@ -48,9 +48,7 @@ StringArray FTTypefaceList::getDefaultFontDirectories() if (fontDirs.isEmpty()) { - std::unique_ptr fontsInfo (findFontsConfFile()); - - if (fontsInfo != nullptr) + if (auto fontsInfo = findFontsConfFile()) { forEachXmlChildElementWithTagName (*fontsInfo, e, "dir") { diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index d30883a100..7f38d0ad8f 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -2655,7 +2655,7 @@ void LookAndFeel_V2::layoutFileBrowserComponent (FileBrowserComponent& browserCo //============================================================================== static Drawable* createDrawableFromSVG (const char* data) { - std::unique_ptr xml (XmlDocument::parse (data)); + auto xml = parseXML (data); jassert (xml != nullptr); return Drawable::createFromSVG (*xml); } diff --git a/modules/juce_gui_basics/misc/juce_JUCESplashScreen.cpp b/modules/juce_gui_basics/misc/juce_JUCESplashScreen.cpp index 3bffb8ef45..b28a73bc85 100644 --- a/modules/juce_gui_basics/misc/juce_JUCESplashScreen.cpp +++ b/modules/juce_gui_basics/misc/juce_JUCESplashScreen.cpp @@ -294,7 +294,8 @@ std::unique_ptr JUCESplashScreen::getSplashScreenLogo() )JUCESPLASHSCREEN"; - std::unique_ptr svgXml (XmlDocument::parse (svgData)); + auto svgXml = parseXML (svgData); + jassert (svgXml != nullptr); return std::unique_ptr (Drawable::createFromSVG (*svgXml)); } diff --git a/modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp b/modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp index a81e0dec9e..ac064df304 100644 --- a/modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp +++ b/modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp @@ -436,40 +436,42 @@ String TableHeaderComponent::toString() const void TableHeaderComponent::restoreFromString (const String& storedVersion) { - std::unique_ptr storedXml (XmlDocument::parse (storedVersion)); - int index = 0; - - if (storedXml != nullptr && storedXml->hasTagName ("TABLELAYOUT")) + if (auto storedXML = parseXML (storedVersion)) { - forEachXmlChildElement (*storedXml, col) + if (storedXML->hasTagName ("TABLELAYOUT")) { - auto tabId = col->getIntAttribute ("id"); + int index = 0; - if (auto* ci = getInfoForId (tabId)) + forEachXmlChildElement (*storedXML, col) { - columns.move (columns.indexOf (ci), index); - ci->width = col->getIntAttribute ("width"); - setColumnVisible (tabId, col->getBoolAttribute ("visible")); - } + auto tabId = col->getIntAttribute ("id"); - ++index; - } + if (auto* ci = getInfoForId (tabId)) + { + columns.move (columns.indexOf (ci), index); + ci->width = col->getIntAttribute ("width"); + setColumnVisible (tabId, col->getBoolAttribute ("visible")); + } - columnsResized = true; - sendColumnsChanged(); + ++index; + } - setSortColumnId (storedXml->getIntAttribute ("sortedCol"), - storedXml->getBoolAttribute ("sortForwards", true)); + columnsResized = true; + sendColumnsChanged(); + + setSortColumnId (storedXML->getIntAttribute ("sortedCol"), + storedXML->getBoolAttribute ("sortForwards", true)); + } } } //============================================================================== -void TableHeaderComponent::addListener (Listener* const newListener) +void TableHeaderComponent::addListener (Listener* newListener) { listeners.addIfNotAlreadyThere (newListener); } -void TableHeaderComponent::removeListener (Listener* const listenerToRemove) +void TableHeaderComponent::removeListener (Listener* listenerToRemove) { listeners.removeFirstMatchingValue (listenerToRemove); } diff --git a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockStatus.cpp b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockStatus.cpp index e5e6b6d532..891499a518 100644 --- a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockStatus.cpp +++ b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockStatus.cpp @@ -120,10 +120,10 @@ struct KeyFileUtils { key.applyToValue (val); - const MemoryBlock mb (val.toMemoryBlock()); + auto mb = val.toMemoryBlock(); if (CharPointer_UTF8::isValidString (static_cast (mb.getData()), (int) mb.getSize())) - xml.reset (XmlDocument::parse (mb.toString())); + xml = parseXML (mb.toString()); } return xml != nullptr ? *xml : XmlElement("key"); @@ -465,9 +465,7 @@ OnlineUnlockStatus::UnlockResult OnlineUnlockStatus::attemptWebserverUnlock (con DBG ("Reply from server: " << reply); - std::unique_ptr xml (XmlDocument::parse (reply)); - - if (xml != nullptr) + if (auto xml = parseXML (reply)) return handleXmlReply (*xml); return handleFailedConnection();