mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-17 18:12:04 +01:00
hacked up a ncname test, although it's not working at the moment and I'm tired and can't think
This commit is contained in:
parent
12b6b5dd92
commit
2e6c372933
10 changed files with 136 additions and 29 deletions
|
@ -126,6 +126,7 @@ class libxml2_wrapper : public XMLReaderInterface<string_type, T0, T1>,
|
|||
typedef SAX::DTDHandler<string_type, string_adaptor> dtdHandlerT;
|
||||
typedef SAX::ContentHandler<string_type, string_adaptor> contentHandlerT;
|
||||
typedef SAX::Attributes<string_type, string_adaptor> attributesT;
|
||||
typedef SAX::AttributeType<string_type, string_adaptor> attributeTypeT;
|
||||
typedef SAX::DeclHandler<string_type, string_adaptor> declHandlerT;
|
||||
typedef SAX::LexicalHandler<string_type, string_adaptor> lexicalHandlerT;
|
||||
typedef SAX::InputSource<string_type, string_adaptor> inputSourceT;
|
||||
|
@ -568,7 +569,7 @@ void libxml2_wrapper<string_type, T0, T1>::SAXstartElement(const xmlChar* qName,
|
|||
attributes.addAttribute(emptyString_,
|
||||
emptyString_,
|
||||
attQName,
|
||||
attributesT::Type::CDATA,
|
||||
attributeTypeT::CDATA,
|
||||
value);
|
||||
}
|
||||
} // while
|
||||
|
@ -585,7 +586,7 @@ void libxml2_wrapper<string_type, T0, T1>::SAXstartElement(const xmlChar* qName,
|
|||
attributes.addAttribute(attName.URI,
|
||||
attName.localName,
|
||||
attName.rawName,
|
||||
attributesT::Type::CDATA,
|
||||
attributeTypeT::CDATA,
|
||||
value);
|
||||
}
|
||||
} // while ...
|
||||
|
@ -611,7 +612,7 @@ void libxml2_wrapper<string_type, T0, T1>::SAXstartElementNoNS(const xmlChar* qN
|
|||
attributes.addAttribute(emptyString_,
|
||||
emptyString_,
|
||||
attQName,
|
||||
attributesT::Type::CDATA,
|
||||
attributeTypeT::CDATA,
|
||||
value);
|
||||
} // while ..
|
||||
} // if ...
|
||||
|
|
41
include/XML/strings.hpp
Executable file
41
include/XML/strings.hpp
Executable file
|
@ -0,0 +1,41 @@
|
|||
#ifndef ARABICA_XML_STRINGS_HPP
|
||||
#define ARABICA_XML_STRINGS_HPP
|
||||
|
||||
#include <XML/XMLCharacterClasses.hpp>
|
||||
#include <text/UnicodeCharacters.hpp>
|
||||
|
||||
namespace Arabica
|
||||
{
|
||||
namespace XML
|
||||
{
|
||||
|
||||
bool is_ncname(const std::string& str)
|
||||
{
|
||||
using namespace Arabica::text;
|
||||
|
||||
std::string::const_iterator s = str.begin();
|
||||
if(!(is_letter(*s) || (*s == Unicode<char>::LOW_LINE)))
|
||||
return false;
|
||||
|
||||
++s;
|
||||
for(std::string::const_iterator se; s != se; ++s)
|
||||
{
|
||||
wchar_t c = static_cast<wchar_t>(*s);
|
||||
if(!(is_letter(c) ||
|
||||
is_digit(c) ||
|
||||
(c == Unicode<wchar_t>::FULL_STOP) ||
|
||||
(c == Unicode<wchar_t>::HYPHEN_MINUS) ||
|
||||
(c == Unicode<wchar_t>::LOW_LINE) ||
|
||||
(c == Unicode<wchar_t>::COLON) ||
|
||||
is_combining_char(c) ||
|
||||
is_extender(c)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // is_ncname
|
||||
|
||||
} // namespace XML
|
||||
} // namespace Arabica
|
||||
|
||||
|
||||
#endif
|
|
@ -51,7 +51,8 @@ namespace impl
|
|||
|
||||
virtual void scan(const XPathExpression_impl<string_type, string_adaptor>* const expr)
|
||||
{
|
||||
const FunctionHolder<string_type, string_adaptor>* const fn = dynamic_cast<const FunctionHolder<string_type, string_adaptor>* const>(expr);
|
||||
typedef FunctionHolder<string_type, string_adaptor> FH;
|
||||
const FH* const fn = dynamic_cast<const FH* const>(expr);
|
||||
if(fn == 0)
|
||||
return;
|
||||
|
||||
|
@ -98,7 +99,7 @@ MatchExpr<string_type, string_adaptor>::MatchExpr(XPathExpression_impl<string_ty
|
|||
RelativeLocation* path = dynamic_cast<RelativeLocation*>(match);
|
||||
// foreach step in the steplist
|
||||
StepList& steps = path->steps_;
|
||||
for(StepList::const_iterator s = steps.begin(), se = steps.end(); s != se; ++s)
|
||||
for(typename StepList::const_iterator s = steps.begin(), se = steps.end(); s != se; ++s)
|
||||
{
|
||||
// foreach predicate in the predicatelist
|
||||
Step* step = dynamic_cast<Step*>(*s);
|
||||
|
@ -106,7 +107,7 @@ MatchExpr<string_type, string_adaptor>::MatchExpr(XPathExpression_impl<string_ty
|
|||
continue;
|
||||
|
||||
Predicates& predicates = step->predicates_;
|
||||
for(Predicates::iterator p = predicates.begin(), pe = predicates.end(); p != pe; ++p)
|
||||
for(typename Predicates::iterator p = predicates.begin(), pe = predicates.end(); p != pe; ++p)
|
||||
{
|
||||
// should rewrite?
|
||||
Expression* pred = *p;
|
||||
|
|
|
@ -32,7 +32,7 @@ template<class string_type, class string_adaptor>
|
|||
class AnyNodeTest : public NodeTest<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual NodeTest* clone() const { return new AnyNodeTest(); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new AnyNodeTest(); }
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
return true;
|
||||
|
@ -43,7 +43,7 @@ template<class string_type, class string_adaptor>
|
|||
class NodeNodeTest : public NodeTest<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual NodeTest* clone() const { return new NodeNodeTest(); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new NodeNodeTest(); }
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
int type = node.getNodeType();
|
||||
|
@ -59,7 +59,7 @@ class NameNodeTest : public NodeTest<string_type, string_adaptor>
|
|||
{
|
||||
public:
|
||||
NameNodeTest(const string_type& name) : name_(name) { }
|
||||
virtual NodeTest* clone() const { return new NameNodeTest(name_); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new NameNodeTest(name_); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ class AttributeNameNodeTest : public NodeTest<string_type, string_adaptor>
|
|||
{
|
||||
public:
|
||||
AttributeNameNodeTest(const string_type& name) : name_(name) { }
|
||||
virtual NodeTest* clone() const { return new AttributeNameNodeTest(name_); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new AttributeNameNodeTest(name_); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ class QNameNodeTest : public NodeTest<string_type, string_adaptor>
|
|||
public:
|
||||
QNameNodeTest(const string_type& namespace_uri, const string_type& name) :
|
||||
uri_(namespace_uri), name_(name) { }
|
||||
virtual NodeTest* clone() const { return new QNameNodeTest(uri_, name_); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new QNameNodeTest(uri_, name_); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -118,7 +118,7 @@ class AttributeQNameNodeTest : public NodeTest<string_type, string_adaptor>
|
|||
public:
|
||||
AttributeQNameNodeTest(const string_type& namespace_uri, const string_type& name) :
|
||||
uri_(namespace_uri), name_(name) { }
|
||||
virtual NodeTest* clone() const { return new AttributeQNameNodeTest(uri_, name_); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new AttributeQNameNodeTest(uri_, name_); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -136,7 +136,7 @@ template<class string_type, class string_adaptor>
|
|||
class StarNodeTest : public NodeTest<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual NodeTest* clone() const { return new StarNodeTest(); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new StarNodeTest(); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -152,7 +152,7 @@ class QStarNodeTest : public StarNodeTest<string_type, string_adaptor>
|
|||
typedef StarNodeTest<string_type, string_adaptor> baseT;
|
||||
public:
|
||||
QStarNodeTest(const string_type& namespace_uri) : baseT(), uri_(namespace_uri) { }
|
||||
virtual NodeTest* clone() const { return new QStarNodeTest(uri_); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new QStarNodeTest(uri_); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ template<class string_type, class string_adaptor>
|
|||
class TextNodeTest : public NodeTest<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual NodeTest* clone() const { return new TextNodeTest(); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new TextNodeTest(); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -180,7 +180,7 @@ template<class string_type, class string_adaptor>
|
|||
class CommentNodeTest : public NodeTest<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual NodeTest* clone() const { return new CommentNodeTest(); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new CommentNodeTest(); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -192,7 +192,7 @@ template<class string_type, class string_adaptor>
|
|||
class AttributeNodeTest : public NodeTest<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual NodeTest* clone() const { return new AttributeNodeTest(); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new AttributeNodeTest(); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -206,7 +206,7 @@ class AttributeQStarNodeTest : public AttributeNodeTest<string_type, string_adap
|
|||
typedef AttributeNodeTest<string_type, string_adaptor> baseT;
|
||||
public:
|
||||
AttributeQStarNodeTest(const string_type& namespace_uri) : baseT(), uri_(namespace_uri) { }
|
||||
virtual NodeTest* clone() const { return new AttributeQStarNodeTest(uri_); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new AttributeQStarNodeTest(uri_); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -223,7 +223,7 @@ template<class string_type, class string_adaptor>
|
|||
class NotAttributeNodeTest : public NodeTest<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual NodeTest* clone() const { return new NotAttributeNodeTest(); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new NotAttributeNodeTest(); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -237,7 +237,7 @@ class ProcessingInstructionNodeTest : public NodeTest<string_type, string_adapto
|
|||
public:
|
||||
ProcessingInstructionNodeTest() : target_() { }
|
||||
ProcessingInstructionNodeTest(const string_type& target) : target_(target) { }
|
||||
virtual NodeTest* clone() const { return new ProcessingInstructionNodeTest(target_); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new ProcessingInstructionNodeTest(target_); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
@ -258,7 +258,7 @@ template<class string_type, class string_adaptor>
|
|||
class RootNodeTest : public NodeTest<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual NodeTest* clone() const { return new RootNodeTest(); }
|
||||
virtual NodeTest<string_type, string_adaptor>* clone() const { return new RootNodeTest(); }
|
||||
|
||||
virtual bool operator()(const DOM::Node<string_type, string_adaptor>& node) const
|
||||
{
|
||||
|
|
|
@ -505,11 +505,11 @@ private:
|
|||
#include "xpath_relational.hpp"
|
||||
#include "xpath_logical.hpp"
|
||||
#include "xpath_step.hpp"
|
||||
#include "xpath_match_rewrite.hpp"
|
||||
#include "xpath_compile_context.hpp"
|
||||
#include "xpath_variable.hpp"
|
||||
#include "xpath_function_holder.hpp"
|
||||
#include "xpath_union.hpp"
|
||||
#include "xpath_match_rewrite.hpp"
|
||||
|
||||
namespace Arabica
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP
|
||||
#define ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP
|
||||
|
||||
#include <XML/strings.hpp>
|
||||
#include <text/UnicodeCharacters.hpp>
|
||||
#include "xslt_item.hpp"
|
||||
|
||||
|
@ -35,6 +36,9 @@ private:
|
|||
if(name.empty())
|
||||
throw SAX::SAXException("xsl:processing-instruction : name attribute must evaluate to a valid name");
|
||||
|
||||
if(!Arabica::XML::is_ncname(name))
|
||||
throw SAX::SAXException("xsl:processing-instruction : '" + name + "' is not valid as the name");
|
||||
|
||||
if(name.length() != 3)
|
||||
return;
|
||||
|
||||
|
|
56
tests/Utils/test_xml_strings.hpp
Executable file
56
tests/Utils/test_xml_strings.hpp
Executable file
|
@ -0,0 +1,56 @@
|
|||
#ifndef UTILS_XML_STRINGS_HPP
|
||||
#define UTILS_XML_STRINGS_HPP
|
||||
|
||||
#include <XML/strings.hpp>
|
||||
|
||||
using namespace Arabica::XML;
|
||||
|
||||
class XMLStringTest : public TestCase
|
||||
{
|
||||
public:
|
||||
XMLStringTest(std::string name) :
|
||||
TestCase(name)
|
||||
{
|
||||
} // XMLStringTest
|
||||
|
||||
void test1()
|
||||
{
|
||||
assertTrue(is_ncname("woo"));
|
||||
} // test1
|
||||
|
||||
void test2()
|
||||
{
|
||||
assertTrue(is_ncname("WOO"));
|
||||
} // test2
|
||||
|
||||
void test3()
|
||||
{
|
||||
assertFalse(is_ncname("???"));
|
||||
} // test3
|
||||
|
||||
void test4()
|
||||
{
|
||||
assertTrue("a:b");
|
||||
} // test4
|
||||
|
||||
void test5()
|
||||
{
|
||||
assertFalse(":b");
|
||||
} // test5
|
||||
|
||||
}; // class XMLStringTest
|
||||
|
||||
TestSuite* XMLStringTest_suite()
|
||||
{
|
||||
TestSuite* suiteOfTests = new TestSuite();
|
||||
|
||||
suiteOfTests->addTest(new TestCaller<XMLStringTest>("test1", &XMLStringTest::test1));
|
||||
suiteOfTests->addTest(new TestCaller<XMLStringTest>("test2", &XMLStringTest::test2));
|
||||
suiteOfTests->addTest(new TestCaller<XMLStringTest>("test3", &XMLStringTest::test3));
|
||||
suiteOfTests->addTest(new TestCaller<XMLStringTest>("test4", &XMLStringTest::test4));
|
||||
suiteOfTests->addTest(new TestCaller<XMLStringTest>("test5", &XMLStringTest::test5));
|
||||
|
||||
return suiteOfTests;
|
||||
} // XMLStringTest_suite
|
||||
|
||||
#endif
|
|
@ -8,6 +8,7 @@
|
|||
#include "test_normalize_whitespace.hpp"
|
||||
#include "test_base64.hpp"
|
||||
#include "test_uri.hpp"
|
||||
#include "test_xml_strings.hpp"
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
bool Util_test_suite(int argc, const char** argv)
|
||||
|
@ -17,6 +18,7 @@ bool Util_test_suite(int argc, const char** argv)
|
|||
runner.addTest("NormalizeWhitespaceTest", NormalizeWhitespaceTest_suite<string_type, string_adaptor >());
|
||||
runner.addTest("Base64Test", Base64Test_suite());
|
||||
runner.addTest("URITest", URITest_suite());
|
||||
runner.addTest("XMLString", XMLStringTest_suite());
|
||||
|
||||
return runner.run(argc, argv);
|
||||
} // main
|
||||
|
|
|
@ -15,11 +15,6 @@
|
|||
// #include "scope_test.hpp"
|
||||
#include "xslt_test.hpp"
|
||||
|
||||
/*
|
||||
typedef std::string string_type;
|
||||
typedef Arabica::default_string_adaptor<std::string> string_adaptor;
|
||||
*/
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
TestRunner runner;
|
||||
|
@ -27,6 +22,7 @@ int main(int argc, const char* argv[])
|
|||
// runner.addTest("ScopeTest", ScopeTest_suite<string_type, string_adaptor>());
|
||||
// Xalan supplied test cases
|
||||
|
||||
/*
|
||||
//runner.addTest("attribset", XSLTTest_suite("attribset"));
|
||||
runner.addTest("attribvaltemplate", XSLTTest_suite("attribvaltemplate"));
|
||||
runner.addTest("axes", XSLTTest_suite("axes"));
|
||||
|
@ -88,7 +84,9 @@ int main(int argc, const char* argv[])
|
|||
//runner.addTest("Namespace_XPath", XSLTTest_suite("Namespace_XPath"));
|
||||
//runner.addTest("Number", XSLTTest_suite("Number"));
|
||||
//runner.addTest("Output", XSLTTest_suite("Output"));
|
||||
*/
|
||||
runner.addTest("ProcessingInstruction", XSLTTest_suite("ProcessingInstruction"));
|
||||
/*
|
||||
//runner.addTest("RTF", XSLTTest_suite("RTF"));
|
||||
runner.addTest("Sorting", XSLTTest_suite("Sorting"));
|
||||
//runner.addTest("Stylesheet", XSLTTest_suite("Stylesheet"));
|
||||
|
@ -98,7 +96,7 @@ int main(int argc, const char* argv[])
|
|||
//runner.addTest("Variables", XSLTTest_suite("Variables"));
|
||||
//runner.addTest("Whitespaces", XSLTTest_suite("Whitespaces"));
|
||||
//runner.addTest("XSLTFunctions", XSLTTest_suite("XSLTFunctions"));
|
||||
|
||||
*/
|
||||
runner.addTest("ArabicaErrors", ArabicaTest_suite("errors"));
|
||||
runner.addTest("ArabicaInclude", ArabicaTest_suite("include"));
|
||||
runner.addTest("ArabicaProcessingInstruction", ArabicaTest_suite("processing-instruction"));
|
||||
|
|
|
@ -531,8 +531,11 @@ protected:
|
|||
class Expected
|
||||
{
|
||||
public:
|
||||
Expected()
|
||||
Expected() { }
|
||||
|
||||
void load()
|
||||
{
|
||||
std::cout << "Loaded expected fails" << std::endl;
|
||||
Arabica::DOM::Document<std::string> fail_doc = buildDOM(PATH_PREFIX + "arabica-expected-fails.xml");
|
||||
Arabica::XPath::NodeSet<std::string> failcases = selectNodes("/test-suite/test-case", fail_doc);
|
||||
for(int i = 0; i != failcases.size(); ++i)
|
||||
|
@ -579,6 +582,7 @@ Arabica::DOM::Document<std::string> loadCatalog(const std::string& catalog_filen
|
|||
c = buildDOM(PATH_PREFIX + catalog_filename);
|
||||
catalogs[catalog_filename] = c;
|
||||
std::cout << "Loaded " << catalog_filename << std::endl;
|
||||
expected.load();
|
||||
} // if(c == 0)
|
||||
|
||||
return c;
|
||||
|
|
Loading…
Reference in a new issue