Update to tinyxml2

This commit is contained in:
David Capello 2024-04-22 18:28:03 -03:00
parent 4d18200b0c
commit e48e71ba28
42 changed files with 495 additions and 7105 deletions

3
.gitmodules vendored
View File

@ -78,3 +78,6 @@
[submodule "third_party/qoi"]
path = third_party/qoi
url = https://github.com/aseprite/qoi.git
[submodule "third_party/tinyxml2"]
path = third_party/tinyxml2
url = https://github.com/aseprite/tinyxml2.git

View File

@ -1,5 +1,5 @@
# Aseprite
# Copyright (C) 2018-2022 Igara Studio S.A.
# Copyright (C) 2018-2024 Igara Studio S.A.
# Copyright (C) 2001-2018 David Capello
cmake_minimum_required(VERSION 3.16)
@ -163,7 +163,7 @@ set(PIXMAN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/pixman)
set(FREETYPE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/freetype2)
set(HARFBUZZ_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/harfbuzz)
set(SIMPLEINI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/simpleini)
set(TINYXML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/tinyxml)
set(TINYXML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/tinyxml2)
set(ZLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib)
# Search in the "cmake" directory for additional CMake modules.
@ -225,12 +225,12 @@ endif()
include_directories(${PNG_INCLUDE_DIRS})
add_definitions(-DPNG_NO_MMX_CODE) # Do not use MMX optimizations in PNG code
# tinyxml
# tinyxml2
if(USE_SHARED_TINYXML)
find_library(TINYXML_LIBRARY NAMES tinyxml)
find_path(TINYXML_INCLUDE_DIR NAMES tinyxml.h)
find_library(TINYXML_LIBRARY NAMES tinyxml2)
find_path(TINYXML_INCLUDE_DIR NAMES tinyxml2.h)
else()
set(TINYXML_LIBRARY tinyxml)
set(TINYXML_LIBRARY tinyxml2)
set(TINYXML_INCLUDE_DIR ${TINYXML_DIR})
endif()
include_directories(${TINYXML_INCLUDE_DIR})

View File

