Skip to content

Commit

Permalink
Move to TinyXML2 v9.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
parsley72 committed Dec 16, 2023
1 parent 1190f8e commit 04a6a71
Show file tree
Hide file tree
Showing 36 changed files with 361 additions and 6,146 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout repository and submodules
uses: actions/checkout@v3
with:
submodules: recursive

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand All @@ -32,4 +35,4 @@ jobs:
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
run: ${{github.workspace}}/build/test_tinyxpath
run: ${{github.workspace}}/build/test_tinyxpath2
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tinyxml2"]
path = tinyxml2
url = https://github.com/leethomason/tinyxml2.git
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/test_tinyxpath",
"program": "${workspaceFolder}/build/test_tinyxpath2",
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"cwd": "${workspaceFolder}/",
Expand All @@ -21,4 +21,4 @@
]
}
]
}
}
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ cmake_minimum_required(VERSION 3.17)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(TinyXPath
project(TinyXPath2
VERSION 1.3.1
LANGUAGES CXX
)

include_directories(tinyxml)
# set(CMAKE_BUILD_TYPE "Debug")

add_library(tinyxpath STATIC htmlutil.cpp tinyxml/tinystr.cpp tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.cpp action_store.cpp lex_util.cpp node_set.cpp tokenlist.cpp xml_util.cpp xpath_expression.cpp xpath_processor.cpp xpath_stack.cpp xpath_stream.cpp xpath_syntax.cpp xpath_static.cpp action_store.h byte_stream.h htmlutil.h lex_token.h lex_util.h node_set.h tinyxpath_conf.h tokenlist.h xml_util.h xpath_expression.h xpath_processor.h xpath_stack.h xpath_stream.h xpath_syntax.h)
include_directories(tinyxml2)

set_target_properties(tinyxpath PROPERTIES PUBLIC_HEADER "tinyxml/tinyxml.h;tinystr.h;xpath_static.h")
add_library(tinyxpath2 STATIC htmlutil.cpp tinyxml2/tinyxml2.cpp action_store.cpp lex_util.cpp node_set.cpp tokenlist.cpp xml_util.cpp xpath_expression.cpp xpath_processor.cpp xpath_stack.cpp xpath_stream.cpp xpath_syntax.cpp xpath_static.cpp action_store.h byte_stream.h htmlutil.h lex_token.h lex_util.h node_set.h tinyxpath_conf.h tokenlist.h xml_util.h xpath_expression.h xpath_processor.h xpath_stack.h xpath_stream.h xpath_syntax.h)

install(TARGETS tinyxpath
set_target_properties(tinyxpath2 PROPERTIES PUBLIC_HEADER "tinyxml2/tinyxml2.h;tinystr.h;xpath_static.h")

install(TARGETS tinyxpath2
PUBLIC_HEADER DESTINATION include
ARCHIVE DESTINATION lib/${LIBRARY_SUBDIR})

add_executable(test_tinyxpath main.cpp htmlutil.cpp tinyxml/tinystr.cpp tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.cpp action_store.cpp lex_util.cpp node_set.cpp tokenlist.cpp xml_util.cpp xpath_expression.cpp xpath_processor.cpp xpath_stack.cpp xpath_stream.cpp xpath_syntax.cpp xpath_static.cpp action_store.h byte_stream.h htmlutil.h lex_token.h lex_util.h node_set.h tinyxpath_conf.h tokenlist.h xml_util.h xpath_expression.h xpath_processor.h xpath_stack.h xpath_stream.h xpath_syntax.h)
add_executable(test_tinyxpath2 main.cpp htmlutil.cpp tinyxml2/tinyxml2.cpp action_store.cpp lex_util.cpp node_set.cpp tokenlist.cpp xml_util.cpp xpath_expression.cpp xpath_processor.cpp xpath_stack.cpp xpath_stream.cpp xpath_syntax.cpp xpath_static.cpp action_store.h byte_stream.h htmlutil.h lex_token.h lex_util.h node_set.h tinyxpath_conf.h tokenlist.h xml_util.h xpath_expression.h xpath_processor.h xpath_stack.h xpath_stream.h xpath_syntax.h)
6 changes: 5 additions & 1 deletion action_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ distribution.

#include "action_store.h"

#include <cassert>

using namespace std;

namespace TinyXPath {

/// Allocation unit
Expand Down Expand Up @@ -73,7 +77,7 @@ void action_store::v_add(int i_1, int i_2, int i_3, const char* cp_string) {
}

/// Get one element from the placeholder
void action_store::v_get(int i_entry, int& i_1, int& i_2, int& i_3, TIXML_STRING& S_out) {
void action_store::v_get(int i_entry, int& i_1, int& i_2, int& i_3, string& S_out) {
assert(i_entry >= 0 && i_entry < _i_size);
assert(_aipp_list[i_entry]);
_aipp_list[i_entry]->v_get(i_1, i_2, i_3, S_out);
Expand Down
10 changes: 6 additions & 4 deletions action_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ distribution.
#ifndef __ACTION_STORE_H
#define __ACTION_STORE_H

#include "tinyxml.h"
#include <string>

#include "tinyxml2.h"

namespace TinyXPath {

Expand All @@ -44,7 +46,7 @@ class action_item {
}

/// Retrieve the set of values
void v_get(int& i_out_1, int& i_out_2, int& i_out_3, TIXML_STRING& S_out) {
void v_get(int& i_out_1, int& i_out_2, int& i_out_3, std::string& S_out) {
i_out_1 = _i_1;
i_out_2 = _i_2;
i_out_3 = _i_3;
Expand All @@ -55,7 +57,7 @@ class action_item {
/// Integer triplet values
int _i_1, _i_2, _i_3;
/// String value
TIXML_STRING _S_string;
std::string _S_string;
};

/// The XPath action stack. Not a stack per se, only a placeholder
Expand All @@ -72,7 +74,7 @@ class action_store {
return _i_size;
}
/// Get one element from the placeholder
void v_get(int i_position, int& i_1, int& i_2, int& i_3, TIXML_STRING& S_out);
void v_get(int i_position, int& i_1, int& i_2, int& i_3, std::string& S_out);
/// Get the current position. See _i_position.
int i_get_position() {
return _i_position;
Expand Down
100 changes: 44 additions & 56 deletions htmlutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ distribution.

#include "htmlutil.h"

#include "tinyxml.h"
#include <cassert>

#include "tinyxml2.h"

using namespace std;
using namespace tinyxml2;

/// Generate some indentation on the HTML or file output
void v_levelize(int i_level, FILE* Fp_out, bool o_html) {
Expand All @@ -44,69 +49,52 @@ void v_levelize(int i_level, FILE* Fp_out, bool o_html) {

/// Dumps an XML tree to an HTML document
/// \n This is a recursive function, called again at each element in the tree
void v_out_html(FILE* Fp_out, ///< Output HTML file
const TiXmlNode* XNp_source, ///< Input XML tree
unsigned u_level) ///< Current level
void v_out_html(FILE* Fp_out, ///< Output HTML file
const XMLNode* XNp_source, ///< Input XML tree
unsigned u_level) ///< Current level
{
const TiXmlNode* XNp_child;
const TiXmlAttribute* XAp_att;
const XMLNode* XNp_child;
const XMLAttribute* XAp_att;

XNp_child = XNp_source->FirstChild();
while (XNp_child) {
switch (XNp_child->Type()) {
case TiXmlNode::TINYXML_DOCUMENT:
fprintf(Fp_out, "\nStart document\n");
break;

case TiXmlNode::TINYXML_ELEMENT:
v_levelize((int)u_level, Fp_out, true);
fprintf(Fp_out, "&lt;"); // '<'
fprintf(Fp_out, "%s", XNp_child->ToElement()->Value());
// fprintf (Fp_out, "<small>[%d]</small>", XNp_child -> GetUserValue ());
XAp_att = XNp_child->ToElement()->FirstAttribute();
while (XAp_att) {
fprintf(Fp_out, " %s='%s'", XAp_att->Name(), XAp_att->Value());
XAp_att = XAp_att->Next();
}
if (XNp_child->FirstChild())
fprintf(Fp_out, "&gt;<br>\n"); // '>\n'
else
fprintf(Fp_out, " /&gt;<br>\n");
break;

case TiXmlNode::TINYXML_COMMENT:
fprintf(Fp_out, "&lt;!-- %s --&gt;<br>\n", XNp_child->ToComment()->Value());
break;
case TiXmlNode::TINYXML_TEXT:
fprintf(Fp_out, "%s\n", XNp_child->ToText()->Value());
break;
case TiXmlNode::TINYXML_UNKNOWN:
case TiXmlNode::TINYXML_DECLARATION:
break;
default:
assert(false);
if (XNp_child->ToDocument()) {
fprintf(Fp_out, "\nStart document\n");
} else if (XNp_child->ToElement()) {
v_levelize((int)u_level, Fp_out, true);
fprintf(Fp_out, "&lt;"); // '<'
fprintf(Fp_out, "%s", XNp_child->ToElement()->Value());
// fprintf (Fp_out, "<small>[%d]</small>", XNp_child -> GetUserValue ());
XAp_att = XNp_child->ToElement()->FirstAttribute();
while (XAp_att) {
fprintf(Fp_out, " %s='%s'", XAp_att->Name(), XAp_att->Value());
XAp_att = XAp_att->Next();
}
if (XNp_child->FirstChild())
fprintf(Fp_out, "&gt;<br>\n"); // '>\n'
else
fprintf(Fp_out, " /&gt;<br>\n");
} else if (XNp_child->ToComment()) {
fprintf(Fp_out, "&lt;!-- %s --&gt;<br>\n", XNp_child->ToComment()->Value());
} else if (XNp_child->ToText()) {
fprintf(Fp_out, "%s\n", XNp_child->ToText()->Value());
} else if (XNp_child->ToUnknown()) {
} else if (XNp_child->ToDeclaration()) {
} else {
assert(false);
}

v_out_html(Fp_out, XNp_child, u_level + 1);

switch (XNp_child->Type()) {
case TiXmlNode::TINYXML_DOCUMENT:
fprintf(Fp_out, "\nEnd document\n");
break;
case TiXmlNode::TINYXML_ELEMENT:
if (XNp_child->FirstChild()) {
v_levelize((int)u_level, Fp_out, true);
fprintf(Fp_out, "&lt;");
fprintf(Fp_out, "/%s", XNp_child->ToElement()->Value());
fprintf(Fp_out, "&gt;<br>\n"); // '>\n'
}
break;
case TiXmlNode::TINYXML_COMMENT:
case TiXmlNode::TINYXML_TEXT:
case TiXmlNode::TINYXML_UNKNOWN:
case TiXmlNode::TINYXML_DECLARATION:
default:
break;
if (XNp_child->ToDocument()) {
fprintf(Fp_out, "\nEnd document\n");
} else if (XNp_child->ToElement()) {
if (XNp_child->FirstChild()) {
v_levelize((int)u_level, Fp_out, true);
fprintf(Fp_out, "&lt;");
fprintf(Fp_out, "/%s", XNp_child->ToElement()->Value());
fprintf(Fp_out, "&gt;<br>\n"); // '>\n'
}
}
XNp_child = XNp_child->NextSibling();
}
Expand Down
4 changes: 2 additions & 2 deletions htmlutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ distribution.
#ifndef __HTMLUTIL_H
#define __HTMLUTIL_H

#include "tinyxml.h"
#include "tinyxml2.h"

extern void v_out_html(FILE* Fp_out, const TiXmlNode* XNp_source, unsigned u_level);
extern void v_out_html(FILE* Fp_out, const tinyxml2::XMLNode* XNp_source, unsigned u_level);
extern void v_levelize(int i_level, FILE* Fp_out = stdout, bool o_html = false);

#endif // __HTMLUTIL_H
11 changes: 5 additions & 6 deletions lex_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ distribution.

#include "lex_util.h"

#include <stdio.h>
#include <string.h>
using namespace std;

namespace TinyXPath {

Expand Down Expand Up @@ -229,8 +228,8 @@ lexico lex_test_id(const _byte_* bp_str, unsigned u_size, lexico lex_next) {
}

/// Removes all leading and trailing white spaces
TIXML_STRING S_remove_lead_trail(const char* cp_in) {
TIXML_STRING S_ret;
string S_remove_lead_trail(const char* cp_in) {
string S_ret;
const char *cp_start, *cp_end;
char *cp_new, *cp_out;

Expand Down Expand Up @@ -259,7 +258,7 @@ TIXML_STRING S_remove_lead_trail(const char* cp_in) {
}

/// Assign an integer to a string
void v_assign_int_to_string(TIXML_STRING& S_string, int i_val) {
void v_assign_int_to_string(string& S_string, int i_val) {
char ca_int[80];

sprintf(ca_int, "%d", i_val);
Expand All @@ -268,7 +267,7 @@ void v_assign_int_to_string(TIXML_STRING& S_string, int i_val) {

/// Assign a double to a string, cleaning any trailing zeroes and the decimal point if there's no
/// decimal part
void v_assign_double_to_string(TIXML_STRING& S_string, double d_val) {
void v_assign_double_to_string(string& S_string, double d_val) {
char ca_int[80];

sprintf(ca_int, "%f", d_val);
Expand Down
10 changes: 6 additions & 4 deletions lex_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ distribution.
#ifndef __TINYUTIL_H
#define __TINYUTIL_H

#include "tinyxml.h"
#include <string>

#include "tinyxml2.h"
#include "tinyxpath_conf.h"

#ifdef _MSC_VER
Expand Down Expand Up @@ -223,9 +225,9 @@ extern const char* cp_disp_class_lex(lexico lex_in);
extern bool o_is_axis_name(lexico lex_test);
extern lexico lex_get_class(_byte_ b_in);
extern lexico lex_test_id(const _byte_* bp_str, unsigned u_size, lexico);
extern TIXML_STRING S_remove_lead_trail(const char* cp_in);
extern void v_assign_int_to_string(TIXML_STRING& S_string, int i_val);
extern void v_assign_double_to_string(TIXML_STRING& S_string, double d_val);
extern std::string S_remove_lead_trail(const char* cp_in);
extern void v_assign_int_to_string(std::string& S_string, int i_val);
extern void v_assign_double_to_string(std::string& S_string, double d_val);
#ifdef TINYXPATH_DEBUG
extern const char* cp_disp_construct(xpath_construct xc);
extern void v_generate_ascii_htm();
Expand Down
Loading

0 comments on commit 04a6a71

Please sign in to comment.