From 9553149aa6b6561c49981adf2848607a43765054 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 11 Oct 2010 12:43:48 +0200 Subject: Support for validation of the pattern facet New test: hybrid/pattern. --- xsde/cxx/parser/elements.cxx | 32 +++++---- xsde/cxx/parser/parser-inline.cxx | 107 +++++++++++++++++++----------- xsde/cxx/serializer/elements.cxx | 36 ++++++---- xsde/cxx/serializer/serializer-inline.cxx | 81 ++++++++++++++-------- 4 files changed, 164 insertions(+), 92 deletions(-) (limited to 'xsde/cxx') diff --git a/xsde/cxx/parser/elements.cxx b/xsde/cxx/parser/elements.cxx index 2c138ce..25e2032 100644 --- a/xsde/cxx/parser/elements.cxx +++ b/xsde/cxx/parser/elements.cxx @@ -207,24 +207,30 @@ namespace CXX SemanticGraph::Type& ub (ultimate_base (c)); Restricts::FacetIterator end (r.facet_end ()); - if ((ub.is_a () || - ub.is_a ()) && - r.facet_find (L"whiteSpace") != end) - return true; - - if (validation) + if (ub.is_a () || + ub.is_a ()) { - if (ub.is_a () || - ub.is_a () || - ub.is_a () || - ub.is_a () || - ub.is_a () || - ub.is_a ()) + if (r.facet_find (L"whiteSpace") != end) + return true; + + if (validation) { if (r.facet_find (L"length") != end || r.facet_find (L"minLength") != end || r.facet_find (L"maxLength") != end || - r.facet_find (L"minInclusive") != end || + r.facet_find (L"pattern") != end) + return true; + } + } + + if (ub.is_a () || + ub.is_a () || + ub.is_a () || + ub.is_a ()) + { + if (validation) + { + if (r.facet_find (L"minInclusive") != end || r.facet_find (L"minExclusive") != end || r.facet_find (L"maxInclusive") != end || r.facet_find (L"maxExclusive") != end) diff --git a/xsde/cxx/parser/parser-inline.cxx b/xsde/cxx/parser/parser-inline.cxx index 984eca6..d20a3e7 100644 --- a/xsde/cxx/parser/parser-inline.cxx +++ b/xsde/cxx/parser/parser-inline.cxx @@ -17,54 +17,83 @@ namespace CXX Void facet_calls (SemanticGraph::Complex& c, Context& ctx) { + using SemanticGraph::Restricts; + std::wostream& os (ctx.os); - using SemanticGraph::Restricts; + SemanticGraph::Type& ub (ctx.ultimate_base (c)); Restricts& r (dynamic_cast (c.inherits ())); - for (Restricts::FacetIterator i (r.facet_begin ()); - i != r.facet_end (); ++i) + if (ub.is_a () || + ub.is_a ()) { - if (i->first == L"length") - { - os << "this->_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"minLength") - { - os << "this->_min_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"maxLength") - { - os << "this->_max_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"minInclusive") - { - os << "this->_min_facet (" << i->second << ", true);"; - } - else if (i->first == L"minExclusive") + for (Restricts::FacetIterator i (r.facet_begin ()); + i != r.facet_end (); ++i) { - os << "this->_min_facet (" << i->second << ", false);"; - } - else if (i->first == L"maxInclusive") - { - os << "this->_max_facet (" << i->second << ", true);"; - } - else if (i->first == L"maxExclusive") - { - os << "this->_max_facet (" << i->second << ", false);"; + if (i->first == L"whiteSpace") + { + os << "this->_whitespace_facet ("; + + if (i->second == L"preserve") + os << "0"; + else if (i->second == L"replace") + os << "1"; + else if (i->second == L"collapse") + os << "2"; + + os << ");"; + continue; + } + + if (!ctx.validation) + continue; + + if (i->first == L"length") + { + os << "this->_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"minLength") + { + os << "this->_min_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"maxLength") + { + os << "this->_max_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"pattern") + { + os << "this->_pattern_facet (" << ctx.strlit (i->second) << ");"; + } } - else if (i->first == L"whiteSpace") - { - os << "this->_whitespace_facet ("; + } - if (i->second == L"preserve") - os << "0"; - else if (i->second == L"replace") - os << "1"; - else if (i->second == L"collapse") - os << "2"; + if (ub.is_a () || + ub.is_a () || + ub.is_a () || + ub.is_a ()) + { + for (Restricts::FacetIterator i (r.facet_begin ()); + i != r.facet_end (); ++i) + { + if (!ctx.validation) + continue; - os << ");"; + if (i->first == L"minInclusive") + { + os << "this->_min_facet (" << i->second << ", true);"; + } + else if (i->first == L"minExclusive") + { + os << "this->_min_facet (" << i->second << ", false);"; + } + else if (i->first == L"maxInclusive") + { + os << "this->_max_facet (" << i->second << ", true);"; + } + else if (i->first == L"maxExclusive") + { + os << "this->_max_facet (" << i->second << ", false);"; + } } } } diff --git a/xsde/cxx/serializer/elements.cxx b/xsde/cxx/serializer/elements.cxx index 62fd32d..e598f8f 100644 --- a/xsde/cxx/serializer/elements.cxx +++ b/xsde/cxx/serializer/elements.cxx @@ -225,24 +225,34 @@ namespace CXX return false; SemanticGraph::Type& ub (ultimate_base (c)); + Restricts::FacetIterator end (r.facet_end ()); + + if (ub.is_a () || + ub.is_a ()) + { + if (validation) + { + if (r.facet_find (L"length") != end || + r.facet_find (L"minLength") != end || + r.facet_find (L"maxLength") != end || + r.facet_find (L"pattern") != end) + return true; + } + } if (ub.is_a () || ub.is_a () || ub.is_a () || - ub.is_a () || - ub.is_a () || - ub.is_a ()) + ub.is_a ()) { - Restricts::FacetIterator end (r.facet_end ()); - - if (r.facet_find (L"length") != end || - r.facet_find (L"minLength") != end || - r.facet_find (L"maxLength") != end || - r.facet_find (L"minInclusive") != end || - r.facet_find (L"minExclusive") != end || - r.facet_find (L"maxInclusive") != end || - r.facet_find (L"maxExclusive") != end) - return true; + if (validation) + { + if (r.facet_find (L"minInclusive") != end || + r.facet_find (L"minExclusive") != end || + r.facet_find (L"maxInclusive") != end || + r.facet_find (L"maxExclusive") != end) + return true; + } } } diff --git a/xsde/cxx/serializer/serializer-inline.cxx b/xsde/cxx/serializer/serializer-inline.cxx index f888e4f..4bebc9c 100644 --- a/xsde/cxx/serializer/serializer-inline.cxx +++ b/xsde/cxx/serializer/serializer-inline.cxx @@ -17,41 +17,68 @@ namespace CXX Void facet_calls (SemanticGraph::Complex& c, Context& ctx) { + using SemanticGraph::Restricts; + std::wostream& os (ctx.os); - using SemanticGraph::Restricts; + SemanticGraph::Type& ub (ctx.ultimate_base (c)); Restricts& r (dynamic_cast (c.inherits ())); - for (Restricts::FacetIterator i (r.facet_begin ()); - i != r.facet_end (); ++i) + if (ub.is_a () || + ub.is_a ()) { - if (i->first == L"length") - { - os << "this->_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"minLength") - { - os << "this->_min_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"maxLength") - { - os << "this->_max_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"minInclusive") + for (Restricts::FacetIterator i (r.facet_begin ()); + i != r.facet_end (); ++i) { - os << "this->_min_facet (" << i->second << ", true);"; - } - else if (i->first == L"minExclusive") - { - os << "this->_min_facet (" << i->second << ", false);"; - } - else if (i->first == L"maxInclusive") - { - os << "this->_max_facet (" << i->second << ", true);"; + if (!ctx.validation) + continue; + + if (i->first == L"length") + { + os << "this->_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"minLength") + { + os << "this->_min_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"maxLength") + { + os << "this->_max_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"pattern") + { + os << "this->_pattern_facet (" << ctx.strlit (i->second) << ");"; + } } - else if (i->first == L"maxExclusive") + } + + if (ub.is_a () || + ub.is_a () || + ub.is_a () || + ub.is_a ()) + { + for (Restricts::FacetIterator i (r.facet_begin ()); + i != r.facet_end (); ++i) { - os << "this->_max_facet (" << i->second << ", false);"; + if (!ctx.validation) + continue; + + if (i->first == L"minInclusive") + { + os << "this->_min_facet (" << i->second << ", true);"; + } + else if (i->first == L"minExclusive") + { + os << "this->_min_facet (" << i->second << ", false);"; + } + else if (i->first == L"maxInclusive") + { + os << "this->_max_facet (" << i->second << ", true);"; + } + else if (i->first == L"maxExclusive") + { + os << "this->_max_facet (" << i->second << ", false);"; + } } } } -- cgit v1.1