@ -1139,10 +1139,10 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
```
# [tinyxml](http://www.grinninglizard.com/tinyxml/)
# [tinyxml2](https://github.com/leethomason/tinyxml2)
```
TinyXML is released under the zlib license:
Original code by Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
@ -1162,12 +1162,6 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
--
TinyXML was originally written by Lee Thomason. Lee reviews changes
and releases new versions, with the help of Yves Berquin, Andrew
Ellerton, and the tinyXml community.
```
# [ucdn](https://github.com/grigorig/ucdn)

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -23,6 +23,8 @@
#include "doc/image.h"
#include "doc/image_impl.h"
#include "tinyxml2.h"
#include <fstream>
namespace app {
@ -30,15 +32,16 @@ namespace app {
using namespace doc;
using namespace base::serialization;
using namespace base::serialization::little_endian;
using namespace tinyxml2;
namespace {
ImageRef load_xml_image(const TiXmlElement* imageElem)
ImageRef load_xml_image(const XMLElement* imageElem)
{
ImageRef image;
int w, h;
if (imageElem->QueryIntAttribute("width", &w) != TIXML_SUCCESS ||
imageElem->QueryIntAttribute("height", &h) != TIXML_SUCCESS ||
if (imageElem->QueryIntAttribute("width", &w) != XML_SUCCESS ||
imageElem->QueryIntAttribute("height", &h) != XML_SUCCESS ||
w < 0 || w > 9999 ||
h < 0 || h > 9999)
return image;
@ -109,7 +112,7 @@ ImageRef load_xml_image(const TiXmlElement* imageElem)
return image;
}
void save_xml_image(TiXmlElement* imageElem, const Image* image)
void save_xml_image(XMLElement* imageElem, const Image* image)
{
int w = image->width();
int h = image->height();
@ -167,8 +170,7 @@ void save_xml_image(TiXmlElement* imageElem, const Image* image)
std::string data_base64;
base::encode_base64(data, data_base64);
TiXmlText textElem(data_base64.c_str());
imageElem->InsertEndChild(textElem);
imageElem->InsertNewText(data_base64.c_str());
}
} // anonymous namespace
@ -305,11 +307,11 @@ static const int kBrushFlags =
void AppBrushes::load(const std::string& filename)
{
XmlDocumentRef doc = app::open_xml(filename);
TiXmlHandle handle(doc.get());
TiXmlElement* brushElem = handle
.FirstChild("brushes")
.FirstChild("brush").ToElement();
XMLDocumentRef doc = app::open_xml(filename);
XMLHandle handle(doc.get());
XMLElement* brushElem = handle
.FirstChildElement("brushes")
.FirstChildElement("brush").ToElement();
while (brushElem) {
// flags
@ -339,9 +341,9 @@ void AppBrushes::load(const std::string& filename)
// Brush image
ImageRef image, mask;
if (TiXmlElement* imageElem = brushElem->FirstChildElement("image"))
if (XMLElement* imageElem = brushElem->FirstChildElement("image"))
image = load_xml_image(imageElem);
if (TiXmlElement* maskElem = brushElem->FirstChildElement("mask"))
if (XMLElement* maskElem = brushElem->FirstChildElement("mask"))
mask = load_xml_image(maskElem);
if (image) {
@ -351,14 +353,14 @@ void AppBrushes::load(const std::string& filename)
}
// Colors
if (TiXmlElement* fgcolorElem = brushElem->FirstChildElement("fgcolor")) {
if (XMLElement* fgcolorElem = brushElem->FirstChildElement("fgcolor")) {
if (auto value = fgcolorElem->Attribute("value")) {
fgColor = app::Color::fromString(value);
flags |= int(BrushSlot::Flags::FgColor);
}
}
if (TiXmlElement* bgcolorElem = brushElem->FirstChildElement("bgcolor")) {
if (XMLElement* bgcolorElem = brushElem->FirstChildElement("bgcolor")) {
if (auto value = bgcolorElem->Attribute("value")) {
bgColor = app::Color::fromString(value);
flags |= int(BrushSlot::Flags::BgColor);
@ -366,14 +368,14 @@ void AppBrushes::load(const std::string& filename)
}
// Ink
if (TiXmlElement* inkTypeElem = brushElem->FirstChildElement("inktype")) {
if (XMLElement* inkTypeElem = brushElem->FirstChildElement("inktype")) {
if (auto value = inkTypeElem->Attribute("value")) {
inkType = app::tools::string_id_to_ink_type(value);
flags |= int(BrushSlot::Flags::InkType);
}
}
if (TiXmlElement* inkOpacityElem = brushElem->FirstChildElement("inkopacity")) {
if (XMLElement* inkOpacityElem = brushElem->FirstChildElement("inkopacity")) {
if (auto value = inkOpacityElem->Attribute("value")) {
inkOpacity = base::convert_to<int>(std::string(value));
flags |= int(BrushSlot::Flags::InkOpacity);
@ -381,7 +383,7 @@ void AppBrushes::load(const std::string& filename)
}
// Shade
if (TiXmlElement* shadeElem = brushElem->FirstChildElement("shade")) {
if (XMLElement* shadeElem = brushElem->FirstChildElement("shade")) {
if (auto value = shadeElem->Attribute("value")) {
shade = shade_from_string(value);
flags |= int(BrushSlot::Flags::Shade);
@ -389,7 +391,7 @@ void AppBrushes::load(const std::string& filename)
}
// Pixel-perfect
if (TiXmlElement* pixelPerfectElem = brushElem->FirstChildElement("pixelperfect")) {
if (XMLElement* pixelPerfectElem = brushElem->FirstChildElement("pixelperfect")) {
pixelPerfect = bool_attr(pixelPerfectElem, "value", false);
flags |= int(BrushSlot::Flags::PixelPerfect);
}
@ -414,13 +416,13 @@ void AppBrushes::load(const std::string& filename)
void AppBrushes::save(const std::string& filename) const
{
XmlDocumentRef doc(new TiXmlDocument());
TiXmlElement brushesElem("brushes");
//<?xml version="1.0" encoding="utf-8"?>
auto doc = std::make_unique<XMLDocument>();
XMLElement* brushesElem = doc->NewElement("brushes");
doc->InsertEndChild(doc->NewDeclaration("xml version=\"1.0\" encoding=\"utf-8\""));
doc->InsertEndChild(brushesElem);
for (const auto& slot : m_slots) {
TiXmlElement brushElem("brush");
XMLElement* brushElem = brushesElem->InsertNewChildElement("brush");
if (slot.locked()) {
// Flags
int flags = int(slot.flags());
@ -435,32 +437,30 @@ void AppBrushes::save(const std::string& filename) const
ASSERT(slot.brush());
if (flags & int(BrushSlot::Flags::BrushType)) {
brushElem.SetAttribute(
brushElem->SetAttribute(
"type", brush_type_to_string_id(slot.brush()->type()).c_str());
}
if (flags & int(BrushSlot::Flags::BrushSize)) {
brushElem.SetAttribute("size", slot.brush()->size());
brushElem->SetAttribute("size", slot.brush()->size());
}
if (flags & int(BrushSlot::Flags::BrushAngle)) {
brushElem.SetAttribute("angle", slot.brush()->angle());
brushElem->SetAttribute("angle", slot.brush()->angle());
}
if (slot.brush()->type() == kImageBrushType &&
slot.brush()->originalImage()) {
TiXmlElement elem("image");
save_xml_image(&elem, slot.brush()->originalImage());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("image");
save_xml_image(elem, slot.brush()->originalImage());
if (slot.brush()->maskBitmap()) {
TiXmlElement maskElem("mask");
save_xml_image(&maskElem, slot.brush()->maskBitmap());
brushElem.InsertEndChild(maskElem);
XMLElement* maskElem = brushElem->InsertNewChildElement("mask");
save_xml_image(maskElem, slot.brush()->maskBitmap());
}
// Image color
brushElem.SetAttribute(
brushElem->SetAttribute(
"imagecolor",
(flags & int(BrushSlot::Flags::ImageColor)) ? "true": "false");
}
@ -468,53 +468,42 @@ void AppBrushes::save(const std::string& filename) const
// Colors
if (flags & int(BrushSlot::Flags::FgColor)) {
TiXmlElement elem("fgcolor");
elem.SetAttribute("value", slot.fgColor().toString().c_str());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("fgcolor");
elem->SetAttribute("value", slot.fgColor().toString().c_str());
}
if (flags & int(BrushSlot::Flags::BgColor)) {
TiXmlElement elem("bgcolor");
elem.SetAttribute("value", slot.bgColor().toString().c_str());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("bgcolor");
elem->SetAttribute("value", slot.bgColor().toString().c_str());
}
// Ink
if (flags & int(BrushSlot::Flags::InkType)) {
TiXmlElement elem("inktype");
elem.SetAttribute(
XMLElement* elem = brushElem->InsertNewChildElement("inktype");
elem->SetAttribute(
"value", app::tools::ink_type_to_string_id(slot.inkType()).c_str());
brushElem.InsertEndChild(elem);
}
if (flags & int(BrushSlot::Flags::InkOpacity)) {
TiXmlElement elem("inkopacity");
elem.SetAttribute("value", slot.inkOpacity());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("inkopacity");
elem->SetAttribute("value", slot.inkOpacity());
}
// Shade
if (flags & int(BrushSlot::Flags::Shade)) {
TiXmlElement elem("shade");
elem.SetAttribute("value", shade_to_string(slot.shade()).c_str());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("shade");
elem->SetAttribute("value", shade_to_string(slot.shade()).c_str());
}
// Pixel-perfect
if (flags & int(BrushSlot::Flags::PixelPerfect)) {
TiXmlElement elem("pixelperfect");
elem.SetAttribute("value", slot.pixelPerfect() ? "true": "false");
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("pixelperfect");
elem->SetAttribute("value", slot.pixelPerfect() ? "true": "false");
}
}
brushesElem.InsertEndChild(brushElem);
}
TiXmlDeclaration declaration("1.0", "utf-8", "");
doc->InsertEndChild(declaration);
doc->InsertEndChild(brushesElem);
save_xml(doc, filename);
save_xml(doc.get(), filename);
}
// static

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -35,7 +35,7 @@
#include "ui/ui.h"
#include "ver/info.h"
#include "tinyxml.h"
#include "tinyxml2.h"
#include <cctype>
#include <cstring>
@ -47,6 +47,7 @@
namespace app {
using namespace tinyxml2;
using namespace ui;
namespace {
@ -343,8 +344,8 @@ void AppMenus::reload()
{
MENUS_TRACE("MENUS: AppMenus::reload()");
XmlDocumentRef doc(GuiXml::instance()->doc());
TiXmlHandle handle(doc.get());
XMLDocument* doc = GuiXml::instance()->doc();
XMLHandle handle(doc);
const char* path = GuiXml::instance()->filename();
////////////////////////////////////////
@ -454,9 +455,9 @@ void AppMenus::reload()
LOG("MENU: Loading commands keyboard shortcuts from %s\n", path);
TiXmlElement* xmlKey = handle
.FirstChild("gui")
.FirstChild("keyboard").ToElement();
XMLElement* xmlKey = handle
.FirstChildElement("gui")
.FirstChildElement("keyboard").ToElement();
// From a fresh start, load the default keys
KeyboardShortcuts::instance()->clear();
@ -716,15 +717,15 @@ void AppMenus::removeMenuItemFromGroup(Widget* menuItem)
});
}
Menu* AppMenus::loadMenuById(TiXmlHandle& handle, const char* id)
Menu* AppMenus::loadMenuById(XMLHandle& handle, const char* id)
{
ASSERT(id != NULL);
// <gui><menus><menu>
TiXmlElement* xmlMenu = handle
.FirstChild("gui")
.FirstChild("menus")
.FirstChild("menu").ToElement();
XMLElement* xmlMenu = handle
.FirstChildElement("gui")
.FirstChildElement("menus")
.FirstChildElement("menu").ToElement();
while (xmlMenu) {
const char* menuId = xmlMenu->Attribute("id");
@ -739,12 +740,12 @@ Menu* AppMenus::loadMenuById(TiXmlHandle& handle, const char* id)
throw base::Exception("Error loading menu '%s'\nReinstall the application.", id);
}
Menu* AppMenus::convertXmlelemToMenu(TiXmlElement* elem)
Menu* AppMenus::convertXmlelemToMenu(XMLElement* elem)
{
Menu* menu = new Menu();
menu->setText(m_xmlTranslator(elem, "text"));
TiXmlElement* child = elem->FirstChildElement();
XMLElement* child = elem->FirstChildElement();
while (child) {
Widget* menuitem = convertXmlelemToMenuitem(child, menu);
if (menuitem)
@ -759,7 +760,7 @@ Menu* AppMenus::convertXmlelemToMenu(TiXmlElement* elem)
return menu;
}
Widget* AppMenus::convertXmlelemToMenuitem(TiXmlElement* elem, Menu* menu)
Widget* AppMenus::convertXmlelemToMenuitem(XMLElement* elem, Menu* menu)
{
const char* id = elem->Attribute("id");
const char* group = elem->Attribute("group");
@ -791,7 +792,7 @@ Widget* AppMenus::convertXmlelemToMenuitem(TiXmlElement* elem, Menu* menu)
// load params
Params params;
if (command) {
TiXmlElement* xmlParam = elem->FirstChildElement("param");
XMLElement* xmlParam = elem->FirstChildElement("param");
while (xmlParam) {
const char* param_name = xmlParam->Attribute("name");
const char* param_value = xmlParam->Attribute("value");

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -20,8 +20,10 @@
#include <memory>
class TiXmlElement;
class TiXmlHandle;
namespace tinyxml2 {
class XMLElement;
class XMLHandle;
}
namespace app {
class Command;
@ -73,9 +75,9 @@ namespace app {
template<typename Pred>
void removeMenuItemFromGroup(Pred pred);
Menu* loadMenuById(TiXmlHandle& handle, const char *id);
Menu* convertXmlelemToMenu(TiXmlElement* elem);
Widget* convertXmlelemToMenuitem(TiXmlElement* elem, Menu* menu);
Menu* loadMenuById(tinyxml2::XMLHandle& handle, const char *id);
Menu* convertXmlelemToMenu(tinyxml2::XMLElement* elem);
Widget* convertXmlelemToMenuitem(tinyxml2::XMLElement* elem, Menu* menu);
void applyShortcutToMenuitemsWithCommand(Menu* menu, Command* command, const Params& params,
const KeyPtr& key);
void syncNativeMenuItemKeyShortcuts(Menu* menu);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -21,6 +21,8 @@
#include "fmt/format.h"
#include "gfx/color.h"
#include "tinyxml2.h"
#include <cstdlib>
#include <cstring>
#include <set>
@ -29,6 +31,7 @@ namespace app {
using namespace base;
using namespace doc;
using namespace tinyxml2;
namespace {
@ -89,7 +92,7 @@ template<typename Container,
typename ChildNameGetterFunc,
typename UpdateXmlChildFunc>
void update_xml_collection(const Container& container,
TiXmlElement* xmlParent,
XMLElement* xmlParent,
const char* childElemName,
const char* idAttrName,
ChildNameGetterFunc childNameGetter,
@ -98,12 +101,12 @@ void update_xml_collection(const Container& container,
if (!xmlParent)
return;
TiXmlElement* xmlNext = nullptr;
XMLElement* xmlNext = nullptr;
std::set<std::string> existent;
// Update existent children
for (TiXmlElement* xmlChild=(xmlParent->FirstChild(childElemName) ?
xmlParent->FirstChild(childElemName)->ToElement(): nullptr);
for (XMLElement* xmlChild=(xmlParent->FirstChildElement(childElemName) ?
xmlParent->FirstChildElement(childElemName): nullptr);
xmlChild;
xmlChild=xmlNext) {
xmlNext = xmlChild->NextSiblingElement();
@ -126,35 +129,33 @@ void update_xml_collection(const Container& container,
// Delete this <child> element (as the child was removed from the
// original container)
if (!found)
xmlParent->RemoveChild(xmlChild);
xmlParent->DeleteChild(xmlChild);
}
// Add new children
for (const auto& child : container) {
std::string thisChildName = childNameGetter(child);
if (existent.find(thisChildName) == existent.end()) {
TiXmlElement xmlChild(childElemName);
xmlChild.SetAttribute(idAttrName, thisChildName.c_str());
updateXmlChild(child, &xmlChild);
xmlParent->InsertEndChild(xmlChild);
XMLElement* xmlChild = xmlParent->InsertNewChildElement(childElemName);
xmlChild->SetAttribute(idAttrName, thisChildName.c_str());
updateXmlChild(child, xmlChild);
}
}
}
void update_xml_part_from_slice_key(const doc::SliceKey* key, TiXmlElement* xmlPart)
void update_xml_part_from_slice_key(const doc::SliceKey* key, XMLElement* xmlPart)
{
xmlPart->SetAttribute("x", key->bounds().x);
xmlPart->SetAttribute("y", key->bounds().y);
if (!key->hasCenter()) {
xmlPart->SetAttribute("w", key->bounds().w);
xmlPart->SetAttribute("h", key->bounds().h);
if (xmlPart->Attribute("w1")) xmlPart->RemoveAttribute("w1");
if (xmlPart->Attribute("w2")) xmlPart->RemoveAttribute("w2");
if (xmlPart->Attribute("w3")) xmlPart->RemoveAttribute("w3");
if (xmlPart->Attribute("h1")) xmlPart->RemoveAttribute("h1");
if (xmlPart->Attribute("h2")) xmlPart->RemoveAttribute("h2");
if (xmlPart->Attribute("h3")) xmlPart->RemoveAttribute("h3");
if (xmlPart->Attribute("w1")) xmlPart->DeleteAttribute("w1");
if (xmlPart->Attribute("w2")) xmlPart->DeleteAttribute("w2");
if (xmlPart->Attribute("w3")) xmlPart->DeleteAttribute("w3");
if (xmlPart->Attribute("h1")) xmlPart->DeleteAttribute("h1");
if (xmlPart->Attribute("h2")) xmlPart->DeleteAttribute("h2");
if (xmlPart->Attribute("h3")) xmlPart->DeleteAttribute("h3");
}
else {
xmlPart->SetAttribute("w1", key->center().x);
@ -163,8 +164,8 @@ void update_xml_part_from_slice_key(const doc::SliceKey* key, TiXmlElement* xmlP
xmlPart->SetAttribute("h1", key->center().y);
xmlPart->SetAttribute("h2", key->center().h);
xmlPart->SetAttribute("h3", key->bounds().h - key->center().y2());
if (xmlPart->Attribute("w")) xmlPart->RemoveAttribute("w");
if (xmlPart->Attribute("h")) xmlPart->RemoveAttribute("h");
if (xmlPart->Attribute("w")) xmlPart->DeleteAttribute("w");
if (xmlPart->Attribute("h")) xmlPart->DeleteAttribute("h");
}
if (key->hasPivot()) {
@ -172,17 +173,17 @@ void update_xml_part_from_slice_key(const doc::SliceKey* key, TiXmlElement* xmlP
xmlPart->SetAttribute("focusy", key->pivot().y);
}
else {
if (xmlPart->Attribute("focusx")) xmlPart->RemoveAttribute("focusx");
if (xmlPart->Attribute("focusy")) xmlPart->RemoveAttribute("focusy");
if (xmlPart->Attribute("focusx")) xmlPart->DeleteAttribute("focusx");
if (xmlPart->Attribute("focusy")) xmlPart->DeleteAttribute("focusy");
}
}
void update_xml_slice(const doc::Slice* slice, TiXmlElement* xmlSlice)
void update_xml_slice(const doc::Slice* slice, XMLElement* xmlSlice)
{
if (!slice->userData().text().empty())
xmlSlice->SetAttribute("text", slice->userData().text().c_str());
else if (xmlSlice->Attribute("text"))
xmlSlice->RemoveAttribute("text");
xmlSlice->DeleteAttribute("text");
xmlSlice->SetAttribute("color", color_to_hex(slice->userData().color()).c_str());
// Update <key> elements
@ -192,7 +193,7 @@ void update_xml_slice(const doc::Slice* slice, TiXmlElement* xmlSlice)
[](const Keyframes<SliceKey>::Key& key) -> std::string {
return base::convert_to<std::string>(key.frame());
},
[](const Keyframes<SliceKey>::Key& key, TiXmlElement* xmlKey) {
[](const Keyframes<SliceKey>::Key& key, XMLElement* xmlKey) {
SliceKey* sliceKey = key.value();
xmlKey->SetAttribute("x", sliceKey->bounds().x);
@ -207,10 +208,10 @@ void update_xml_slice(const doc::Slice* slice, TiXmlElement* xmlSlice)
xmlKey->SetAttribute("ch", sliceKey->center().h);
}
else {
if (xmlKey->Attribute("cx")) xmlKey->RemoveAttribute("cx");
if (xmlKey->Attribute("cy")) xmlKey->RemoveAttribute("cy");
if (xmlKey->Attribute("cw")) xmlKey->RemoveAttribute("cw");
if (xmlKey->Attribute("ch")) xmlKey->RemoveAttribute("ch");
if (xmlKey->Attribute("cx")) xmlKey->DeleteAttribute("cx");
if (xmlKey->Attribute("cy")) xmlKey->DeleteAttribute("cy");
if (xmlKey->Attribute("cw")) xmlKey->DeleteAttribute("cw");
if (xmlKey->Attribute("ch")) xmlKey->DeleteAttribute("ch");
}
if (sliceKey->hasPivot()) {
@ -218,8 +219,8 @@ void update_xml_slice(const doc::Slice* slice, TiXmlElement* xmlSlice)
xmlKey->SetAttribute("py", sliceKey->pivot().y);
}
else {
if (xmlKey->Attribute("px")) xmlKey->RemoveAttribute("px");
if (xmlKey->Attribute("py")) xmlKey->RemoveAttribute("py");
if (xmlKey->Attribute("px")) xmlKey->DeleteAttribute("px");
if (xmlKey->Attribute("py")) xmlKey->DeleteAttribute("py");
}
});
}
@ -230,12 +231,12 @@ void load_aseprite_data_file(const std::string& dataFilename,
doc::Document* doc,
app::Color& defaultSliceColor)
{
XmlDocumentRef xmlDoc = open_xml(dataFilename);
TiXmlHandle handle(xmlDoc.get());
XMLDocumentRef xmlDoc = open_xml(dataFilename);
XMLHandle handle(xmlDoc.get());
TiXmlElement* xmlSlices = handle
.FirstChild("sprite")
.FirstChild("slices").ToElement();
XMLElement* xmlSlices = handle
.FirstChildElement("sprite")
.FirstChildElement("slices").ToElement();
// Load slices/parts from theme.xml file
if (xmlSlices &&
@ -243,13 +244,13 @@ void load_aseprite_data_file(const std::string& dataFilename,
std::string themeFileName = xmlSlices->Attribute("theme");
// Open theme XML file
XmlDocumentRef xmlThemeDoc = open_xml(
XMLDocumentRef xmlThemeDoc = open_xml(
base::join_path(base::get_file_path(dataFilename), themeFileName));
TiXmlHandle themeHandle(xmlThemeDoc.get());
for (TiXmlElement* xmlPart = themeHandle
.FirstChild("theme")
.FirstChild("parts")
.FirstChild("part").ToElement();
XMLHandle themeHandle(xmlThemeDoc.get());
for (XMLElement* xmlPart = themeHandle
.FirstChildElement("theme")
.FirstChildElement("parts")
.FirstChildElement("part").ToElement();
xmlPart;
xmlPart=xmlPart->NextSiblingElement()) {
const char* partId = xmlPart->Attribute("id");
@ -300,8 +301,8 @@ void load_aseprite_data_file(const std::string& dataFilename,
}
// Load slices from <slice> elements
else if (xmlSlices) {
for (TiXmlElement* xmlSlice=(xmlSlices->FirstChild("slice") ?
xmlSlices->FirstChild("slice")->ToElement(): nullptr);
for (XMLElement* xmlSlice=(xmlSlices->FirstChildElement("slice") ?
xmlSlices->FirstChildElement("slice")->ToElement(): nullptr);
xmlSlice;
xmlSlice=xmlSlice->NextSiblingElement()) {
const char* sliceId = xmlSlice->Attribute("id");
@ -332,8 +333,8 @@ void load_aseprite_data_file(const std::string& dataFilename,
}
slice->userData().setColor(color);
for (TiXmlElement* xmlKey=(xmlSlice->FirstChild("key") ?
xmlSlice->FirstChild("key")->ToElement(): nullptr);
for (XMLElement* xmlKey=(xmlSlice->FirstChildElement("key") ?
xmlSlice->FirstChildElement("key")->ToElement(): nullptr);
xmlKey;
xmlKey=xmlKey->NextSiblingElement()) {
if (!xmlKey->Attribute("frame"))
@ -373,12 +374,12 @@ void load_aseprite_data_file(const std::string& dataFilename,
#ifdef ENABLE_SAVE
void save_aseprite_data_file(const std::string& dataFilename, const doc::Document* doc)
{
XmlDocumentRef xmlDoc = open_xml(dataFilename);
TiXmlHandle handle(xmlDoc.get());
XMLDocumentRef xmlDoc = open_xml(dataFilename);
XMLHandle handle(xmlDoc.get());
TiXmlElement* xmlSlices = handle
.FirstChild("sprite")
.FirstChild("slices").ToElement();
XMLElement* xmlSlices = handle
.FirstChildElement("sprite")
.FirstChildElement("slices").ToElement();
// Update theme.xml file
if (xmlSlices &&
@ -386,13 +387,13 @@ void save_aseprite_data_file(const std::string& dataFilename, const doc::Documen
// Open theme XML file
std::string themeFileName = base::join_path(
base::get_file_path(dataFilename), xmlSlices->Attribute("theme"));
XmlDocumentRef xmlThemeDoc = open_xml(themeFileName);
XMLDocumentRef xmlThemeDoc = open_xml(themeFileName);
TiXmlHandle themeHandle(xmlThemeDoc.get());
TiXmlElement* xmlParts =
XMLHandle themeHandle(xmlThemeDoc.get());
XMLElement* xmlParts =
themeHandle
.FirstChild("theme")
.FirstChild("parts").ToElement();
.FirstChildElement("theme")
.FirstChildElement("parts").ToElement();
update_xml_collection(
doc->sprite()->slices(),
@ -403,13 +404,13 @@ void save_aseprite_data_file(const std::string& dataFilename, const doc::Documen
else
return std::string();
},
[](Slice* slice, TiXmlElement* xmlSlice) {
[](Slice* slice, XMLElement* xmlSlice) {
ASSERT(slice->getByFrame(0));
update_xml_part_from_slice_key(slice->getByFrame(0), xmlSlice);
});
// Save theme.xml file
save_xml(xmlThemeDoc, themeFileName);
save_xml(xmlThemeDoc.get(), themeFileName);
}
// <slices> without "theme" attribute
else if (xmlSlices) {
@ -422,7 +423,7 @@ void save_aseprite_data_file(const std::string& dataFilename, const doc::Documen
update_xml_slice);
// Save .aseprite-data file
save_xml(xmlDoc, dataFilename);
save_xml(xmlDoc.get(), dataFilename);
}
}
#endif

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
@ -28,8 +28,8 @@ namespace app {
GuiXml();
// Returns the tinyxml document instance.
XmlDocumentRef doc() {
return m_doc;
tinyxml2::XMLDocument* doc() {
return m_doc.get();
}
// Returns the name of the gui.xml file.
@ -38,7 +38,7 @@ namespace app {
}
private:
XmlDocumentRef m_doc;
XMLDocumentRef m_doc;
friend class std::unique_ptr<GuiXml>;
};

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2017 David Capello
//
// This program is distributed under the terms of
@ -11,11 +12,13 @@
#include "app/i18n/xml_translator.h"
#include "app/i18n/strings.h"
#include "tinyxml.h"
#include "tinyxml2.h"
namespace app {
std::string XmlTranslator::operator()(const TiXmlElement* elem,
using namespace tinyxml2;
std::string XmlTranslator::operator()(const XMLElement* elem,
const char* attrName)
{
const char* value = elem->Attribute(attrName);

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2017 David Capello
//
// This program is distributed under the terms of
@ -10,13 +11,15 @@
#include <string>
class TiXmlElement;
namespace tinyxml2 {
class XMLElement;
}
namespace app {
class XmlTranslator {
public:
std::string operator()(const TiXmlElement* elem,
std::string operator()(const tinyxml2::XMLElement* elem,
const char* attrName);
void clearStringIdPrefix();

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -29,6 +29,8 @@
#include "doc/image_impl.h"
#include "doc/mask.h"
#include "tinyxml2.h"
#include <algorithm>
#include <cstdlib>
@ -41,6 +43,7 @@ namespace app {
namespace tools {
using namespace gfx;
using namespace tinyxml2;
const char* WellKnownTools::RectangularMarquee = "rectangular_marquee";
const char* WellKnownTools::Lasso = "lasso";
@ -206,11 +209,14 @@ void ToolBox::loadTools()
{
LOG("TOOL: Loading tools...\n");
XmlDocumentRef doc(GuiXml::instance()->doc());
TiXmlHandle handle(doc.get());
XMLDocument* doc = GuiXml::instance()->doc();
XMLHandle handle(doc);
// For each group
TiXmlElement* xmlGroup = handle.FirstChild("gui").FirstChild("tools").FirstChild("group").ToElement();
XMLElement* xmlGroup = handle
.FirstChildElement("gui")
.FirstChildElement("tools")
.FirstChildElement("group").ToElement();
while (xmlGroup) {
const char* groupId = xmlGroup->Attribute("id");
if (!groupId)
@ -233,8 +239,8 @@ void ToolBox::loadTools()
}
// For each tool
TiXmlNode* xmlToolNode = xmlGroup->FirstChild("tool");
TiXmlElement* xmlTool = xmlToolNode ? xmlToolNode->ToElement(): NULL;
XMLNode* xmlToolNode = xmlGroup->FirstChildElement("tool");
XMLElement* xmlTool = (xmlToolNode ? xmlToolNode->ToElement(): nullptr);
while (xmlTool) {
const char* toolId = xmlTool->Attribute("id");
std::string toolText = m_xmlTranslator(xmlTool, "text");
@ -272,7 +278,7 @@ void ToolBox::loadTools()
LOG("TOOL: Done. %d tools, %d groups.\n", m_tools.size(), m_groups.size());
}
void ToolBox::loadToolProperties(TiXmlElement* xmlTool, Tool* tool, int button, const std::string& suffix)
void ToolBox::loadToolProperties(XMLElement* xmlTool, Tool* tool, int button, const std::string& suffix)
{
const char* tool_id = tool->getId().c_str();
const char* fill = xmlTool->Attribute(("fill_"+suffix).c_str());

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -16,7 +16,9 @@
#include "app/i18n/xml_translator.h"
#include "app/tools/tool.h"
class TiXmlElement;
namespace tinyxml2 {
class XMLElement;
}
namespace app {
namespace tools {
@ -113,7 +115,7 @@ namespace app {
private:
void loadTools();
void loadToolProperties(TiXmlElement* xmlTool, Tool* tool, int button, const std::string& suffix);
void loadToolProperties(tinyxml2::XMLElement* xmlTool, Tool* tool, int button, const std::string& suffix);
std::map<std::string, Ink*> m_inks;
std::map<std::string, Controller*> m_controllers;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -31,6 +31,8 @@
#include "ui/accelerator.h"
#include "ui/message.h"
#include "tinyxml2.h"
#include <algorithm>
#include <set>
#include <vector>
@ -39,6 +41,8 @@
#define I18N_KEY(a) app::Strings::keyboard_shortcuts_##a()
using namespace tinyxml2;
namespace {
struct KeyShortcutAction {
@ -138,7 +142,7 @@ namespace {
return g_wheel_actions;
}
const char* get_shortcut(TiXmlElement* elem) {
const char* get_shortcut(XMLElement* elem) {
const char* shortcut = NULL;
#ifdef _WIN32
@ -613,13 +617,13 @@ void KeyboardShortcuts::clear()
m_keys.clear();
}
void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
void KeyboardShortcuts::importFile(XMLElement* rootElement, KeySource source)
{
// <keyboard><commands><key>
TiXmlHandle handle(rootElement);
TiXmlElement* xmlKey = handle
.FirstChild("commands")
.FirstChild("key").ToElement();
XMLHandle handle(rootElement);
XMLElement* xmlKey = handle
.FirstChildElement("commands")
.FirstChildElement("key").ToElement();
while (xmlKey) {
const char* command_name = xmlKey->Attribute("command");
const char* command_key = get_shortcut(xmlKey);
@ -637,7 +641,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
// Read params
Params params;
TiXmlElement* xmlParam = xmlKey->FirstChildElement("param");
XMLElement* xmlParam = xmlKey->FirstChildElement("param");
while (xmlParam) {
const char* param_name = xmlParam->Attribute("name");
const char* param_value = xmlParam->Attribute("value");
@ -677,8 +681,8 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
// Load keyboard shortcuts for tools
// <keyboard><tools><key>
xmlKey = handle
.FirstChild("tools")
.FirstChild("key").ToElement();
.FirstChildElement("tools")
.FirstChildElement("key").ToElement();
while (xmlKey) {
const char* tool_id = xmlKey->Attribute("tool");
const char* tool_key = get_shortcut(xmlKey);
@ -705,8 +709,8 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
// Load keyboard shortcuts for quicktools
// <keyboard><quicktools><key>
xmlKey = handle
.FirstChild("quicktools")
.FirstChild("key").ToElement();
.FirstChildElement("quicktools")
.FirstChildElement("key").ToElement();
while (xmlKey) {
const char* tool_id = xmlKey->Attribute("tool");
const char* tool_key = get_shortcut(xmlKey);
@ -733,8 +737,8 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
// Load special keyboard shortcuts for sprite editor customization
// <keyboard><actions><key>
xmlKey = handle
.FirstChild("actions")
.FirstChild("key").ToElement();
.FirstChildElement("actions")
.FirstChildElement("key").ToElement();
while (xmlKey) {
const char* action_id = xmlKey->Attribute("action");
const char* action_key = get_shortcut(xmlKey);
@ -768,8 +772,8 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
// Load special keyboard shortcuts for mouse wheel customization
// <keyboard><wheel><key>
xmlKey = handle
.FirstChild("wheel")
.FirstChild("key").ToElement();
.FirstChildElement("wheel")
.FirstChildElement("key").ToElement();
while (xmlKey) {
const char* action_id = xmlKey->Attribute("action");
const char* action_key = get_shortcut(xmlKey);
@ -796,8 +800,8 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
// Load special keyboard shortcuts to simulate mouse wheel actions
// <keyboard><drag><key>
xmlKey = handle
.FirstChild("drag")
.FirstChild("key").ToElement();
.FirstChildElement("drag")
.FirstChildElement("key").ToElement();
while (xmlKey) {
const char* action_id = xmlKey->Attribute("action");
const char* action_key = get_shortcut(xmlKey);
@ -835,26 +839,25 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
void KeyboardShortcuts::importFile(const std::string& filename, KeySource source)
{
XmlDocumentRef doc = app::open_xml(filename);
TiXmlHandle handle(doc.get());
TiXmlElement* xmlKey = handle.FirstChild("keyboard").ToElement();
XMLDocumentRef doc = app::open_xml(filename);
XMLHandle handle(doc.get());
XMLElement* xmlKey = handle.FirstChildElement("keyboard").ToElement();
importFile(xmlKey, source);
}
void KeyboardShortcuts::exportFile(const std::string& filename)
{
XmlDocumentRef doc(new TiXmlDocument());
auto doc = std::make_unique<XMLDocument>();
XMLElement* keyboard = doc->NewElement("keyboard");
XMLElement* commands = keyboard->InsertNewChildElement("commands");
XMLElement* tools = keyboard->InsertNewChildElement("tools");
XMLElement* quicktools = keyboard->InsertNewChildElement("quicktools");
XMLElement* actions = keyboard->InsertNewChildElement("actions");
XMLElement* wheel = keyboard->InsertNewChildElement("wheel");
XMLElement* drag = keyboard->InsertNewChildElement("drag");
TiXmlElement keyboard("keyboard");
TiXmlElement commands("commands");
TiXmlElement tools("tools");
TiXmlElement quicktools("quicktools");
TiXmlElement actions("actions");
TiXmlElement wheel("wheel");
TiXmlElement drag("drag");
keyboard.SetAttribute("version", XML_KEYBOARD_FILE_VERSION);
keyboard->SetAttribute("version", XML_KEYBOARD_FILE_VERSION);
exportKeys(commands, KeyType::Command);
exportKeys(tools, KeyType::Tool);
@ -863,20 +866,12 @@ void KeyboardShortcuts::exportFile(const std::string& filename)
exportKeys(wheel, KeyType::WheelAction);
exportKeys(drag, KeyType::DragAction);
keyboard.InsertEndChild(commands);
keyboard.InsertEndChild(tools);
keyboard.InsertEndChild(quicktools);
keyboard.InsertEndChild(actions);
keyboard.InsertEndChild(wheel);
keyboard.InsertEndChild(drag);
TiXmlDeclaration declaration("1.0", "utf-8", "");
doc->InsertEndChild(declaration);
doc->InsertEndChild(doc->NewDeclaration("xml version=\"1.0\" encoding=\"utf-8\""));
doc->InsertEndChild(keyboard);
save_xml(doc, filename);
save_xml(doc.get(), filename);
}
void KeyboardShortcuts::exportKeys(TiXmlElement& parent, KeyType type)
void KeyboardShortcuts::exportKeys(XMLElement* parent, KeyType type)
{
for (KeyPtr& key : m_keys) {
// Save only user defined accelerators.
@ -893,17 +888,17 @@ void KeyboardShortcuts::exportKeys(TiXmlElement& parent, KeyType type)
}
}
void KeyboardShortcuts::exportAccel(TiXmlElement& parent, const Key* key, const ui::Accelerator& accel, bool removed)
void KeyboardShortcuts::exportAccel(XMLElement* parent, const Key* key, const ui::Accelerator& accel, bool removed)
{
TiXmlElement elem("key");
XMLElement* elem = parent->InsertNewChildElement("key");
switch (key->type()) {
case KeyType::Command: {
elem.SetAttribute("command", key->command()->id().c_str());
elem->SetAttribute("command", key->command()->id().c_str());
if (key->keycontext() != KeyContext::Any) {
elem.SetAttribute("context",
elem->SetAttribute("context",
base::convert_to<std::string>(key->keycontext()).c_str());
}
@ -911,48 +906,45 @@ void KeyboardShortcuts::exportAccel(TiXmlElement& parent, const Key* key, const
if (param.second.empty())
continue;
TiXmlElement paramElem("param");
paramElem.SetAttribute("name", param.first.c_str());
paramElem.SetAttribute("value", param.second.c_str());
elem.InsertEndChild(paramElem);
XMLElement* paramElem = elem->InsertNewChildElement("param");
paramElem->SetAttribute("name", param.first.c_str());
paramElem->SetAttribute("value", param.second.c_str());
}
break;
}
case KeyType::Tool:
case KeyType::Quicktool:
elem.SetAttribute("tool", key->tool()->getId().c_str());
elem->SetAttribute("tool", key->tool()->getId().c_str());
break;
case KeyType::Action:
elem.SetAttribute("action",
elem->SetAttribute("action",
base::convert_to<std::string>(key->action()).c_str());
if (key->keycontext() != KeyContext::Any)
elem.SetAttribute("context",
elem->SetAttribute("context",
base::convert_to<std::string>(key->keycontext()).c_str());
break;
case KeyType::WheelAction:
elem.SetAttribute("action",
base::convert_to<std::string>(key->wheelAction()));
elem->SetAttribute("action",
base::convert_to<std::string>(key->wheelAction()).c_str());
break;
case KeyType::DragAction:
elem.SetAttribute("action",
base::convert_to<std::string>(key->wheelAction()));
elem.SetAttribute("vector",
fmt::format("{},{}",
key->dragVector().x,
key->dragVector().y));
elem->SetAttribute("action",
base::convert_to<std::string>(key->wheelAction()).c_str());
elem->SetAttribute("vector",
fmt::format("{},{}",
key->dragVector().x,
key->dragVector().y).c_str());
break;
}
elem.SetAttribute("shortcut", accel.toString().c_str());
elem->SetAttribute("shortcut", accel.toString().c_str());
if (removed)
elem.SetAttribute("removed", "true");
parent.InsertEndChild(elem);
elem->SetAttribute("removed", "true");
}
void KeyboardShortcuts::reset()

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -12,7 +12,9 @@
#include "app/ui/key.h"
#include "obs/signal.h"
class TiXmlElement;
namespace tinyxml2 {
class XMLElement;
}
namespace app {
@ -38,7 +40,7 @@ namespace app {
const bool cloneKeys);
void clear();
void importFile(TiXmlElement* rootElement, KeySource source);
void importFile(tinyxml2::XMLElement* rootElement, KeySource source);
void importFile(const std::string& filename, KeySource source);
void exportFile(const std::string& filename);
void reset();
@ -78,8 +80,8 @@ namespace app {
obs::signal<void()> UserChange;
private:
void exportKeys(TiXmlElement& parent, KeyType type);
void exportAccel(TiXmlElement& parent, const Key* key, const ui::Accelerator& accel, bool removed);
void exportKeys(tinyxml2::XMLElement* parent, KeyType type);
void exportAccel(tinyxml2::XMLElement* parent, const Key* key, const ui::Accelerator& accel, bool removed);
mutable Keys m_keys;
};

View File

@ -27,15 +27,16 @@
#include "ui/view.h"
#include "ver/info.h"
#include "tinyxml.h"
#include "tinyxml2.h"
#include <cctype>
#include <sstream>
namespace app {
using namespace ui;
using namespace app::skin;
using namespace tinyxml2;
using namespace ui;
namespace {
@ -267,7 +268,7 @@ void NewsListBox::parseFile(const std::string& filename)
{
View* view = View::getView(this);
XmlDocumentRef doc;
XMLDocumentRef doc;
try {
doc = open_xml(filename);
}
@ -278,18 +279,18 @@ void NewsListBox::parseFile(const std::string& filename)
return;
}
TiXmlHandle handle(doc.get());
TiXmlElement* itemXml = handle
.FirstChild("rss")
.FirstChild("channel")
.FirstChild("item").ToElement();
XMLHandle handle(doc.get());
XMLElement* itemXml = handle
.FirstChildElement("rss")
.FirstChildElement("channel")
.FirstChildElement("item").ToElement();
int count = 0;
while (itemXml) {
TiXmlElement* titleXml = itemXml->FirstChildElement("title");
TiXmlElement* descXml = itemXml->FirstChildElement("description");
TiXmlElement* linkXml = itemXml->FirstChildElement("link");
XMLElement* titleXml = itemXml->FirstChildElement("title");
XMLElement* descXml = itemXml->FirstChildElement("description");
XMLElement* linkXml = itemXml->FirstChildElement("link");
if (titleXml && titleXml->GetText() &&
descXml && descXml->GetText() &&
linkXml && linkXml->GetText()) {
@ -316,10 +317,10 @@ void NewsListBox::parseFile(const std::string& filename)
itemXml = itemXml->NextSiblingElement();
}
TiXmlElement* linkXml = handle
.FirstChild("rss")
.FirstChild("channel")
.FirstChild("link").ToElement();
XMLElement* linkXml = handle
.FirstChildElement("rss")
.FirstChildElement("channel")
.FirstChildElement("link").ToElement();
if (linkXml && linkXml->GetText())
addChild(
new NewsItem(linkXml->GetText(), Strings::news_listbox_more(), ""));

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -40,7 +40,7 @@
#include "ui/intern.h"
#include "ui/ui.h"
#include "tinyxml.h"
#include "tinyxml2.h"
#include <algorithm>
#include <cstring>
@ -52,6 +52,7 @@ namespace app {
namespace skin {
using namespace gfx;
using namespace tinyxml2;
using namespace ui;
// TODO For backward compatibility, in future versions we should remove this (extensions are preferred)
@ -77,7 +78,8 @@ class app::skin::SkinTheme::BackwardCompatibility {
// Loaded XML <style> element from the original theme (cloned
// elements). Must be in order to insert them in the same order in
// the selected theme.
std::vector<std::unique_ptr<TiXmlElement>> m_styles;
XMLDocumentRef m_stylesDoc;
std::vector<XMLElement*> m_styles;
public:
void copyingStyles() {
@ -85,13 +87,17 @@ public:
}
// Called for each <style> element found in theme.xml.
void onStyle(TiXmlElement* xmlStyle) {
void onStyle(XMLElement* xmlStyle) {
// Loading <style> from the default theme
if (m_state == State::LoadingStyles)
m_styles.emplace_back((TiXmlElement*)xmlStyle->Clone());
if (m_state == State::LoadingStyles) {
if (!m_stylesDoc)
m_stylesDoc = std::make_unique<XMLDocument>();
m_styles.emplace_back(
xmlStyle->DeepClone(m_stylesDoc.get())->ToElement());
}
}
void removeExistentStyles(TiXmlElement* xmlStyle) {
void removeExistentStyles(XMLElement* xmlStyle) {
if (m_state != State::CopyingStyles)
return;
@ -117,7 +123,7 @@ public:
// Copies all missing <style> elements to the new theme. xmlStyles
// is the <styles> element from the theme.xml of the selected theme
// (non the default one).
void copyMissingStyles(TiXmlNode* xmlStyles) {
void copyMissingStyles(XMLNode* xmlStyles) {
if (m_state != State::CopyingStyles)
return;
@ -125,8 +131,8 @@ public:
LOG(VERBOSE, "THEME: Copying <style id='%s'> from default theme\n",
style->Attribute("id"));
// InsertEndChild() clones the node
xmlStyles->InsertEndChild(*style.get());
xmlStyles->InsertEndChild(
style->DeepClone(xmlStyles->GetDocument()));
}
}
};
@ -153,7 +159,7 @@ static const char* g_cursor_names[kCursorTypes] = {
};
static FontData* load_font(std::map<std::string, FontData*>& fonts,
const TiXmlElement* xmlFont,
const XMLElement* xmlFont,
const std::string& xmlFilename)
{
const char* fontRef = xmlFont->Attribute("font");
@ -237,8 +243,8 @@ static FontData* load_font(std::map<std::string, FontData*>& fonts,
font.release();
// Fallback font
const TiXmlElement* xmlFallback =
(const TiXmlElement*)xmlFont->FirstChild("fallback");
const XMLElement* xmlFallback =
(const XMLElement*)xmlFont->FirstChildElement("fallback");
if (xmlFallback) {
FontData* fallback = load_font(fonts, xmlFallback, xmlFilename);
if (fallback) {
@ -345,12 +351,12 @@ void SkinTheme::loadFontData()
if (!rf.findFirst())
throw base::Exception("File %s not found", fontsFilename.c_str());
XmlDocumentRef doc = open_xml(rf.filename());
TiXmlHandle handle(doc.get());
XMLDocumentRef doc = open_xml(rf.filename());
XMLHandle handle(doc.get());
TiXmlElement* xmlFont = handle
.FirstChild("fonts")
.FirstChild("font").ToElement();
XMLElement* xmlFont = handle
.FirstChildElement("fonts")
.FirstChildElement("font").ToElement();
while (xmlFont) {
load_font(m_fonts, xmlFont, rf.filename());
xmlFont = xmlFont->NextSiblingElement();
@ -420,15 +426,15 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
// Load the skin XML
std::string xml_filename(base::join_path(m_path, "theme.xml"));
XmlDocumentRef doc = open_xml(xml_filename);
TiXmlHandle handle(doc.get());
XMLDocumentRef doc = open_xml(xml_filename);
XMLHandle handle(doc.get());
// Load Preferred scaling
m_preferredScreenScaling = -1;
m_preferredUIScaling = -1;
{
TiXmlElement* xmlTheme = handle
.FirstChild("theme").ToElement();
XMLElement* xmlTheme = handle
.FirstChildElement("theme").ToElement();
if (xmlTheme) {
const char* screenScaling = xmlTheme->Attribute("screenscaling");
const char* uiScaling = xmlTheme->Attribute("uiscaling");
@ -441,10 +447,10 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
// Load fonts
{
TiXmlElement* xmlFont = handle
.FirstChild("theme")
.FirstChild("fonts")
.FirstChild("font").ToElement();
XMLElement* xmlFont = handle
.FirstChildElement("theme")
.FirstChildElement("fonts")
.FirstChildElement("font").ToElement();
while (xmlFont) {
const char* idStr = xmlFont->Attribute("id");
FontData* fontData = load_font(m_fonts, xmlFont, xml_filename);
@ -485,10 +491,10 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
// Load dimension
{
TiXmlElement* xmlDim = handle
.FirstChild("theme")
.FirstChild("dimensions")
.FirstChild("dim").ToElement();
XMLElement* xmlDim = handle
.FirstChildElement("theme")
.FirstChildElement("dimensions")
.FirstChildElement("dim").ToElement();
while (xmlDim) {
std::string id = xmlDim->Attribute("id");
uint32_t value = strtol(xmlDim->Attribute("value"), NULL, 10);
@ -502,10 +508,10 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
// Load colors
{
TiXmlElement* xmlColor = handle
.FirstChild("theme")
.FirstChild("colors")
.FirstChild("color").ToElement();
XMLElement* xmlColor = handle
.FirstChildElement("theme")
.FirstChildElement("colors")
.FirstChildElement("color").ToElement();
while (xmlColor) {
std::string id = xmlColor->Attribute("id");
uint32_t value = strtol(xmlColor->Attribute("value")+1, NULL, 16);
@ -523,10 +529,10 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
// Load parts
{
TiXmlElement* xmlPart = handle
.FirstChild("theme")
.FirstChild("parts")
.FirstChild("part").ToElement();
XMLElement* xmlPart = handle
.FirstChildElement("theme")
.FirstChildElement("parts")
.FirstChildElement("part").ToElement();
while (xmlPart) {
// Get the tool-icon rectangle
const char* part_id = xmlPart->Attribute("id");
@ -616,10 +622,10 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
// Load styles
{
TiXmlElement* xmlStyle = handle
.FirstChild("theme")
.FirstChild("styles")
.FirstChild("style").ToElement();
XMLElement* xmlStyle = handle
.FirstChildElement("theme")
.FirstChildElement("styles")
.FirstChildElement("style").ToElement();
if (!xmlStyle) // Without styles?
throw base::Exception("There are no styles");
@ -752,7 +758,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
}
}
TiXmlElement* xmlLayer = xmlStyle->FirstChildElement();
XMLElement* xmlLayer = xmlStyle->FirstChildElement();
while (xmlLayer) {
const std::string layerName = xmlLayer->Value();

View File

@ -34,7 +34,7 @@
#include "os/system.h"
#include "ui/ui.h"
#include "tinyxml.h"
#include "tinyxml2.h"
#include <cstdio>
#include <cstdlib>
@ -44,11 +44,12 @@
namespace app {
using namespace ui;
using namespace app::skin;
using namespace tinyxml2;
using namespace ui;
static int convert_align_value_to_flags(const char *value);
static int int_attr(const TiXmlElement* elem, const char* attribute_name, int default_value);
static int int_attr(const XMLElement* elem, const char* attribute_name, int default_value);
WidgetLoader::WidgetLoader()
: m_tooltipManager(NULL)
@ -96,12 +97,12 @@ Widget* WidgetLoader::loadWidgetFromXmlFile(
m_tooltipManager = NULL;
m_xmlTranslator.setStringIdPrefix(widgetId.c_str());
XmlDocumentRef doc(open_xml(xmlFilename));
TiXmlHandle handle(doc.get());
XMLDocumentRef doc = open_xml(xmlFilename);
XMLHandle handle(doc.get());
// Search the requested widget.
TiXmlElement* xmlElement = handle
.FirstChild("gui")
XMLElement* xmlElement = handle
.FirstChildElement("gui")
.FirstChildElement().ToElement();
while (xmlElement) {
@ -118,7 +119,7 @@ Widget* WidgetLoader::loadWidgetFromXmlFile(
return widget;
}
Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget* root, Widget* parent, Widget* widget)
Widget* WidgetLoader::convertXmlElementToWidget(const XMLElement* elem, Widget* root, Widget* parent, Widget* widget)
{
const std::string elem_name = elem->Value();
@ -542,7 +543,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
return widget;
}
void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem, Widget* root, Widget* widget)
void WidgetLoader::fillWidgetWithXmlElementAttributes(const XMLElement* elem, Widget* root, Widget* widget)
{
const char* id = elem->Attribute("id");
const char* tooltip_dir = elem->Attribute("tooltip_dir");
@ -679,7 +680,7 @@ void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem,
widget->initTheme();
}
void WidgetLoader::fillWidgetWithXmlElementAttributesWithChildren(const TiXmlElement* elem, ui::Widget* root, ui::Widget* widget)
void WidgetLoader::fillWidgetWithXmlElementAttributesWithChildren(const XMLElement* elem, ui::Widget* root, ui::Widget* widget)
{
fillWidgetWithXmlElementAttributes(elem, root, widget);
@ -687,7 +688,7 @@ void WidgetLoader::fillWidgetWithXmlElementAttributesWithChildren(const TiXmlEle
root = widget;
// Children
const TiXmlElement* childElem = elem->FirstChildElement();
const XMLElement* childElem = elem->FirstChildElement();
while (childElem) {
Widget* child = convertXmlElementToWidget(childElem, root, widget, NULL);
if (child) {
@ -772,7 +773,7 @@ static int convert_align_value_to_flags(const char *value)
return flags;
}
static int int_attr(const TiXmlElement* elem, const char* attribute_name, int default_value)
static int int_attr(const XMLElement* elem, const char* attribute_name, int default_value)
{
const char* value = elem->Attribute(attribute_name);

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -14,7 +15,9 @@
#include <map>
#include <string>
class TiXmlElement;
namespace tinyxml2 {
class XMLElement;
}
namespace ui {
class Widget;
@ -30,7 +33,7 @@ namespace app {
public:
virtual ~IWidgetTypeCreator() { }
virtual void dispose() = 0;
virtual ui::Widget* createWidgetFromXml(const TiXmlElement* xmlElem) = 0;
virtual ui::Widget* createWidgetFromXml(const tinyxml2::XMLElement* xmlElem) = 0;
};
WidgetLoader();
@ -62,9 +65,9 @@ namespace app {
const std::string& widgetId,
ui::Widget* widget);
ui::Widget* convertXmlElementToWidget(const TiXmlElement* elem, ui::Widget* root, ui::Widget* parent, ui::Widget* widget);
void fillWidgetWithXmlElementAttributes(const TiXmlElement* elem, ui::Widget* root, ui::Widget* widget);
void fillWidgetWithXmlElementAttributesWithChildren(const TiXmlElement* elem, ui::Widget* root, ui::Widget* widget);
ui::Widget* convertXmlElementToWidget(const tinyxml2::XMLElement* elem, ui::Widget* root, ui::Widget* parent, ui::Widget* widget);
void fillWidgetWithXmlElementAttributes(const tinyxml2::XMLElement* elem, ui::Widget* root, ui::Widget* widget);
void fillWidgetWithXmlElementAttributesWithChildren(const tinyxml2::XMLElement* elem, ui::Widget* root, ui::Widget* widget);
typedef std::map<std::string, IWidgetTypeCreator*> TypeCreatorsMap;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
@ -14,28 +14,28 @@
#include "app/xml_exception.h"
#include "base/file_handle.h"
#include "tinyxml.h"
#include "tinyxml2.h"
namespace app {
using namespace base;
using namespace tinyxml2;
XmlDocumentRef open_xml(const std::string& filename)
XMLDocumentRef open_xml(const std::string& filename)
{
FileHandle file(open_file(filename, "rb"));
if (!file)
throw Exception("Error loading file: " + filename);
// Try to load the XML file
auto doc = std::make_shared<TiXmlDocument>();
doc->SetValue(filename.c_str());
if (!doc->LoadFile(file.get()))
throw XmlException(doc.get());
auto doc = std::make_unique<XMLDocument>();
if (doc->LoadFile(file.get()) != XML_SUCCESS)
throw XmlException(filename, doc.get());
return doc;
}
void save_xml(XmlDocumentRef doc, const std::string& filename)
void save_xml(XMLDocument* doc, const std::string& filename)
{
FileHandle file(open_file(filename, "wb"));
if (!file) {
@ -43,11 +43,11 @@ void save_xml(XmlDocumentRef doc, const std::string& filename)
throw Exception("Error loading file: " + filename);
}
if (!doc->SaveFile(file.get()))
throw XmlException(doc.get());
if (doc->SaveFile(file.get()) != XML_SUCCESS)
throw XmlException(filename, doc);
}
bool bool_attr(const TiXmlElement* elem, const char* attrName, bool defaultVal)
bool bool_attr(const XMLElement* elem, const char* attrName, bool defaultVal)
{
const char* value = elem->Attribute(attrName);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
@ -11,19 +11,21 @@
#include "base/exception.h"
#include "tinyxml.h"
#include "tinyxml2.h"
#include <memory>
#include <string>
namespace app {
typedef std::shared_ptr<TiXmlDocument> XmlDocumentRef;
using XMLDocumentRef = std::unique_ptr<tinyxml2::XMLDocument>;
XmlDocumentRef open_xml(const std::string& filename);
void save_xml(XmlDocumentRef doc, const std::string& filename);
XMLDocumentRef open_xml(const std::string& filename);
void save_xml(tinyxml2::XMLDocument* doc, const std::string& filename);
bool bool_attr(const TiXmlElement* elem, const char* attrName, bool defaultVal);
bool bool_attr(const tinyxml2::XMLElement* elem,
const char* attrName,
bool defaultVal);
} // namespace app

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2023 Igara Studio S.A.
// Copyright (C) 2023-2024 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
@ -12,17 +12,21 @@
#include "app/xml_exception.h"
#include "fmt/format.h"
#include "tinyxml.h"
#include "tinyxml2.h"
namespace app {
XmlException::XmlException(const TiXmlDocument* doc) throw()
using namespace tinyxml2;
XmlException::XmlException(const std::string& filename,
const XMLDocument* doc) noexcept
{
try {
setMessage(
fmt::format("Error in XML file '{}' (line {}, column {})\nError {}: {}",
doc->Value(), doc->ErrorRow(), doc->ErrorCol(),
doc->ErrorId(), doc->ErrorDesc()).c_str());
fmt::format("Error in XML file '{}' (line {})\nError {}: {}",
filename, doc->ErrorLineNum(),
int(doc->ErrorID()),
doc->ErrorStr()).c_str());
}
catch (...) {
// No throw

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
@ -10,13 +11,16 @@
#include "base/exception.h"
class TiXmlDocument;
namespace tinyxml2 {
class XMLDocument;
}
namespace app {
class XmlException : public base::Exception {
public:
XmlException(const TiXmlDocument* doc) throw();
XmlException(const std::string& filename,
const tinyxml2::XMLDocument* doc) noexcept;
};
} // namespace app

View File

@ -1,5 +1,5 @@
// Aseprite Code Generator
// Copyright (c) 2021-2023 Igara Studio S.A.
// Copyright (c) 2021-2024 Igara Studio S.A.
// Copyright (c) 2016-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -15,7 +15,7 @@
#include "cfg/cfg.h"
#include "gen/common.h"
#include "tinyxml.h"
#include "tinyxml2.h"
#include <cctype>
#include <iostream>
@ -27,11 +27,12 @@
// All other translations will be considered work-in-progress.
#define ENGLISH_ONLY 1
typedef std::vector<TiXmlElement*> XmlElements;
using namespace tinyxml2;
using XmlElements = std::vector<XMLElement*>;
static std::string find_first_id(TiXmlElement* elem)
static std::string find_first_id(XMLElement* elem)
{
TiXmlElement* child = elem->FirstChildElement();
XMLElement* child = elem->FirstChildElement();
while (child) {
const char* id = child->Attribute("id");
if (id)
@ -46,9 +47,9 @@ static std::string find_first_id(TiXmlElement* elem)
return "";
}
static void collect_elements_with_strings(TiXmlElement* elem, XmlElements& elems)
static void collect_elements_with_strings(XMLElement* elem, XmlElements& elems)
{
TiXmlElement* child = elem->FirstChildElement();
XMLElement* child = elem->FirstChildElement();
while (child) {
const char* text = child->Attribute("text");
const char* tooltip = child->Attribute("tooltip");
@ -111,19 +112,17 @@ public:
for (const auto& fn : base::list_files(dir)) {
std::string fullFn = base::join_path(dir, fn);
base::FileHandle inputFile(base::open_file(fullFn, "rb"));
std::unique_ptr<TiXmlDocument> doc(new TiXmlDocument());
doc->SetValue(fullFn.c_str());
if (!doc->LoadFile(inputFile.get())) {
std::cerr << doc->Value() << ":"
<< doc->ErrorRow() << ":"
<< doc->ErrorCol() << ": "
<< "error " << doc->ErrorId() << ": "
<< doc->ErrorDesc() << "\n";
auto doc = std::make_unique<XMLDocument>();
if (doc->LoadFile(inputFile.get()) != XML_SUCCESS) {
std::cerr << fullFn << ":"
<< doc->ErrorLineNum() << ": "
<< "error " << int(doc->ErrorID()) << ": "
<< doc->ErrorStr() << "\n";
throw std::runtime_error("invalid input file");
}
TiXmlHandle handle(doc.get());
XMLHandle handle(doc.get());
XmlElements widgets;
const char* warnings = doc->RootElement()->Attribute("i18nwarnings");
@ -133,64 +132,63 @@ public:
m_prefixId = find_first_id(doc->RootElement());
collect_elements_with_strings(doc->RootElement(), widgets);
for (TiXmlElement* elem : widgets) {
checkString(elem, elem->Attribute("text"));
checkString(elem, elem->Attribute("tooltip"));
for (XMLElement* elem : widgets) {
checkString(fullFn, elem, elem->Attribute("text"));
checkString(fullFn, elem, elem->Attribute("tooltip"));
}
}
}
void checkStringsOnGuiFile(const std::string& fullFn) {
base::FileHandle inputFile(base::open_file(fullFn, "rb"));
std::unique_ptr<TiXmlDocument> doc(new TiXmlDocument());
doc->SetValue(fullFn.c_str());
if (!doc->LoadFile(inputFile.get())) {
std::cerr << doc->Value() << ":"
<< doc->ErrorRow() << ":"
<< doc->ErrorCol() << ": "
<< "error " << doc->ErrorId() << ": "
<< doc->ErrorDesc() << "\n";
auto doc = std::make_unique<XMLDocument>();
if (doc->LoadFile(inputFile.get()) != XML_SUCCESS) {
std::cerr << fullFn << ":"
<< doc->ErrorLineNum() << ": "
<< "error " << int(doc->ErrorID()) << ": "
<< doc->ErrorStr() << "\n";
throw std::runtime_error("invalid input file");
}
TiXmlHandle handle(doc.get());
XMLHandle handle(doc.get());
// For each menu
TiXmlElement* xmlMenu = handle
.FirstChild("gui")
.FirstChild("menus")
.FirstChild("menu").ToElement();
XMLElement* xmlMenu = handle
.FirstChildElement("gui")
.FirstChildElement("menus")
.FirstChildElement("menu").ToElement();
while (xmlMenu) {
const char* menuId = xmlMenu->Attribute("id");
if (menuId) {
m_prefixId = menuId;
XmlElements menus;
collect_elements_with_strings(xmlMenu, menus);
for (TiXmlElement* elem : menus)
checkString(elem, elem->Attribute("text"));
for (XMLElement* elem : menus)
checkString(fullFn, elem, elem->Attribute("text"));
}
xmlMenu = xmlMenu->NextSiblingElement();
}
// For each tool
m_prefixId = "tools";
TiXmlElement* xmlGroup = handle
.FirstChild("gui")
.FirstChild("tools")
.FirstChild("group").ToElement();
XMLElement* xmlGroup = handle
.FirstChildElement("gui")
.FirstChildElement("tools")
.FirstChildElement("group").ToElement();
while (xmlGroup) {
XmlElements tools;
collect_elements_with_strings(xmlGroup, tools);
for (TiXmlElement* elem : tools) {
checkString(elem, elem->Attribute("text"));
checkString(elem, elem->Attribute("tooltip"));
for (XMLElement* elem : tools) {
checkString(fullFn, elem, elem->Attribute("text"));
checkString(fullFn, elem, elem->Attribute("tooltip"));
}
xmlGroup = xmlGroup->NextSiblingElement();
}
}
void checkString(TiXmlElement* elem, const char* text) {
void checkString(const std::string& filename,
XMLElement* elem, const char* text) {
if (!text)
return; // Do nothing
else if (text[0] == '@') {
@ -212,9 +210,8 @@ public:
const char* translated =
cfg->getValue(section.c_str(), var.c_str(), nullptr);
if (!translated || translated[0] == 0) {
std::cerr << elem->GetDocument()->Value() << ":"
<< elem->Row() << ":"
<< elem->Column() << ": "
std::cerr << filename << ":"
<< elem->GetLineNum() << ": "
<< "warning: <" << lang
<< "> translation for a string ID wasn't found '"
<< text << "' (" << section << "." << var << ")\n";
@ -224,9 +221,8 @@ public:
else if (text[0] != '!' &&
has_alpha_char(text) &&
!is_email(text)) {
std::cerr << elem->GetDocument()->Value() << ":"
<< elem->Row() << ":"
<< elem->Column() << ": "
std::cerr << filename << ":"
<< elem->GetLineNum() << ": "
<< "warning: raw string found '"
<< text << "'\n";
}

View File

@ -1,5 +1,5 @@
// Aseprite Code Generator
// Copyright (c) 2021 Igara Studio S.A.
// Copyright (c) 2021-2024 Igara Studio S.A.
// Copyright (c) 2014-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -15,12 +15,13 @@
#include "gen/strings_class.h"
#include "gen/theme_class.h"
#include "gen/ui_class.h"
#include "tinyxml.h"
#include "tinyxml2.h"
#include <iostream>
#include <memory>
typedef base::ProgramOptions PO;
using PO = base::ProgramOptions;
using namespace tinyxml2;
static void run(int argc, const char* argv[])
{
@ -38,21 +39,18 @@ static void run(int argc, const char* argv[])
po.parse(argc, argv);
// Try to load the XML file
std::unique_ptr<TiXmlDocument> doc;
std::unique_ptr<XMLDocument> doc;
std::string inputFilename = po.value_of(inputOpt);
if (!inputFilename.empty() &&
base::get_file_extension(inputFilename) == "xml") {
base::FileHandle inputFile(base::open_file(inputFilename, "rb"));
doc.reset(new TiXmlDocument);
doc->SetValue(inputFilename.c_str());
if (!doc->LoadFile(inputFile.get())) {
std::cerr << doc->Value() << ":"
<< doc->ErrorRow() << ":"
<< doc->ErrorCol() << ": "
<< "error " << doc->ErrorId() << ": "
<< doc->ErrorDesc() << "\n";
doc = std::make_unique<XMLDocument>();
if (doc->LoadFile(inputFile.get()) != XML_SUCCESS) {
std::cerr << inputFilename << ":"
<< doc->ErrorLineNum() << ": "
<< "error " << int(doc->ErrorID()) << ": "
<< doc->ErrorStr() << "\n";
throw std::runtime_error("invalid input file");
}
}

View File

@ -1,5 +1,5 @@
// Aseprite Code Generator
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2014-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -17,9 +17,11 @@
#include <stdexcept>
#include <vector>
typedef std::vector<TiXmlElement*> XmlElements;
using namespace tinyxml2;
static void print_pref_class_def(TiXmlElement* elem, const std::string& className, const char* section, int indentSpaces)
typedef std::vector<XMLElement*> XmlElements;
static void print_pref_class_def(XMLElement* elem, const std::string& className, const char* section, int indentSpaces)
{
std::string indent(indentSpaces, ' ');
std::cout
@ -39,7 +41,7 @@ static void print_pref_class_def(TiXmlElement* elem, const std::string& classNam
<< indent << " Section* section(const char* id) override;\n"
<< indent << " OptionBase* option(const char* id) override;\n";
TiXmlElement* child = (elem->FirstChild() ? elem->FirstChild()->ToElement(): NULL);
XMLElement* child = (elem->FirstChild() ? elem->FirstChild()->ToElement(): nullptr);
while (child) {
if (child->Value()) {
std::string name = child->Value();
@ -68,7 +70,7 @@ static void print_pref_class_def(TiXmlElement* elem, const std::string& classNam
<< indent << "};\n";
}
static void print_pref_class_impl(TiXmlElement* elem, const std::string& prefix, const std::string& className, const char* section)
static void print_pref_class_impl(XMLElement* elem, const std::string& prefix, const std::string& className, const char* section)
{
std::cout
<< "\n"
@ -79,7 +81,7 @@ static void print_pref_class_impl(TiXmlElement* elem, const std::string& prefix,
else
std::cout << " : Section(name)\n";
TiXmlElement* child = (elem->FirstChild() ? elem->FirstChild()->ToElement(): NULL);
XMLElement* child = (elem->FirstChild() ? elem->FirstChild()->ToElement(): nullptr);
while (child) {
if (child->Value()) {
std::string name = child->Value();
@ -284,7 +286,7 @@ static void print_pref_class_impl(TiXmlElement* elem, const std::string& prefix,
}
}
void gen_pref_header(TiXmlDocument* doc, const std::string& inputFn)
void gen_pref_header(XMLDocument* doc, const std::string& inputFn)
{
std::cout
<< "// Don't modify, generated file from " << inputFn << "\n"
@ -300,18 +302,18 @@ void gen_pref_header(TiXmlDocument* doc, const std::string& inputFn)
<< "namespace app {\n"
<< "namespace gen {\n";
TiXmlHandle handle(doc);
TiXmlElement* elem = handle
.FirstChild("preferences")
.FirstChild("types")
.FirstChild("enum").ToElement();
XMLHandle handle(doc);
XMLElement* elem = handle
.FirstChildElement("preferences")
.FirstChildElement("types")
.FirstChildElement("enum").ToElement();
while (elem) {
if (!elem->Attribute("id")) throw std::runtime_error("missing 'id' attr in <enum>");
std::cout
<< "\n"
<< " enum class " << elem->Attribute("id") << " {\n";
TiXmlElement* child = elem->FirstChildElement("value");
XMLElement* child = elem->FirstChildElement("value");
while (child) {
if (!child->Attribute("id")) throw std::runtime_error("missing 'id' attr in <value>");
if (!child->Attribute("value")) throw std::runtime_error("missing 'value' attr in <value>");
@ -328,20 +330,20 @@ void gen_pref_header(TiXmlDocument* doc, const std::string& inputFn)
}
elem = handle
.FirstChild("preferences")
.FirstChild("global").ToElement();
.FirstChildElement("preferences")
.FirstChildElement("global").ToElement();
if (elem)
print_pref_class_def(elem, "GlobalPref", NULL, 2);
elem = handle
.FirstChild("preferences")
.FirstChild("tool").ToElement();
.FirstChildElement("preferences")
.FirstChildElement("tool").ToElement();
if (elem)
print_pref_class_def(elem, "ToolPref", NULL, 2);
elem = handle
.FirstChild("preferences")
.FirstChild("document").ToElement();
.FirstChildElement("preferences")
.FirstChildElement("document").ToElement();
if (elem)
print_pref_class_def(elem, "DocPref", NULL, 2);
@ -353,7 +355,7 @@ void gen_pref_header(TiXmlDocument* doc, const std::string& inputFn)
<< "#endif\n";
}
void gen_pref_impl(TiXmlDocument* doc, const std::string& inputFn)
void gen_pref_impl(XMLDocument* doc, const std::string& inputFn)
{
std::cout
<< "// Don't modify, generated file from " << inputFn << "\n"
@ -370,22 +372,22 @@ void gen_pref_impl(TiXmlDocument* doc, const std::string& inputFn)
<< "namespace app {\n"
<< "namespace gen {\n";
TiXmlHandle handle(doc);
TiXmlElement* elem = handle
.FirstChild("preferences")
.FirstChild("global").ToElement();
XMLHandle handle(doc);
XMLElement* elem = handle
.FirstChildElement("preferences")
.FirstChildElement("global").ToElement();
if (elem)
print_pref_class_impl(elem, "", "GlobalPref", NULL);
elem = handle
.FirstChild("preferences")
.FirstChild("tool").ToElement();
.FirstChildElement("preferences")
.FirstChildElement("tool").ToElement();
if (elem)
print_pref_class_impl(elem, "", "ToolPref", NULL);
elem = handle
.FirstChild("preferences")
.FirstChild("document").ToElement();
.FirstChildElement("preferences")
.FirstChildElement("document").ToElement();
if (elem)
print_pref_class_impl(elem, "", "DocPref", NULL);

View File

@ -1,4 +1,5 @@
// Aseprite Code Generator
// Copyright (c) 2024 Igara Studio S.A.
// Copyright (c) 2014 David Capello
//
// This file is released under the terms of the MIT license.
@ -9,9 +10,9 @@
#pragma once
#include <string>
#include "tinyxml.h"
#include "tinyxml2.h"
void gen_pref_header(TiXmlDocument* doc, const std::string& inputFn);
void gen_pref_impl(TiXmlDocument* doc, const std::string& inputFn);
void gen_pref_header(tinyxml2::XMLDocument* doc, const std::string& inputFn);
void gen_pref_impl(tinyxml2::XMLDocument* doc, const std::string& inputFn);
#endif

View File

@ -1,4 +1,5 @@
// Aseprite Code Generator
// Copyright (c) 2024 Igara Studio S.A.
// Copyright (c) 2015-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -13,7 +14,9 @@
#include <iostream>
#include <vector>
void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
using namespace tinyxml2;
void gen_theme_class(XMLDocument* doc, const std::string& inputFn)
{
std::vector<std::string> dimensions;
std::vector<std::string> colors;
@ -21,11 +24,11 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
std::vector<std::string> cursors;
std::vector<std::string> styles;
TiXmlHandle handle(doc);
TiXmlElement* elem = handle
.FirstChild("theme")
.FirstChild("dimensions")
.FirstChild("dim").ToElement();
XMLHandle handle(doc);
XMLElement* elem = handle
.FirstChildElement("theme")
.FirstChildElement("dimensions")
.FirstChildElement("dim").ToElement();
while (elem) {
const char* id = elem->Attribute("id");
dimensions.push_back(id);
@ -33,9 +36,9 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
}
elem = handle
.FirstChild("theme")
.FirstChild("colors")
.FirstChild("color").ToElement();
.FirstChildElement("theme")
.FirstChildElement("colors")
.FirstChildElement("color").ToElement();
while (elem) {
const char* id = elem->Attribute("id");
colors.push_back(id);
@ -43,9 +46,9 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
}
elem = handle
.FirstChild("theme")
.FirstChild("parts")
.FirstChild("part").ToElement();
.FirstChildElement("theme")
.FirstChildElement("parts")
.FirstChildElement("part").ToElement();
while (elem) {
const char* id = elem->Attribute("id");
if (std::strncmp(id, "cursor_", 7) == 0) {
@ -57,9 +60,9 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
}
elem = handle
.FirstChild("theme")
.FirstChild("styles")
.FirstChild("style").ToElement();
.FirstChildElement("theme")
.FirstChildElement("styles")
.FirstChildElement("style").ToElement();
while (elem) {
const char* id = elem->Attribute("id");
styles.push_back(id);

View File

@ -1,4 +1,5 @@
// Aseprite Code Generator
// Copyright (c) 2024 Igara Studio S.A.
// Copyright (c) 2015-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -9,8 +10,8 @@
#pragma once
#include <string>
#include "tinyxml.h"
#include "tinyxml2.h"
void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn);
void gen_theme_class(tinyxml2::XMLDocument* doc, const std::string& inputFn);
#endif

View File

@ -17,7 +17,8 @@
#include <set>
#include <vector>
typedef std::vector<TiXmlElement*> XmlElements;
using namespace tinyxml2;
using XmlElements = std::vector<XMLElement*>;
namespace {
@ -36,15 +37,15 @@ struct Item {
}
static TiXmlElement* find_element_by_id(TiXmlElement* elem, const std::string& thisId)
static XMLElement* find_element_by_id(XMLElement* elem, const std::string& thisId)
{
const char* id = elem->Attribute("id");
if (id && id == thisId)
return elem;
TiXmlElement* child = elem->FirstChildElement();
XMLElement* child = elem->FirstChildElement();
while (child) {
TiXmlElement* match = find_element_by_id(child, thisId);
XMLElement* match = find_element_by_id(child, thisId);
if (match)
return match;
@ -54,9 +55,9 @@ static TiXmlElement* find_element_by_id(TiXmlElement* elem, const std::string& t
return NULL;
}
static void collect_widgets_with_ids(TiXmlElement* elem, XmlElements& widgets)
static void collect_widgets_with_ids(XMLElement* elem, XmlElements& widgets)
{
TiXmlElement* child = elem->FirstChildElement();
XMLElement* child = elem->FirstChildElement();
while (child) {
const char* id = child->Attribute("id");
if (id)
@ -66,7 +67,7 @@ static void collect_widgets_with_ids(TiXmlElement* elem, XmlElements& widgets)
}
}
static Item convert_to_item(TiXmlElement* elem)
static Item convert_to_item(XMLElement* elem)
{
static std::string parent;
const std::string name = elem->Value();
@ -182,7 +183,7 @@ static Item convert_to_item(TiXmlElement* elem)
throw base::Exception("Unknown widget name: " + name);
}
void gen_ui_class(TiXmlDocument* doc,
void gen_ui_class(XMLDocument* doc,
const std::string& inputFn,
const std::string& widgetId)
{
@ -190,8 +191,8 @@ void gen_ui_class(TiXmlDocument* doc,
<< "// Don't modify, generated file from " << inputFn << "\n"
<< "\n";
TiXmlHandle handle(doc);
TiXmlElement* elem = handle.FirstChild("gui").ToElement();
XMLHandle handle(doc);
XMLElement* elem = handle.FirstChildElement("gui").ToElement();
elem = find_element_by_id(elem, widgetId);
if (!elem) {
std::cout << "#error Widget not found: " << widgetId << "\n";
@ -202,7 +203,7 @@ void gen_ui_class(TiXmlDocument* doc,
{
XmlElements xmlWidgets;
collect_widgets_with_ids(elem, xmlWidgets);
for (TiXmlElement* elem : xmlWidgets) {
for (XMLElement* elem : xmlWidgets) {
const char* id = elem->Attribute("id");
if (!id)
continue;

View File

@ -1,4 +1,5 @@
// Aseprite Code Generator
// Copyright (c) 2024 Igara Studio S.A.
// Copyright (c) 2014-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -9,9 +10,9 @@
#pragma once
#include <string>
#include "tinyxml.h"
#include "tinyxml2.h"
void gen_ui_class(TiXmlDocument* doc,
void gen_ui_class(tinyxml2::XMLDocument* doc,
const std::string& inputFn,
const std::string& widgetId);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -16,7 +16,7 @@
#include "net/http_headers.h"
#include "net/http_request.h"
#include "net/http_response.h"
#include "tinyxml.h"
#include "tinyxml2.h"
#include "updater/user_agent.h"
#include "ver/info.h"
@ -26,6 +26,8 @@
namespace updater {
using namespace tinyxml2;
CheckUpdateResponse::CheckUpdateResponse()
: m_type(Unknown)
, m_waitDays(0.0)
@ -44,11 +46,11 @@ CheckUpdateResponse::CheckUpdateResponse(const std::string& responseBody)
: m_type(Unknown)
, m_waitDays(0.0)
{
TiXmlDocument doc;
XMLDocument doc;
doc.Parse(responseBody.c_str());
TiXmlHandle handle(&doc);
TiXmlElement* xmlUpdate = handle.FirstChild("update").ToElement();
XMLHandle handle(&doc);
XMLElement* xmlUpdate = handle.FirstChildElement("update").ToElement();
if (!xmlUpdate) {
// TODO show error?
return;

View File

@ -54,7 +54,7 @@ if(ENABLE_WEBP AND NOT LAF_BACKEND STREQUAL "skia")
endif()
if(NOT USE_SHARED_TINYXML)
add_subdirectory(tinyxml)
add_subdirectory(tinyxml2)
endif()
if(REQUIRE_CURL AND NOT USE_SHARED_CURL)

View File

@ -1,12 +0,0 @@
# ASEPRITE
# Copyright (C) 2020 Igara Studio S.A.
# Copyright (C) 2001-2013 David Capello
add_library(tinyxml
tinyxml.cpp
tinyxmlerror.cpp
tinyxmlparser.cpp)
# Use std::string instead of TiXmlString (we've found some threading
# issues related to TiXmlString::nullrep_)
target_compile_definitions(tinyxml PUBLIC TIXML_USE_STL)

View File

@ -1,298 +0,0 @@
Changes in version 1.0.1:
- Fixed comment tags which were outputing as '<?--' instead of
the correct '<!--'.
- Implemented the Next and Prev methods of the TiXmlAttribute class.
- Renamed 'LastAttribtute' to 'LastAttribute'
- Fixed bad pointer to 'isspace' that could occur while parsing text.
- Errors finding beginning and end of tags no longer throw it into an
infinite loop. (Hopefully.)
Changes in version 1.0.2
- Minor documentation fixes.
Changes in version 1.0.3
- After nodes are added to a document, they return a pointer
to the new node instead of a bool for success.
- Elements can be constructed with a value, which is the
element name. Every element must have a value or it will be
invalid, but the code changes to enforce this are not fully
in place.
Changes in version 1.1.0
- Added the TiXmlAttributeSet class to pull the attributes into
a seperate container.
- Moved the doubly liked list out of XmlBase. Now XmlBase only
requires the Print() function and defines some utility functions.
- Moved errors into a seperate file. (With the idea of internationalization
to the other latin-1 languages.)
- Added the "NodeType"
- Fixed white space parsing in text to conform with the standard.
Basically, all white space becomes just one space.
- Added the TiXmlDeclaration class to read xml declarations.
Changes in version 1.2.0
- Removed the factory. The factory was not really in the spirit
of small and simple, confused the code, and was of limited value.
- Added FirstChildElement and NextSiblingElement, because they
are such common functions.
- Re-wrote the example to test and demonstrate more functionality.
Changes in version 1.2.1
- Fixed a bug where comments couldn't be inside elements.
- Loading now clears out existing XML rather than appending.
- Added the "Clear" method on a node to delete all its children.
Changes in version 1.2.2
- Fixed TiXmlAttribute::Previous actually returning "next." Thanks
to Rickard Troedsson for the bug fix.
Changes in version 1.2.3
- Added the TIXML prefix to the error strings to resolve conflicts
with #defines in OS headers. Thanks to Steve Lhomme.
- Fixed a delete buf that should be a delete [] buf.
Thanks to Ephi Sinowitz.
Changes in version 1.2.4
- ReplaceChild() was almost guarenteed to fail. Should be fixed,
thanks to Joe Smith. Joe also pointed out that the Print() functions
should take stream references: I agree, and would like to overload
the Print() method to take either format, but I don't want to do
this in a dot release.
- Some compilers seem to need an extra <ctype.h> include. Thanks
to Steve Lhomme for that.
Changes in version 2.0.0 BETA
- Made the ToXXX() casts safe if 'this' is null.
When "LoadFile" is called with a filename, the value will correctly get set.
Thanks to Brian Yoder.
- Fixed bug where isalpha() and isalnum() would get called with a negative value for
high ascii numbers. Thanks to Alesky Aksenov.
- Fixed some errors codes that were not getting set.
- Made methods "const" that were not.
- Added a switch to enable or disable the ignoring of white space. ( TiXmlDocument::SetIgnoreWhiteSpace() )
- Greater standardization and code re-use in the parser.
- Added a stream out operator.
- Added a stream in operator.
- Entity support, of predefined entites. &#x entities are untouched by input or output.
- Improved text out formatting.
- Fixed ReplaceChild bug, thanks to Tao Chen.
Changes in version 2.0.1
- Fixed hanging on loading a 0 length file. Thanks to Jeff Scozzafava.
- Fixed crashing on InsertBeforeChild and InsertAfterChild. Also possibility of bad links being
created by same function. Thanks to Frank De prins.
- Added missing licence text. Thanks to Lars Willemsens.
- Added <ctype.h> include, at the suggestion of Steve Walters.
Changes in version 2.1.0
- Yves Berquin brings us the STL switch. The forum on SourceForge, and various emails to
me, have long debated all out STL vs. no STL at all. And now you can have it both ways.
TinyXml will compile either way.
Changes in version 2.1.1
- Compilation warnings.
Changes in version 2.1.2
- Uneeded code is not compiled in the STL case.
- Changed headers so that STL can be turned on or off in tinyxml.h
Changes in version 2.1.3
- Fixed non-const reference in API; now uses a pointer.
- Copy constructor of TiXmlString not checking for assignment to self.
- Nimrod Cohen found a truly evil bug in the STL implementation that occurs
when a string is converted to a c_str and then assigned to self. Search for
STL_STRING_BUG for a full description. I'm asserting this is a Microsoft STL
bug, since &string and string.c_str() should never be the same. Nevertheless,
the code works around it.
- Urivan Saaib pointed out a compiler conflict, where the C headers define
the isblank macro, which was wiping out the TiXmlString::isblank() method.
The method was unused and has been removed.
Changes in version 2.1.4
- Reworked the entity code. Entities were not correctly surving round trip input and output.
Will now automatically create entities for high ascii in output.
Changes in version 2.1.5
- Bug fix by kylotan : infinite loop on some input (tinyxmlparser.cpp rev 1.27)
- Contributed by Ivica Aracic (bytelord) : 1 new VC++ project to compile versions as static libraries (tinyxml_lib.dsp),
and an example usage in xmltest.dsp
(Patch request ID 678605)
- A suggestion by Ronald Fenner Jr (dormlock) to add #include <istream> and <ostream> for Apple's Project Builder
(Patch request ID 697642)
- A patch from ohommes that allows to parse correctly dots in element names and attribute names
(Patch request 602600 and kylotan 701728)
- A patch from hermitgeek ( James ) and wasteland for improper error reporting
- Reviewed by Lee, with the following changes:
- Got sick of fighting the STL/non-STL thing in the windows build. Broke
them out as seperate projects.
- I have too long not included the dsw. Added.
- TinyXmlText had a protected Print. Odd.
- Made LinkEndChild public, with docs and appropriate warnings.
- Updated the docs.
2.2.0
- Fixed an uninitialized pointer in the TiXmlAttributes
- Fixed STL compilation problem in MinGW (and gcc 3?) - thanks Brian Yoder for finding this one
- Fixed a syntax error in TiXmlDeclaration - thanks Brian Yoder
- Fletcher Dunn proposed and submitted new error handling that tracked the row and column. Lee
modified it to not have performance impact.
- General cleanup suggestions from Fletcher Dunn.
- In error handling, general errors will no longer clear the error state of specific ones.
- Fix error in documentation : comments starting with "<?--" instead of "<!--" (thanks ion_pulse)
- Added the TiXmlHandle. An easy, safe way to browse XML DOMs with less code.
- Added QueryAttribute calls which have better error messaging. (Proposed by Fletcher Dunn)
- Nodes and attributes can now print themselves to strings. (Yves suggestion)
- Fixed bug where entities with one character would confuse parser. (Thanks Roman)
2.2.1
- Additional testing (no more bugs found to be fixed in this release)
- Significant performance improvement to the cursor code.
2.3.0
- User Data are now defined in TiXmlBase instead of TiXmlNode
- Character Entities are now UCS-2
- Character Entities can be decimal or hexadecimal
- UTF-8 conversion.
- Fixed many, many bugs.
2.3.1
- Fixed bug in handling nulls embedded in the input.
- Make UTF-8 parser tolerant of bad text encoding.
- Added encoding detection.
- Many fixes and input from John-Philip Leonard Johansson (JP) and Ellers,
including UTF-8 feedback, bug reports, and patches. Thanks!
- Added version # constants - a suggestion from JP and Ellers.
- [ 979180 ] Missing ; in entity reference, fix from Rob Laveaux.
- Copy constructors and assignment have been a long time coming. Thanks to
Fokke and JP.
2.3.2
- Made the IsAlpha and IsAlphaNum much more tolerant of non-UTF-8 encodings. Thanks
Volker Boerchers for finding the issue.
- Ran the program though the magnificent Valgrind - http://valgrind.kde.org - to check
for memory errors. Fixed some minor issues.
2.3.3
- Fixed crash when test program was run from incorrect directory.
- Fixed bug 1070717 - empty document not returned correctly - thanks Katsuhisa Yuasa.
- Bug 1079301 resolved - deprecated stdlib calls. Thanks Adrian Boeing.
- Bug 1035218 fixed - documentation errors. Xunji Luo
- Other bug fixes have accumulated and been fixed on the way as well; my apologies to
authors not credited!
- Big fix / addition is to correctly return const values. TinyXml could basically
remove const in a method like this: TiXmlElement* Foo() const, where the returned element
was a pointer to internal data. That is now: const TiXmlElement* Foo() const and
TiXmlElement* Foo().
2.3.4
- Fixed additional const errors, thanks Kent Gibson.
- Correctly re-enable warnings after tinyxml header. Thanks Cory Nelson.
- Variety of type cleanup and warning fixes. Thanks Warren Stevens.
- Cleaned up unneeded constructor calls in TinyString - thanks to Geoff Carlton and
the discussion group on sourceforge.
2.4.0
- Improved string class, thanks Tyge Lovset (whose name gets mangled in English - sorry)
- Type cast compiler warning, thanks Rob van den Bogaard
- Added GetText() convenience function. Thanks Ilya Parniuk & Andrew Ellers for input.
- Many thanks to marlonism for finding an infinite loop in bad xml.
- A patch to cleanup warnings from Robert Gebis.
- Added ValueStr() to get the value of a node as a string.
- TiXmlText can now parse and output as CDATA
- Additional string improvement from James (z2895)
- Removed extraneous 'const', thanks David Aldrich
- First pass at switching to the "safe" stdlib functions. Many people have suggested and
pushed on this, but Warren Stevens put together the first proposal.
- TinyXml now will do EOL normalization before parsing, consistent with the W3C XML spec.
- Documents loaded with the UTF-8 BOM will now save with the UTF-8 BOM. Good suggestion
from 'instructor_'
- Ellers submitted his very popular tutorials, which have been added to the distribution.
2.4.1
- Fixed CDATA output formatting
- Fixed memory allocators in TinyString to work with overloaded new/delete
2.4.2
- solosnake pointed out that TIXML_LOG causes problems on an XBOX. The definition in the header
was superflous and was moved inside of DEBUG_PARSING
2.4.3
- Fixed a test bug that caused a crash in 'xmltest'. TinyXML was fine, but it isn't good
to ship with a broken test suite.
- Started converting some functions to not cast between std::string and const char*
quite as often.
- Added FILE* versions of the document loads - good suggestion from Wade Brainerd
- Empty documents might not always return the errors they should. [1398915] Thanks to igor v.
- Added some asserts for multiply adding a node, regardng bug [1391937] suggested by Paco Arjonilla.
2.4.4
- Bug find thanks to andre-gross found a memory leak that occured when a document failed to load.
- Bug find (and good analysis) by VirtualJim who found a case where attribute parsing
should be throwing an error and wasn't.
- Steve Hyatt suggested the QueryValueAttribute method, which is now implemented.
- DavidA identified a chunk of dead code.
- Andrew Baxter sent in some compiler warnings that were good clean up points.
2.5
- Added the Visit() API. Many thanks to both Andrew Ellerton and John-Philip for all their
work, code, suggestion, and just general pushing that it should be done.
- Removed existing streaming code and use TiXmlPrinter instead.
- [ tinyxml-Bugs-1527079 ] Compile error in tinystr.cpp fixed, thanks to Paul Suggs
- [ tinyxml-Bugs-1522890 ] SaveFile has no error checks fixed, thanks to Ivan Dobrokotov
- Ivan Dobrokotov also reported redundant memory allocation in the Attribute() method, which
upon investigation was a mess. The attribute should now be fixed for both const char* and
std::string, and the return types match the input parameters.
- Feature [ 1511105 ] Make TiXmlComment constructor accept a string / char*, implemented.
Thanks to Karl Itschen for the feedback.
- [ 1480108 ] Stream parsing fails when CDATA contains tags was found by Tobias Grimm, who also
submitted a test case and patch. A significant bug in CDATA streaming (operator>>) has now
been fixed.
2.5.2
- Lieven, and others, pointed out a missing const-cast that upset the Open Watcom compiler.
Should now be fixed.
- ErrorRow and ErrorCol should have been const, and weren't. Fixed thanks to Dmitry Polutov.
2.5.3
- zloe_zlo identified a missing string specialization for QueryValueAttribute() [ 1695429 ]. Worked
on this bug, but not sure how to fix it in a safe, cross-compiler way.
- increased warning level to 4 and turned on detect 64 bit portability issues for VC2005.
May address [ 1677737 ] VS2005: /Wp64 warnings
- grosheck identified several problems with the Document copy. Many thanks for [ 1660367 ]
- Nice catch, and suggested fix, be Gilad Novik on the Printer dropping entities.
"[ 1600650 ] Bug when printing xml text" is now fixed.
- A subtle fix from Nicos Gollan in the tinystring initializer:
[ 1581449 ] Fix initialiser of TiXmlString::nullrep_
- Great catch, although there isn't a submitter for the bug. [ 1475201 ] TinyXML parses entities in comments.
Comments should not, in fact, parse entities. Fixed the code path and added tests.
- We were not catching all the returns from ftell. Thanks to Bernard for catching that.
2.5.4
- A TiXMLDocument can't be a sub-node. Block this from happening in the 'replace'. Thanks Noam.
- [ 1714831 ] TiXmlBase::location is not copied by copy-ctors, fix reported and suggested by Nicola Civran.
- Fixed possible memory overrun in the comment reading code - thanks gcarlton77
2.5.5
- Alex van der Wal spotted incorrect types (lf) being used in print and scan. robertnestor pointed out some problems with the simple solution. Types updated.
- Johannes Hillert pointed out some bug typos.
- Christian Mueller identified inconsistent error handling with Attributes.
- olivier barthelemy also reported a problem with double truncation, also related to the %lf issue.
- zaelsius came up with a great (and simple) suggestion to fix QueryValueAttribute truncating strings.
- added some null pointer checks suggested by hansenk
- Sami Väisänen found a (rare) buffer overrun that could occur in parsing.
- vi tri filed a bug that led to a refactoring of the attribute setting mess (as well as adding a missing SetDoubleAttribute() )
- removed TIXML_ERROR_OUT_OF_MEMORY. TinyXML does not systematically address OOO, and the notion it does is misleading.
- vanneto, keithmarshall, others all reported the warning from IsWhiteSpace() usage. Cleaned this up - many thanks to everyone who reported this one.
- tibur found a bug in end tag parsing
2.6.2
- Switched over to VC 2010
- Fixed up all the build issues arising from that. (Lots of latent build problems.)
- Removed the old, now unmaintained and likely not working, build files.
- Fixed some static analysis issues reported by orbitcowboy from cppcheck.
- Bayard 95 sent in analysis from a different analyzer - fixes applied from that as well.
- Tim Kosse sent a patch fixing an infinite loop.
- Ma Anguo identified a doc issue.
- Eddie Cohen identified a missing qualifier resulting in a compilation error on some systems.
- Fixed a line ending bug. (What year is this? Can we all agree on a format for text files? Please? ...oh well.)

View File

@ -1,530 +0,0 @@
/** @mainpage
<h1> TinyXML </h1>
TinyXML is a simple, small, C++ XML parser that can be easily
integrated into other programs.
<h2> What it does. </h2>
In brief, TinyXML parses an XML document, and builds from that a
Document Object Model (DOM) that can be read, modified, and saved.
XML stands for "eXtensible Markup Language." It allows you to create
your own document markups. Where HTML does a very good job of marking
documents for browsers, XML allows you to define any kind of document
markup, for example a document that describes a "to do" list for an
organizer application. XML is a very structured and convenient format.
All those random file formats created to store application data can
all be replaced with XML. One parser for everything.
The best place for the complete, correct, and quite frankly hard to
read spec is at <a href="http://www.w3.org/TR/2004/REC-xml-20040204/">
http://www.w3.org/TR/2004/REC-xml-20040204/</a>. An intro to XML
(that I really like) can be found at
<a href="http://skew.org/xml/tutorial/">http://skew.org/xml/tutorial</a>.
There are different ways to access and interact with XML data.
TinyXML uses a Document Object Model (DOM), meaning the XML data is parsed
into a C++ objects that can be browsed and manipulated, and then
written to disk or another output stream. You can also construct an XML document
from scratch with C++ objects and write this to disk or another output
stream.
TinyXML is designed to be easy and fast to learn. It is two headers
and four cpp files. Simply add these to your project and off you go.
There is an example file - xmltest.cpp - to get you started.
TinyXML is released under the ZLib license,
so you can use it in open source or commercial code. The details
of the license are at the top of every source file.
TinyXML attempts to be a flexible parser, but with truly correct and
compliant XML output. TinyXML should compile on any reasonably C++
compliant system. It does not rely on exceptions or RTTI. It can be
compiled with or without STL support. TinyXML fully supports
the UTF-8 encoding, and the first 64k character entities.
<h2> What it doesn't do. </h2>
TinyXML doesn't parse or use DTDs (Document Type Definitions) or XSLs
(eXtensible Stylesheet Language.) There are other parsers out there
(check out www.sourceforge.org, search for XML) that are much more fully
featured. But they are also much bigger, take longer to set up in
your project, have a higher learning curve, and often have a more
restrictive license. If you are working with browsers or have more
complete XML needs, TinyXML is not the parser for you.
The following DTD syntax will not parse at this time in TinyXML:
@verbatim
<!DOCTYPE Archiv [
<!ELEMENT Comment (#PCDATA)>
]>
@endverbatim
because TinyXML sees this as a !DOCTYPE node with an illegally
embedded !ELEMENT node. This may be addressed in the future.
<h2> Tutorials. </h2>
For the impatient, here is a tutorial to get you going. A great way to get started,
but it is worth your time to read this (very short) manual completely.
- @subpage tutorial0
<h2> Code Status. </h2>
TinyXML is mature, tested code. It is very stable. If you find
bugs, please file a bug report on the sourceforge web site
(www.sourceforge.net/projects/tinyxml). We'll get them straightened
out as soon as possible.
There are some areas of improvement; please check sourceforge if you are
interested in working on TinyXML.
<h2> Related Projects </h2>
TinyXML projects you may find useful! (Descriptions provided by the projects.)
<ul>
<li> <b>TinyXPath</b> (http://tinyxpath.sourceforge.net). TinyXPath is a small footprint
XPath syntax decoder, written in C++.</li>
<li> <b>TinyXML++</b> (http://code.google.com/p/ticpp/). TinyXML++ is a completely new
interface to TinyXML that uses MANY of the C++ strengths. Templates,
exceptions, and much better error handling.</li>
</ul>
<h2> Features </h2>
<h3> Using STL </h3>
TinyXML can be compiled to use or not use STL. When using STL, TinyXML
uses the std::string class, and fully supports std::istream, std::ostream,
operator<<, and operator>>. Many API methods have both 'const char*' and
'const std::string&' forms.
When STL support is compiled out, no STL files are included whatsoever. All
the string classes are implemented by TinyXML itself. API methods
all use the 'const char*' form for input.
Use the compile time #define:
TIXML_USE_STL
to compile one version or the other. This can be passed by the compiler,
or set as the first line of "tinyxml.h".
Note: If compiling the test code in Linux, setting the environment
variable TINYXML_USE_STL=YES/NO will control STL compilation. In the
Windows project file, STL and non STL targets are provided. In your project,
It's probably easiest to add the line "#define TIXML_USE_STL" as the first
line of tinyxml.h.
<h3> UTF-8 </h3>
TinyXML supports UTF-8 allowing to manipulate XML files in any language. TinyXML
also supports "legacy mode" - the encoding used before UTF-8 support and
probably best described as "extended ascii".
Normally, TinyXML will try to detect the correct encoding and use it. However,
by setting the value of TIXML_DEFAULT_ENCODING in the header file, TinyXML
can be forced to always use one encoding.
TinyXML will assume Legacy Mode until one of the following occurs:
<ol>
<li> If the non-standard but common "UTF-8 lead bytes" (0xef 0xbb 0xbf)
begin the file or data stream, TinyXML will read it as UTF-8. </li>
<li> If the declaration tag is read, and it has an encoding="UTF-8", then
TinyXML will read it as UTF-8. </li>
<li> If the declaration tag is read, and it has no encoding specified, then TinyXML will
read it as UTF-8. </li>
<li> If the declaration tag is read, and it has an encoding="something else", then TinyXML
will read it as Legacy Mode. In legacy mode, TinyXML will work as it did before. It's
not clear what that mode does exactly, but old content should keep working.</li>
<li> Until one of the above criteria is met, TinyXML runs in Legacy Mode.</li>
</ol>
What happens if the encoding is incorrectly set or detected? TinyXML will try
to read and pass through text seen as improperly encoded. You may get some strange results or
mangled characters. You may want to force TinyXML to the correct mode.
You may force TinyXML to Legacy Mode by using LoadFile( TIXML_ENCODING_LEGACY ) or
LoadFile( filename, TIXML_ENCODING_LEGACY ). You may force it to use legacy mode all
the time by setting TIXML_DEFAULT_ENCODING = TIXML_ENCODING_LEGACY. Likewise, you may
force it to TIXML_ENCODING_UTF8 with the same technique.
For English users, using English XML, UTF-8 is the same as low-ASCII. You
don't need to be aware of UTF-8 or change your code in any way. You can think
of UTF-8 as a "superset" of ASCII.
UTF-8 is not a double byte format - but it is a standard encoding of Unicode!
TinyXML does not use or directly support wchar, TCHAR, or Microsoft's _UNICODE at this time.
It is common to see the term "Unicode" improperly refer to UTF-16, a wide byte encoding
of unicode. This is a source of confusion.
For "high-ascii" languages - everything not English, pretty much - TinyXML can
handle all languages, at the same time, as long as the XML is encoded
in UTF-8. That can be a little tricky, older programs and operating systems
tend to use the "default" or "traditional" code page. Many apps (and almost all
modern ones) can output UTF-8, but older or stubborn (or just broken) ones
still output text in the default code page.
For example, Japanese systems traditionally use SHIFT-JIS encoding.
Text encoded as SHIFT-JIS can not be read by TinyXML.
A good text editor can import SHIFT-JIS and then save as UTF-8.
The <a href="http://skew.org/xml/tutorial/">Skew.org link</a> does a great
job covering the encoding issue.
The test file "utf8test.xml" is an XML containing English, Spanish, Russian,
and Simplified Chinese. (Hopefully they are translated correctly). The file
"utf8test.gif" is a screen capture of the XML file, rendered in IE. Note that
if you don't have the correct fonts (Simplified Chinese or Russian) on your
system, you won't see output that matches the GIF file even if you can parse
it correctly. Also note that (at least on my Windows machine) console output
is in a Western code page, so that Print() or printf() cannot correctly display
the file. This is not a bug in TinyXML - just an OS issue. No data is lost or
destroyed by TinyXML. The console just doesn't render UTF-8.
<h3> Entities </h3>
TinyXML recognizes the pre-defined "character entities", meaning special
characters. Namely:
@verbatim
&amp; &
&lt; <
&gt; >
&quot; "
&apos; '
@endverbatim
These are recognized when the XML document is read, and translated to there
UTF-8 equivalents. For instance, text with the XML of:
@verbatim
Far &amp; Away
@endverbatim
will have the Value() of "Far & Away" when queried from the TiXmlText object,
and will be written back to the XML stream/file as an ampersand. Older versions
of TinyXML "preserved" character entities, but the newer versions will translate
them into characters.
Additionally, any character can be specified by its Unicode code point:
The syntax "&#xA0;" or "&#160;" are both to the non-breaking space characher.
<h3> Printing </h3>
TinyXML can print output in several different ways that all have strengths and limitations.
- Print( FILE* ). Output to a std-C stream, which includes all C files as well as stdout.
- "Pretty prints", but you don't have control over printing options.
- The output is streamed directly to the FILE object, so there is no memory overhead
in the TinyXML code.
- used by Print() and SaveFile()
- operator<<. Output to a c++ stream.
- Integrates with standart C++ iostreams.
- Outputs in "network printing" mode without line breaks. Good for network transmission
and moving XML between C++ objects, but hard for a human to read.
- TiXmlPrinter. Output to a std::string or memory buffer.
- API is less concise
- Future printing options will be put here.
- Printing may change slightly in future versions as it is refined and expanded.
<h3> Streams </h3>
With TIXML_USE_STL on TinyXML supports C++ streams (operator <<,>>) streams as well
as C (FILE*) streams. There are some differences that you may need to be aware of.
C style output:
- based on FILE*
- the Print() and SaveFile() methods
Generates formatted output, with plenty of white space, intended to be as
human-readable as possible. They are very fast, and tolerant of ill formed
XML documents. For example, an XML document that contains 2 root elements
and 2 declarations, will still print.
C style input:
- based on FILE*
- the Parse() and LoadFile() methods
A fast, tolerant read. Use whenever you don't need the C++ streams.
C++ style output:
- based on std::ostream
- operator<<
Generates condensed output, intended for network transmission rather than
readability. Depending on your system's implementation of the ostream class,
these may be somewhat slower. (Or may not.) Not tolerant of ill formed XML:
a document should contain the correct one root element. Additional root level
elements will not be streamed out.
C++ style input:
- based on std::istream
- operator>>
Reads XML from a stream, making it useful for network transmission. The tricky
part is knowing when the XML document is complete, since there will almost
certainly be other data in the stream. TinyXML will assume the XML data is
complete after it reads the root element. Put another way, documents that
are ill-constructed with more than one root element will not read correctly.
Also note that operator>> is somewhat slower than Parse, due to both
implementation of the STL and limitations of TinyXML.
<h3> White space </h3>
The world simply does not agree on whether white space should be kept, or condensed.
For example, pretend the '_' is a space, and look at "Hello____world". HTML, and
at least some XML parsers, will interpret this as "Hello_world". They condense white
space. Some XML parsers do not, and will leave it as "Hello____world". (Remember
to keep pretending the _ is a space.) Others suggest that __Hello___world__ should become
Hello___world.
It's an issue that hasn't been resolved to my satisfaction. TinyXML supports the
first 2 approaches. Call TiXmlBase::SetCondenseWhiteSpace( bool ) to set the desired behavior.
The default is to condense white space.
If you change the default, you should call TiXmlBase::SetCondenseWhiteSpace( bool )
before making any calls to Parse XML data, and I don't recommend changing it after
it has been set.
<h3> Handles </h3>
Where browsing an XML document in a robust way, it is important to check
for null returns from method calls. An error safe implementation can
generate a lot of code like:
@verbatim
TiXmlElement* root = document.FirstChildElement( "Document" );
if ( root )
{
TiXmlElement* element = root->FirstChildElement( "Element" );
if ( element )
{
TiXmlElement* child = element->FirstChildElement( "Child" );
if ( child )
{
TiXmlElement* child2 = child->NextSiblingElement( "Child" );
if ( child2 )
{
// Finally do something useful.
@endverbatim
Handles have been introduced to clean this up. Using the TiXmlHandle class,
the previous code reduces to:
@verbatim
TiXmlHandle docHandle( &document );
TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();
if ( child2 )
{
// do something useful
@endverbatim
Which is much easier to deal with. See TiXmlHandle for more information.
<h3> Row and Column tracking </h3>
Being able to track nodes and attributes back to their origin location
in source files can be very important for some applications. Additionally,
knowing where parsing errors occured in the original source can be very
time saving.
TinyXML can tracks the row and column origin of all nodes and attributes
in a text file. The TiXmlBase::Row() and TiXmlBase::Column() methods return
the origin of the node in the source text. The correct tabs can be
configured in TiXmlDocument::SetTabSize().
<h2> Using and Installing </h2>
To Compile and Run xmltest:
A Linux Makefile and a Windows Visual C++ .dsw file is provided.
Simply compile and run. It will write the file demotest.xml to your
disk and generate output on the screen. It also tests walking the
DOM by printing out the number of nodes found using different
techniques.
The Linux makefile is very generic and runs on many systems - it
is currently tested on mingw and
MacOSX. You do not need to run 'make depend'. The dependecies have been
hard coded.
<h3>Windows project file for VC6</h3>
<ul>
<li>tinyxml: tinyxml library, non-STL </li>
<li>tinyxmlSTL: tinyxml library, STL </li>
<li>tinyXmlTest: test app, non-STL </li>
<li>tinyXmlTestSTL: test app, STL </li>
</ul>
<h3>Makefile</h3>
At the top of the makefile you can set:
PROFILE, DEBUG, and TINYXML_USE_STL. Details (such that they are) are in
the makefile.
In the tinyxml directory, type "make clean" then "make". The executable
file 'xmltest' will be created.
<h3>To Use in an Application:</h3>
Add tinyxml.cpp, tinyxml.h, tinyxmlerror.cpp, tinyxmlparser.cpp, tinystr.cpp, and tinystr.h to your
project or make file. That's it! It should compile on any reasonably
compliant C++ system. You do not need to enable exceptions or
RTTI for TinyXML.
<h2> How TinyXML works. </h2>
An example is probably the best way to go. Take:
@verbatim
<?xml version="1.0" standalone=no>
<!-- Our to do list data -->
<ToDo>
<Item priority="1"> Go to the <bold>Toy store!</bold></Item>
<Item priority="2"> Do bills</Item>
</ToDo>
@endverbatim
Its not much of a To Do list, but it will do. To read this file
(say "demo.xml") you would create a document, and parse it in:
@verbatim
TiXmlDocument doc( "demo.xml" );
doc.LoadFile();
@endverbatim
And its ready to go. Now lets look at some lines and how they
relate to the DOM.
@verbatim
<?xml version="1.0" standalone=no>
@endverbatim
The first line is a declaration, and gets turned into the
TiXmlDeclaration class. It will be the first child of the
document node.
This is the only directive/special tag parsed by TinyXML.
Generally directive tags are stored in TiXmlUnknown so the
commands wont be lost when it is saved back to disk.
@verbatim
<!-- Our to do list data -->
@endverbatim
A comment. Will become a TiXmlComment object.
@verbatim
<ToDo>
@endverbatim
The "ToDo" tag defines a TiXmlElement object. This one does not have
any attributes, but does contain 2 other elements.
@verbatim
<Item priority="1">
@endverbatim
Creates another TiXmlElement which is a child of the "ToDo" element.
This element has 1 attribute, with the name "priority" and the value
"1".
@verbatim
Go to the
@endverbatim
A TiXmlText. This is a leaf node and cannot contain other nodes.
It is a child of the "Item" TiXmlElement.
@verbatim
<bold>
@endverbatim
Another TiXmlElement, this one a child of the "Item" element.
Etc.
Looking at the entire object tree, you end up with:
@verbatim
TiXmlDocument "demo.xml"
TiXmlDeclaration "version='1.0'" "standalone=no"
TiXmlComment " Our to do list data"
TiXmlElement "ToDo"
TiXmlElement "Item" Attribtutes: priority = 1
TiXmlText "Go to the "
TiXmlElement "bold"
TiXmlText "Toy store!"
TiXmlElement "Item" Attributes: priority=2
TiXmlText "Do bills"
@endverbatim
<h2> Documentation </h2>
The documentation is build with Doxygen, using the 'dox'
configuration file.
<h2> License </h2>
TinyXML is released under the zlib license:
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
<h2> References </h2>
The World Wide Web Consortium is the definitive standard body for
XML, and their web pages contain huge amounts of information.
The definitive spec: <a href="http://www.w3.org/TR/2004/REC-xml-20040204/">
http://www.w3.org/TR/2004/REC-xml-20040204/</a>
I also recommend "XML Pocket Reference" by Robert Eckstein and published by
OReilly...the book that got the whole thing started.
<h2> Contributors, Contacts, and a Brief History </h2>
Thanks very much to everyone who sends suggestions, bugs, ideas, and
encouragement. It all helps, and makes this project fun. A special thanks
to the contributors on the web pages that keep it lively.
So many people have sent in bugs and ideas, that rather than list here
we try to give credit due in the "changes.txt" file.
TinyXML was originally written by Lee Thomason. (Often the "I" still
in the documentation.) Lee reviews changes and releases new versions,
with the help of Yves Berquin, Andrew Ellerton, and the tinyXml community.
We appreciate your suggestions, and would love to know if you
use TinyXML. Hopefully you will enjoy it and find it useful.
Please post questions, comments, file bugs, or contact us at:
www.sourceforge.net/projects/tinyxml
Lee Thomason, Yves Berquin, Andrew Ellerton
*/

View File

@ -1,111 +0,0 @@
/*
www.sourceforge.net/projects/tinyxml
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef TIXML_USE_STL
#include "tinystr.h"
// Error value for find primitive
const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
// Null rep.
TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
void TiXmlString::reserve (size_type cap)
{
if (cap > capacity())
{
TiXmlString tmp;
tmp.init(length(), cap);
memcpy(tmp.start(), data(), length());
swap(tmp);
}
}
TiXmlString& TiXmlString::assign(const char* str, size_type len)
{
size_type cap = capacity();
if (len > cap || cap > 3*(len + 8))
{
TiXmlString tmp;
tmp.init(len);
memcpy(tmp.start(), str, len);
swap(tmp);
}
else
{
memmove(start(), str, len);
set_size(len);
}
return *this;
}
TiXmlString& TiXmlString::append(const char* str, size_type len)
{
size_type newsize = length() + len;
if (newsize > capacity())
{
reserve (newsize + capacity());
}
memmove(finish(), str, len);
set_size(newsize);
return *this;
}
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
{
TiXmlString tmp;
tmp.reserve(a.length() + b.length());
tmp += a;
tmp += b;
return tmp;
}
TiXmlString operator + (const TiXmlString & a, const char* b)
{
TiXmlString tmp;
TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
tmp.reserve(a.length() + b_len);
tmp += a;
tmp.append(b, b_len);
return tmp;
}
TiXmlString operator + (const char* a, const TiXmlString & b)
{
TiXmlString tmp;
TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
tmp.reserve(a_len + b.length());
tmp.append(a, a_len);
tmp += b;
return tmp;
}
#endif // TIXML_USE_STL

View File

@ -1,305 +0,0 @@
/*
www.sourceforge.net/projects/tinyxml
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef TIXML_USE_STL
#ifndef TIXML_STRING_INCLUDED
#define TIXML_STRING_INCLUDED
#include <assert.h>
#include <string.h>
/* The support for explicit isn't that universal, and it isn't really
required - it is used to check that the TiXmlString class isn't incorrectly
used. Be nice to old compilers and macro it here:
*/
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
// Microsoft visual studio, version 6 and higher.
#define TIXML_EXPLICIT explicit
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
// GCC version 3 and higher.s
#define TIXML_EXPLICIT explicit
#else
#define TIXML_EXPLICIT
#endif
/*
TiXmlString is an emulation of a subset of the std::string template.
Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
Only the member functions relevant to the TinyXML project have been implemented.
The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase
a string and there's no more room, we allocate a buffer twice as big as we need.
*/
class TiXmlString
{
public :
// The size type used
typedef size_t size_type;
// Error value for find primitive
static const size_type npos; // = -1;
// TiXmlString empty constructor
TiXmlString () : rep_(&nullrep_)
{
}
// TiXmlString copy constructor
TiXmlString ( const TiXmlString & copy) : rep_(0)
{
init(copy.length());
memcpy(start(), copy.data(), length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
{
init( static_cast<size_type>( strlen(copy) ));
memcpy(start(), copy, length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
{
init(len);
memcpy(start(), str, len);
}
// TiXmlString destructor
~TiXmlString ()
{
quit();
}
TiXmlString& operator = (const char * copy)
{
return assign( copy, (size_type)strlen(copy));
}
TiXmlString& operator = (const TiXmlString & copy)
{
return assign(copy.start(), copy.length());
}
// += operator. Maps to append
TiXmlString& operator += (const char * suffix)
{
return append(suffix, static_cast<size_type>( strlen(suffix) ));
}
// += operator. Maps to append
TiXmlString& operator += (char single)
{
return append(&single, 1);
}
// += operator. Maps to append
TiXmlString& operator += (const TiXmlString & suffix)
{
return append(suffix.data(), suffix.length());
}
// Convert a TiXmlString into a null-terminated char *
const char * c_str () const { return rep_->str; }
// Convert a TiXmlString into a char * (need not be null terminated).
const char * data () const { return rep_->str; }
// Return the length of a TiXmlString
size_type length () const { return rep_->size; }
// Alias for length()
size_type size () const { return rep_->size; }
// Checks if a TiXmlString is empty
bool empty () const { return rep_->size == 0; }
// Return capacity of string
size_type capacity () const { return rep_->capacity; }
// single char extraction
const char& at (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// [] operator
char& operator [] (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// find a char in a string. Return TiXmlString::npos if not found
size_type find (char lookup) const
{
return find(lookup, 0);
}
// find a char in a string from an offset. Return TiXmlString::npos if not found
size_type find (char tofind, size_type offset) const
{
if (offset >= length()) return npos;
for (const char* p = c_str() + offset; *p != '\0'; ++p)
{
if (*p == tofind) return static_cast< size_type >( p - c_str() );
}
return npos;
}
void clear ()
{
//Lee:
//The original was just too strange, though correct:
// TiXmlString().swap(*this);
//Instead use the quit & re-init:
quit();
init(0,0);
}
/* Function to reserve a big amount of data when we know we'll need it. Be aware that this
function DOES NOT clear the content of the TiXmlString if any exists.
*/
void reserve (size_type cap);
TiXmlString& assign (const char* str, size_type len);
TiXmlString& append (const char* str, size_type len);
void swap (TiXmlString& other)
{
Rep* r = rep_;
rep_ = other.rep_;
other.rep_ = r;
}
private:
void init(size_type sz) { init(sz, sz); }
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
char* start() const { return rep_->str; }
char* finish() const { return rep_->str + rep_->size; }
struct Rep
{
size_type size, capacity;
char str[1];
};
void init(size_type sz, size_type cap)
{
if (cap)
{
// Lee: the original form:
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
// doesn't work in some cases of new being overloaded. Switching
// to the normal allocation, although use an 'int' for systems
// that are overly picky about structure alignment.
const size_type bytesNeeded = sizeof(Rep) + cap;
const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
rep_->str[ rep_->size = sz ] = '\0';
rep_->capacity = cap;
}
else
{
rep_ = &nullrep_;
}
}
void quit()
{
if (rep_ != &nullrep_)
{
// The rep_ is really an array of ints. (see the allocator, above).
// Cast it back before delete, so the compiler won't incorrectly call destructors.
delete [] ( reinterpret_cast<int*>( rep_ ) );
}
}
Rep * rep_;
static Rep nullrep_;
} ;
inline bool operator == (const TiXmlString & a, const TiXmlString & b)
{
return ( a.length() == b.length() ) // optimization on some platforms
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
}
inline bool operator < (const TiXmlString & a, const TiXmlString & b)
{
return strcmp(a.c_str(), b.c_str()) < 0;
}
inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; }
inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
TiXmlString operator + (const TiXmlString & a, const char* b);
TiXmlString operator + (const char* a, const TiXmlString & b);
/*
TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
Only the operators that we need for TinyXML have been developped.
*/
class TiXmlOutStream : public TiXmlString
{
public :
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const TiXmlString & in)
{
*this += in;
return *this;
}
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const char * in)
{
*this += in;
return *this;
}
} ;
#endif // TIXML_STRING_INCLUDED
#endif // TIXML_USE_STL

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +0,0 @@
/*
www.sourceforge.net/projects/tinyxml
Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "tinyxml.h"
// The goal of the seperate error file is to make the first
// step towards localization. tinyxml (currently) only supports
// english error messages, but the could now be translated.
//
// It also cleans up the code a bit.
//
const char* TiXmlBase::errorString[ TiXmlBase::TIXML_ERROR_STRING_COUNT ] =
{
"No error",
"Error",
"Failed to open file",
"Error parsing Element.",
"Failed to read Element name",
"Error reading Element value.",
"Error reading Attributes.",
"Error: empty tag.",
"Error reading end tag.",
"Error parsing Unknown.",
"Error parsing Comment.",
"Error parsing Declaration.",
"Error document empty.",
"Error null (0) or unexpected EOF found in input stream.",
"Error parsing CDATA.",
"Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
};

File diff suppressed because it is too large Load Diff

1
third_party/tinyxml2 vendored Submodule

@ -0,0 +1 @@
Subproject commit 312a8092245df393db14a0b2427457ed2ba75e1b