commit
1654c9de66
@ -0,0 +1,7 @@ |
||||
venv/ |
||||
__pycache__/ |
||||
build/ |
||||
dist/ |
||||
*.xml |
||||
*.spec |
||||
*.log |
||||
@ -0,0 +1,5 @@ |
||||
{ |
||||
"files.associations": { |
||||
"ostream": "cpp" |
||||
} |
||||
} |
||||
Binary file not shown.
@ -0,0 +1,66 @@ |
||||
#include <iostream> |
||||
#include <Windows.h> |
||||
#include <string> |
||||
|
||||
#include "rapidxml-1.13/rapidxml.hpp" |
||||
#include "rapidxml-1.13/rapidxml_print.hpp" |
||||
#include "rapidxml-1.13/rapidxml_utils.hpp" |
||||
|
||||
#define DEBUG |
||||
|
||||
using namespace std; |
||||
|
||||
void getClipboardText(string& pasteBin)
|
||||
{ |
||||
HANDLE clip; |
||||
#ifdef DEBUG |
||||
cout << "Current clipboard: " << pasteBin << endl; |
||||
#endif |
||||
if (OpenClipboard(NULL))
|
||||
{ |
||||
clip = GetClipboardData(CF_TEXT); |
||||
pasteBin = (char*)clip; |
||||
CloseClipboard(); |
||||
#ifdef DEBUG |
||||
cout << "New clipboard: " << pasteBin << endl; |
||||
#endif |
||||
} |
||||
} |
||||
|
||||
void getTextToParse(string& pasteBin) |
||||
{ |
||||
bool accecpted {false}; |
||||
|
||||
while (!accecpted) { |
||||
getClipboardText(pasteBin); |
||||
cout << "Your current clipboard is:\n" << pasteBin << endl; |
||||
cout << "Is this the text you would like to parse? (y/n)" << endl; |
||||
char resp; |
||||
cin >> resp; |
||||
|
||||
if (resp == 'y') |
||||
accecpted = true; |
||||
|
||||
} |
||||
} |
||||
|
||||
|
||||
int main() |
||||
{ |
||||
cout << "Hello Word!\n"; |
||||
|
||||
string parseText; |
||||
|
||||
getTextToParse(parseText); |
||||
|
||||
|
||||
|
||||
// {
|
||||
// using namespace rapidxml;
|
||||
// xml_document<> doc;
|
||||
|
||||
// doc.parse<std::string>(currentClip)
|
||||
|
||||
// }
|
||||
|
||||
} |
||||
@ -0,0 +1,52 @@ |
||||
Use of this software is granted under one of the following two licenses, |
||||
to be chosen freely by the user. |
||||
|
||||
1. Boost Software License - Version 1.0 - August 17th, 2003 |
||||
=============================================================================== |
||||
|
||||
Copyright (c) 2006, 2007 Marcin Kalicinski |
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization |
||||
obtaining a copy of the software and accompanying documentation covered by |
||||
this license (the "Software") to use, reproduce, display, distribute, |
||||
execute, and transmit the Software, and to prepare derivative works of the |
||||
Software, and to permit third-parties to whom the Software is furnished to |
||||
do so, all subject to the following: |
||||
|
||||
The copyright notices in the Software and this entire statement, including |
||||
the above license grant, this restriction and the following disclaimer, |
||||
must be included in all copies of the Software, in whole or in part, and |
||||
all derivative works of the Software, unless such copies or derivative |
||||
works are solely in the form of machine-executable object code generated by |
||||
a source language processor. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
|
||||
2. The MIT License |
||||
=============================================================================== |
||||
|
||||
Copyright (c) 2006, 2007 Marcin Kalicinski |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
||||
of the Software, and to permit persons to whom the Software is furnished to do so, |
||||
subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
||||
IN THE SOFTWARE. |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,174 @@ |
||||
#ifndef RAPIDXML_ITERATORS_HPP_INCLUDED |
||||
#define RAPIDXML_ITERATORS_HPP_INCLUDED |
||||
|
||||
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||
// Version 1.13
|
||||
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||
//! \file rapidxml_iterators.hpp This file contains rapidxml iterators
|
||||
|
||||
#include "rapidxml.hpp" |
||||
|
||||
namespace rapidxml |
||||
{ |
||||
|
||||
//! Iterator of child nodes of xml_node
|
||||
template<class Ch> |
||||
class node_iterator |
||||
{ |
||||
|
||||
public: |
||||
|
||||
typedef typename xml_node<Ch> value_type; |
||||
typedef typename xml_node<Ch> &reference; |
||||
typedef typename xml_node<Ch> *pointer; |
||||
typedef std::ptrdiff_t difference_type; |
||||
typedef std::bidirectional_iterator_tag iterator_category; |
||||
|
||||
node_iterator() |
||||
: m_node(0) |
||||
{ |
||||
} |
||||
|
||||
node_iterator(xml_node<Ch> *node) |
||||
: m_node(node->first_node()) |
||||
{ |
||||
} |
||||
|
||||
reference operator *() const |
||||
{ |
||||
assert(m_node); |
||||
return *m_node; |
||||
} |
||||
|
||||
pointer operator->() const |
||||
{ |
||||
assert(m_node); |
||||
return m_node; |
||||
} |
||||
|
||||
node_iterator& operator++() |
||||
{ |
||||
assert(m_node); |
||||
m_node = m_node->next_sibling(); |
||||
return *this; |
||||
} |
||||
|
||||
node_iterator operator++(int) |
||||
{ |
||||
node_iterator tmp = *this; |
||||
++this; |
||||
return tmp; |
||||
} |
||||
|
||||
node_iterator& operator--() |
||||
{ |
||||
assert(m_node && m_node->previous_sibling()); |
||||
m_node = m_node->previous_sibling(); |
||||
return *this; |
||||
} |
||||
|
||||
node_iterator operator--(int) |
||||
{ |
||||
node_iterator tmp = *this; |
||||
++this; |
||||
return tmp; |
||||
} |
||||
|
||||
bool operator ==(const node_iterator<Ch> &rhs) |
||||
{ |
||||
return m_node == rhs.m_node; |
||||
} |
||||
|
||||
bool operator !=(const node_iterator<Ch> &rhs) |
||||
{ |
||||
return m_node != rhs.m_node; |
||||
} |
||||
|
||||
private: |
||||
|
||||
xml_node<Ch> *m_node; |
||||
|
||||
}; |
||||
|
||||
//! Iterator of child attributes of xml_node
|
||||
template<class Ch> |
||||
class attribute_iterator |
||||
{ |
||||
|
||||
public: |
||||
|
||||
typedef typename xml_attribute<Ch> value_type; |
||||
typedef typename xml_attribute<Ch> &reference; |
||||
typedef typename xml_attribute<Ch> *pointer; |
||||
typedef std::ptrdiff_t difference_type; |
||||
typedef std::bidirectional_iterator_tag iterator_category; |
||||
|
||||
attribute_iterator() |
||||
: m_attribute(0) |
||||
{ |
||||
} |
||||
|
||||
attribute_iterator(xml_node<Ch> *node) |
||||
: m_attribute(node->first_attribute()) |
||||
{ |
||||
} |
||||
|
||||
reference operator *() const |
||||
{ |
||||
assert(m_attribute); |
||||
return *m_attribute; |
||||
} |
||||
|
||||
pointer operator->() const |
||||
{ |
||||
assert(m_attribute); |
||||
return m_attribute; |
||||
} |
||||
|
||||
attribute_iterator& operator++() |
||||
{ |
||||
assert(m_attribute); |
||||
m_attribute = m_attribute->next_attribute(); |
||||
return *this; |
||||
} |
||||
|
||||
attribute_iterator operator++(int) |
||||
{ |
||||
attribute_iterator tmp = *this; |
||||
++this; |
||||
return tmp; |
||||
} |
||||
|
||||
attribute_iterator& operator--() |
||||
{ |
||||
assert(m_attribute && m_attribute->previous_attribute()); |
||||
m_attribute = m_attribute->previous_attribute(); |
||||
return *this; |
||||
} |
||||
|
||||
attribute_iterator operator--(int) |
||||
{ |
||||
attribute_iterator tmp = *this; |
||||
++this; |
||||
return tmp; |
||||
} |
||||
|
||||
bool operator ==(const attribute_iterator<Ch> &rhs) |
||||
{ |
||||
return m_attribute == rhs.m_attribute; |
||||
} |
||||
|
||||
bool operator !=(const attribute_iterator<Ch> &rhs) |
||||
{ |
||||
return m_attribute != rhs.m_attribute; |
||||
} |
||||
|
||||
private: |
||||
|
||||
xml_attribute<Ch> *m_attribute; |
||||
|
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,421 @@ |
||||
#ifndef RAPIDXML_PRINT_HPP_INCLUDED |
||||
#define RAPIDXML_PRINT_HPP_INCLUDED |
||||
|
||||
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||
// Version 1.13
|
||||
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||
//! \file rapidxml_print.hpp This file contains rapidxml printer implementation
|
||||
|
||||
#include "rapidxml.hpp" |
||||
|
||||
// Only include streams if not disabled
|
||||
#ifndef RAPIDXML_NO_STREAMS |
||||
#include <ostream> |
||||
#include <iterator> |
||||
#endif |
||||
|
||||
namespace rapidxml |
||||
{ |
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Printing flags
|
||||
|
||||
const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Internal
|
||||
|
||||
//! \cond internal
|
||||
namespace internal |
||||
{ |
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Internal character operations
|
||||
|
||||
// Copy characters from given range to given output iterator
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out) |
||||
{ |
||||
while (begin != end) |
||||
*out++ = *begin++; |
||||
return out; |
||||
} |
||||
|
||||
// Copy characters from given range to given output iterator and expand
|
||||
// characters into references (< > ' " &)
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand, OutIt out) |
||||
{ |
||||
while (begin != end) |
||||
{ |
||||
if (*begin == noexpand) |
||||
{ |
||||
*out++ = *begin; // No expansion, copy character
|
||||
} |
||||
else |
||||
{ |
||||
switch (*begin) |
||||
{ |
||||
case Ch('<'): |
||||
*out++ = Ch('&'); *out++ = Ch('l'); *out++ = Ch('t'); *out++ = Ch(';'); |
||||
break; |
||||
case Ch('>'):
|
||||
*out++ = Ch('&'); *out++ = Ch('g'); *out++ = Ch('t'); *out++ = Ch(';'); |
||||
break; |
||||
case Ch('\''):
|
||||
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('p'); *out++ = Ch('o'); *out++ = Ch('s'); *out++ = Ch(';'); |
||||
break; |
||||
case Ch('"'):
|
||||
*out++ = Ch('&'); *out++ = Ch('q'); *out++ = Ch('u'); *out++ = Ch('o'); *out++ = Ch('t'); *out++ = Ch(';'); |
||||
break; |
||||
case Ch('&'):
|
||||
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('m'); *out++ = Ch('p'); *out++ = Ch(';');
|
||||
break; |
||||
default: |
||||
*out++ = *begin; // No expansion, copy character
|
||||
} |
||||
} |
||||
++begin; // Step to next character
|
||||
} |
||||
return out; |
||||
} |
||||
|
||||
// Fill given output iterator with repetitions of the same character
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt fill_chars(OutIt out, int n, Ch ch) |
||||
{ |
||||
for (int i = 0; i < n; ++i) |
||||
*out++ = ch; |
||||
return out; |
||||
} |
||||
|
||||
// Find character
|
||||
template<class Ch, Ch ch> |
||||
inline bool find_char(const Ch *begin, const Ch *end) |
||||
{ |
||||
while (begin != end) |
||||
if (*begin++ == ch) |
||||
return true; |
||||
return false; |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Internal printing operations
|
||||
|
||||
// Print node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
// Print proper node type
|
||||
switch (node->type()) |
||||
{ |
||||
|
||||
// Document
|
||||
case node_document: |
||||
out = print_children(out, node, flags, indent); |
||||
break; |
||||
|
||||
// Element
|
||||
case node_element: |
||||
out = print_element_node(out, node, flags, indent); |
||||
break; |
||||
|
||||
// Data
|
||||
case node_data: |
||||
out = print_data_node(out, node, flags, indent); |
||||
break; |
||||
|
||||
// CDATA
|
||||
case node_cdata: |
||||
out = print_cdata_node(out, node, flags, indent); |
||||
break; |
||||
|
||||
// Declaration
|
||||
case node_declaration: |
||||
out = print_declaration_node(out, node, flags, indent); |
||||
break; |
||||
|
||||
// Comment
|
||||
case node_comment: |
||||
out = print_comment_node(out, node, flags, indent); |
||||
break; |
||||
|
||||
// Doctype
|
||||
case node_doctype: |
||||
out = print_doctype_node(out, node, flags, indent); |
||||
break; |
||||
|
||||
// Pi
|
||||
case node_pi: |
||||
out = print_pi_node(out, node, flags, indent); |
||||
break; |
||||
|
||||
// Unknown
|
||||
default: |
||||
assert(0); |
||||
break; |
||||
} |
||||
|
||||
// If indenting not disabled, add line break after node
|
||||
if (!(flags & print_no_indenting)) |
||||
*out = Ch('\n'), ++out; |
||||
|
||||
// Return modified iterator
|
||||
return out; |
||||
} |
||||
|
||||
// Print children of the node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
for (xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling()) |
||||
out = print_node(out, child, flags, indent); |
||||
return out; |
||||
} |
||||
|
||||
// Print attributes of the node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags) |
||||
{ |
||||
for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute()) |
||||
{ |
||||
if (attribute->name() && attribute->value()) |
||||
{ |
||||
// Print attribute name
|
||||
*out = Ch(' '), ++out; |
||||
out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out); |
||||
*out = Ch('='), ++out; |
||||
// Print attribute value using appropriate quote type
|
||||
if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size())) |
||||
{ |
||||
*out = Ch('\''), ++out; |
||||
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out); |
||||
*out = Ch('\''), ++out; |
||||
} |
||||
else |
||||
{ |
||||
*out = Ch('"'), ++out; |
||||
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out); |
||||
*out = Ch('"'), ++out; |
||||
} |
||||
} |
||||
} |
||||
return out; |
||||
} |
||||
|
||||
// Print data node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
assert(node->type() == node_data); |
||||
if (!(flags & print_no_indenting)) |
||||
out = fill_chars(out, indent, Ch('\t')); |
||||
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out); |
||||
return out; |
||||
} |
||||
|
||||
// Print data node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
assert(node->type() == node_cdata); |
||||
if (!(flags & print_no_indenting)) |
||||
out = fill_chars(out, indent, Ch('\t')); |
||||
*out = Ch('<'); ++out; |
||||
*out = Ch('!'); ++out; |
||||
*out = Ch('['); ++out; |
||||
*out = Ch('C'); ++out; |
||||
*out = Ch('D'); ++out; |
||||
*out = Ch('A'); ++out; |
||||
*out = Ch('T'); ++out; |
||||
*out = Ch('A'); ++out; |
||||
*out = Ch('['); ++out; |
||||
out = copy_chars(node->value(), node->value() + node->value_size(), out); |
||||
*out = Ch(']'); ++out; |
||||
*out = Ch(']'); ++out; |
||||
*out = Ch('>'); ++out; |
||||
return out; |
||||
} |
||||
|
||||
// Print element node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
assert(node->type() == node_element); |
||||
|
||||
// Print element name and attributes, if any
|
||||
if (!(flags & print_no_indenting)) |
||||
out = fill_chars(out, indent, Ch('\t')); |
||||
*out = Ch('<'), ++out; |
||||
out = copy_chars(node->name(), node->name() + node->name_size(), out); |
||||
out = print_attributes(out, node, flags); |
||||
|
||||
// If node is childless
|
||||
if (node->value_size() == 0 && !node->first_node()) |
||||
{ |
||||
// Print childless node tag ending
|
||||
*out = Ch('/'), ++out; |
||||
*out = Ch('>'), ++out; |
||||
} |
||||
else |
||||
{ |
||||
// Print normal node tag ending
|
||||
*out = Ch('>'), ++out; |
||||
|
||||
// Test if node contains a single data node only (and no other nodes)
|
||||
xml_node<Ch> *child = node->first_node(); |
||||
if (!child) |
||||
{ |
||||
// If node has no children, only print its value without indenting
|
||||
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out); |
||||
} |
||||
else if (child->next_sibling() == 0 && child->type() == node_data) |
||||
{ |
||||
// If node has a sole data child, only print its value without indenting
|
||||
out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out); |
||||
} |
||||
else |
||||
{ |
||||
// Print all children with full indenting
|
||||
if (!(flags & print_no_indenting)) |
||||
*out = Ch('\n'), ++out; |
||||
out = print_children(out, node, flags, indent + 1); |
||||
if (!(flags & print_no_indenting)) |
||||
out = fill_chars(out, indent, Ch('\t')); |
||||
} |
||||
|
||||
// Print node end
|
||||
*out = Ch('<'), ++out; |
||||
*out = Ch('/'), ++out; |
||||
out = copy_chars(node->name(), node->name() + node->name_size(), out); |
||||
*out = Ch('>'), ++out; |
||||
} |
||||
return out; |
||||
} |
||||
|
||||
// Print declaration node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
// Print declaration start
|
||||
if (!(flags & print_no_indenting)) |
||||
out = fill_chars(out, indent, Ch('\t')); |
||||
*out = Ch('<'), ++out; |
||||
*out = Ch('?'), ++out; |
||||
*out = Ch('x'), ++out; |
||||
*out = Ch('m'), ++out; |
||||
*out = Ch('l'), ++out; |
||||
|
||||
// Print attributes
|
||||
out = print_attributes(out, node, flags); |
||||
|
||||
// Print declaration end
|
||||
*out = Ch('?'), ++out; |
||||
*out = Ch('>'), ++out; |
||||
|
||||
return out; |
||||
} |
||||
|
||||
// Print comment node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
assert(node->type() == node_comment); |
||||
if (!(flags & print_no_indenting)) |
||||
out = fill_chars(out, indent, Ch('\t')); |
||||
*out = Ch('<'), ++out; |
||||
*out = Ch('!'), ++out; |
||||
*out = Ch('-'), ++out; |
||||
*out = Ch('-'), ++out; |
||||
out = copy_chars(node->value(), node->value() + node->value_size(), out); |
||||
*out = Ch('-'), ++out; |
||||
*out = Ch('-'), ++out; |
||||
*out = Ch('>'), ++out; |
||||
return out; |
||||
} |
||||
|
||||
// Print doctype node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
assert(node->type() == node_doctype); |
||||
if (!(flags & print_no_indenting)) |
||||
out = fill_chars(out, indent, Ch('\t')); |
||||
*out = Ch('<'), ++out; |
||||
*out = Ch('!'), ++out; |
||||
*out = Ch('D'), ++out; |
||||
*out = Ch('O'), ++out; |
||||
*out = Ch('C'), ++out; |
||||
*out = Ch('T'), ++out; |
||||
*out = Ch('Y'), ++out; |
||||
*out = Ch('P'), ++out; |
||||
*out = Ch('E'), ++out; |
||||
*out = Ch(' '), ++out; |
||||
out = copy_chars(node->value(), node->value() + node->value_size(), out); |
||||
*out = Ch('>'), ++out; |
||||
return out; |
||||
} |
||||
|
||||
// Print pi node
|
||||
template<class OutIt, class Ch> |
||||
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) |
||||
{ |
||||
assert(node->type() == node_pi); |
||||
if (!(flags & print_no_indenting)) |
||||
out = fill_chars(out, indent, Ch('\t')); |
||||
*out = Ch('<'), ++out; |
||||
*out = Ch('?'), ++out; |
||||
out = copy_chars(node->name(), node->name() + node->name_size(), out); |
||||
*out = Ch(' '), ++out; |
||||
out = copy_chars(node->value(), node->value() + node->value_size(), out); |
||||
*out = Ch('?'), ++out; |
||||
*out = Ch('>'), ++out; |
||||
return out; |
||||
} |
||||
|
||||
} |
||||
//! \endcond
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Printing
|
||||
|
||||
//! Prints XML to given output iterator.
|
||||
//! \param out Output iterator to print to.
|
||||
//! \param node Node to be printed. Pass xml_document to print entire document.
|
||||
//! \param flags Flags controlling how XML is printed.
|
||||
//! \return Output iterator pointing to position immediately after last character of printed text.
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print(OutIt out, const xml_node<Ch> &node, int flags = 0) |
||||
{ |
||||
return internal::print_node(out, &node, flags, 0); |
||||
} |
||||
|
||||
#ifndef RAPIDXML_NO_STREAMS |
||||
|
||||
//! Prints XML to given output stream.
|
||||
//! \param out Output stream to print to.
|
||||
//! \param node Node to be printed. Pass xml_document to print entire document.
|
||||
//! \param flags Flags controlling how XML is printed.
|
||||
//! \return Output stream.
|
||||
template<class Ch>
|
||||
inline std::basic_ostream<Ch> &print(std::basic_ostream<Ch> &out, const xml_node<Ch> &node, int flags = 0) |
||||
{ |
||||
print(std::ostream_iterator<Ch>(out), node, flags); |
||||
return out; |
||||
} |
||||
|
||||
//! Prints formatted XML to given output stream. Uses default printing flags. Use print() function to customize printing process.
|
||||
//! \param out Output stream to print to.
|
||||
//! \param node Node to be printed.
|
||||
//! \return Output stream.
|
||||
template<class Ch>
|
||||
inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out, const xml_node<Ch> &node) |
||||
{ |
||||
return print(out, node); |
||||
} |
||||
|
||||
#endif |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,122 @@ |
||||
#ifndef RAPIDXML_UTILS_HPP_INCLUDED |
||||
#define RAPIDXML_UTILS_HPP_INCLUDED |
||||
|
||||
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||
// Version 1.13
|
||||
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||
//! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful
|
||||
//! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective.
|
||||
|
||||
#include "rapidxml.hpp" |
||||
#include <vector> |
||||
#include <string> |
||||
#include <fstream> |
||||
#include <stdexcept> |
||||
|
||||
namespace rapidxml |
||||
{ |
||||
|
||||
//! Represents data loaded from a file
|
||||
template<class Ch = char> |
||||
class file |
||||
{ |
||||
|
||||
public: |
||||
|
||||
//! Loads file into the memory. Data will be automatically destroyed by the destructor.
|
||||
//! \param filename Filename to load.
|
||||
file(const char *filename) |
||||
{ |
||||
using namespace std; |
||||
|
||||
// Open stream
|
||||
basic_ifstream<Ch> stream(filename, ios::binary); |
||||
if (!stream) |
||||
throw runtime_error(string("cannot open file ") + filename); |
||||
stream.unsetf(ios::skipws); |
||||
|
||||
// Determine stream size
|
||||
stream.seekg(0, ios::end); |
||||
size_t size = stream.tellg(); |
||||
stream.seekg(0);
|
||||
|
||||
// Load data and add terminating 0
|
||||
m_data.resize(size + 1); |
||||
stream.read(&m_data.front(), static_cast<streamsize>(size)); |
||||
m_data[size] = 0; |
||||
} |
||||
|
||||
//! Loads file into the memory. Data will be automatically destroyed by the destructor
|
||||
//! \param stream Stream to load from
|
||||
file(std::basic_istream<Ch> &stream) |
||||
{ |
||||
using namespace std; |
||||
|
||||
// Load data and add terminating 0
|
||||
stream.unsetf(ios::skipws); |
||||
m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>()); |
||||
if (stream.fail() || stream.bad()) |
||||
throw runtime_error("error reading stream"); |
||||
m_data.push_back(0); |
||||
} |
||||
|
||||
//! Gets file data.
|
||||
//! \return Pointer to data of file.
|
||||
Ch *data() |
||||
{ |
||||
return &m_data.front(); |
||||
} |
||||
|
||||
//! Gets file data.
|
||||
//! \return Pointer to data of file.
|
||||
const Ch *data() const |
||||
{ |
||||
return &m_data.front(); |
||||
} |
||||
|
||||
//! Gets file data size.
|
||||
//! \return Size of file data, in characters.
|
||||
std::size_t size() const |
||||
{ |
||||
return m_data.size(); |
||||
} |
||||
|
||||
private: |
||||
|
||||
std::vector<Ch> m_data; // File data
|
||||
|
||||
}; |
||||
|
||||
//! Counts children of node. Time complexity is O(n).
|
||||
//! \return Number of children of node
|
||||
template<class Ch> |
||||
inline std::size_t count_children(xml_node<Ch> *node) |
||||
{ |
||||
xml_node<Ch> *child = node->first_node(); |
||||
std::size_t count = 0; |
||||
while (child) |
||||
{ |
||||
++count; |
||||
child = child->next_sibling(); |
||||
} |
||||
return count; |
||||
} |
||||
|
||||
//! Counts attributes of node. Time complexity is O(n).
|
||||
//! \return Number of attributes of node
|
||||
template<class Ch> |
||||
inline std::size_t count_attributes(xml_node<Ch> *node) |
||||
{ |
||||
xml_attribute<Ch> *attr = node->first_attribute(); |
||||
std::size_t count = 0; |
||||
while (attr) |
||||
{ |
||||
++count; |
||||
attr = attr->next_attribute(); |
||||
} |
||||
return count; |
||||
} |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,77 @@ |
||||
from typing import Literal, Optional |
||||
def cprint( |
||||
printValue, |
||||
color: Optional[Literal[ |
||||
"BLACK", |
||||
"RED", |
||||
"GREEN", |
||||
"BROWN", |
||||
"BLUE", |
||||
"PURPLE", |
||||
"CYAN", |
||||
"LIGHT_GRAY", |
||||
"DARK_GRAY", |
||||
"LIGHT_RED", |
||||
"LIGHT_GREEN", |
||||
"YELLOW", |
||||
"LIGHT_BLUE", |
||||
"LIGHT_PURPLE", |
||||
"LIGHT_CYAN", |
||||
"LIGHT_WHITE" |
||||
]] = None, |
||||
effect: Optional[Literal[ |
||||
"BOLD", |
||||
"FAINT", |
||||
"ITALIC", |
||||
"UNDERLINE", |
||||
"BLINK", |
||||
"NEGATIVE", |
||||
"CROSSED" |
||||
]] = None, |
||||
endFormatting: bool = True |
||||
): |
||||
""" |
||||
Prints printValue with added ascii effects. |
||||
If the value fails to print with effects, falls back to regular print |
||||
params: |
||||
printValue (any) : value to print |
||||
color (Literal["BLACK","RED","GREEN","BROWN","BLUE","PURPLE","CYAN","LIGHT_GRAY", |
||||
"DARK_GRAY","LIGHT_RED","LIGHT_GREEN","YELLOW","LIGHT_BLUE","LIGHT_PURPLE","LIGHT_CYAN","LIGHT_WHITE"]) |
||||
: sets the color of the text |
||||
effect ((Literal["BOLD","FAINT","ITALIC","UNDERLINE","BLINK","NEGATIVE","CROSSED"]) |
||||
: applies an effect to the text |
||||
endFormatting (bool): stop apply effects & resume default after printing. |
||||
return: |
||||
No return |
||||
No exceptions |
||||
""" |
||||
EFFECTS = { |
||||
"BLACK" : "\033[0;30m", |
||||
"RED" : "\033[0;31m", |
||||
"GREEN" : "\033[0;32m", |
||||
"BROWN" : "\033[0;33m", |
||||
"BLUE" : "\033[0;34m", |
||||
"PURPLE" : "\033[0;35m", |
||||
"CYAN" : "\033[0;36m", |
||||
"LIGHT_GRAY" : "\033[0;37m", |
||||
"DARK_GRAY" : "\033[1;30m", |
||||
"LIGHT_RED" : "\033[1;31m", |
||||
"LIGHT_GREEN" : "\033[1;32m", |
||||
"YELLOW" : "\033[1;33m", |
||||
"LIGHT_BLUE" : "\033[1;34m", |
||||
"LIGHT_PURPLE" : "\033[1;35m", |
||||
"LIGHT_CYAN" : "\033[1;36m", |
||||
"LIGHT_WHITE" : "\033[1;37m", |
||||
"BOLD" : "\033[1m", |
||||
"FAINT" : "\033[2m", |
||||
"ITALIC" : "\033[3m", |
||||
"UNDERLINE" : "\033[4m", |
||||
"BLINK" : "\033[5m", |
||||
"NEGATIVE" : "\033[7m", |
||||
"CROSSED" : "\033[9m", |
||||
"END" : "\033[0m", |
||||
} |
||||
try: |
||||
print(f"{EFFECTS[color] if color != None else ''}{EFFECTS[effect] if effect != None else ''}{printValue}{EFFECTS['END'] if endFormatting else ''}") |
||||
except: |
||||
print(printValue) |
||||
@ -0,0 +1,110 @@ |
||||
try: |
||||
import re |
||||
from pandas import DataFrame |
||||
from typing import Union |
||||
from logging import debug as dbg, getLogger |
||||
import win32clipboard |
||||
|
||||
|
||||
def create_table(xmlStr: str) -> Union[DataFrame, Exception]: |
||||
dataDict = { |
||||
"SEQ": [], |
||||
} |
||||
MATCH_SCENARIO = "<Scenario Seq=\"\d{1,3}\">((?!<Sc)(.|\n))*</S" |
||||
senarios = re.finditer(MATCH_SCENARIO,xmlStr) |
||||
dbg(senarios) |
||||
senario: re.Match |
||||
for senario in senarios: |
||||
senarioGroup = senario.group() |
||||
seqMatch = re.search("\"\d{1,3}\"",senarioGroup).group() |
||||
seq = seqMatch[1:-1] |
||||
dbg(f"\nSeq: {seq}") |
||||
|
||||
CONDITION_REGEX = "<Condition Id=\"\w+\" Group=\"\w+\" CompareTo=\"(Value|Range)\">((?!</C)(.|\n))*</Condition>" |
||||
c = list(re.finditer(CONDITION_REGEX,senarioGroup)) |
||||
dbg(f"conditions:\n{[cond for cond in c]}") |
||||
senarioDict = {} |
||||
senarioDict["SEQ"] = int(seq) |
||||
for m in c: |
||||
group = m.group() |
||||
idStart, idEnd = re.search("\"[^\"]*\"", group).span() |
||||
id = group[idStart+1:idEnd-1] |
||||
dbg(f"SEQ: {seq} | {id}") |
||||
valueGroup = re.search("e\">(.)*<", group) |
||||
if valueGroup == None: |
||||
valueGroup = re.search("e\"(((?!</C)(.|\n))*)</C", group) |
||||
value = valueGroup.group()[4:-3].strip() |
||||
else: |
||||
value = valueGroup.group()[3:-1] |
||||
dbg(f"SEQ: {seq} | {valueGroup}") |
||||
dbg(f"SEQ: {seq} | {value}") |
||||
senarioDict[id] = value |
||||
# Now merge the values from that senario into the main dict |
||||
seen = [] |
||||
for key in dataDict.keys(): |
||||
dbg(dataDict[key]) |
||||
try: |
||||
senarioValue = senarioDict[key] |
||||
except KeyError: |
||||
senarioValue = '' |
||||
dataDict[key].append(senarioValue) |
||||
seen.append(key) |
||||
for key in [k for k in senarioDict.keys() if k not in seen]: |
||||
dataFill = ['' for _ in range(1,int(seq))] |
||||
dataFill.append(senarioDict[key]) |
||||
dataDict[key] = dataFill |
||||
dbg(f"New key: {key} | {dataDict[key]}") |
||||
|
||||
dbg(f"{seq} | {dataDict}\n") |
||||
|
||||
dbg(dataDict) |
||||
if getLogger().level == 10: |
||||
for key in dataDict.keys(): |
||||
dbg(f"{key} : {len(dataDict[key])}") |
||||
try: |
||||
table = DataFrame(dataDict) |
||||
table.set_index('SEQ', inplace=True) |
||||
dbg(table) |
||||
if table.empty: |
||||
raise Exception("No data found...", color='RED', effect='BOLD') |
||||
return table |
||||
except Exception as e: |
||||
return e |
||||
|
||||
|
||||
def process_clipboard() -> str: |
||||
correct = False |
||||
while not correct: |
||||
win32clipboard.OpenClipboard() |
||||
try: |
||||
xml = win32clipboard.GetClipboardData() |
||||
except: |
||||
xml = "None" |
||||
win32clipboard.CloseClipboard() |
||||
print(f"\n\nYour current clipboard is as follows:") |
||||
print(xml) |
||||
yn = input("\nIs this the XML you'd like to parse? (y/n)\n >") |
||||
if yn.lower() == "debug": |
||||
getLogger().setLevel(10) |
||||
print("\nYou have now entered debug mode...") |
||||
correct = True if re.search("(?i)y|1", yn) != None else False |
||||
if not correct: |
||||
input("Please copy the xml then press enter...") |
||||
return xml |
||||
|
||||
|
||||
table = None |
||||
while type(table) != DataFrame: |
||||
xml = process_clipboard() |
||||
table: Union[DataFrame, Exception] = create_table(xml) |
||||
if type(table) != DataFrame: |
||||
print(f"\n\nENCOUNTERED ERROR!:\n{table}\n") |
||||
input("Please try again...") |
||||
continue |
||||
print(f"Table sample:") |
||||
print(table) |
||||
table.to_clipboard() |
||||
input("This table is now in your clipboard to paste into excel.") |
||||
except Exception as e: |
||||
print(f"The program failed to start do the the following exception:\n{e}") |
||||
input(f"Please make note of the error before closing so that you can report it.") |
||||
|
After Width: | Height: | Size: 66 KiB |
Loading…
Reference in new issue