diff options
Diffstat (limited to 'libxsde/xsde/cxx/parser')
280 files changed, 27436 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/parser/context.cxx b/libxsde/xsde/cxx/parser/context.cxx new file mode 100644 index 0000000..264ffd5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/context.cxx @@ -0,0 +1,18 @@ +// file : xsde/cxx/parser/context.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/context.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + } + } +} diff --git a/libxsde/xsde/cxx/parser/context.hxx b/libxsde/xsde/cxx/parser/context.hxx new file mode 100644 index 0000000..2b79be9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/context.hxx @@ -0,0 +1,139 @@ +// file : xsde/cxx/parser/context.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_CONTEXT_HXX +#define XSDE_CXX_PARSER_CONTEXT_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/c/expat/expat.h> + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/sys-error.hxx> +#endif + +#ifdef XSDE_PARSER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace parser + { + struct parser_base; + + struct parser_state + { + parser_state (); + + // Depth is maintained only when we don't have a parser for a + // document fragment or if we are handling a wildcard in which + // case the any flag should be set. + // + parser_base* parser_; + size_t depth_; + bool any_; + }; + + class context + { + public: + context (XML_Parser xml_parser); + + public: + XML_Parser + xml_parser (); + + // Error handling via codes. + // + public: + + // Application error. + // +#ifndef XSDE_EXCEPTIONS + public: + int + app_error () const; + + void + app_error (int); +#endif + + // Schema error. + // +#ifdef XSDE_PARSER_VALIDATION + public: + typedef cxx::schema_error::value schema_error_t; + + schema_error_t + schema_error () const; + + void + schema_error (schema_error_t); +#endif + + // System error. + // +#ifndef XSDE_EXCEPTIONS + public: + typedef cxx::sys_error::value sys_error_t; + + sys_error_t + sys_error () const; + + void + sys_error (sys_error_t); +#endif + + // Implementation details. + // +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + public: + enum error_type_t + { + error_none = 0, + error_app, + error_schema, + error_sys + }; + + error_type_t + error_type () const; + + protected: + error_type_t error_type_; + + union + { +#ifndef XSDE_EXCEPTIONS + int app; +#endif +#ifdef XSDE_PARSER_VALIDATION + schema_error_t schema; +#endif +#ifndef XSDE_EXCEPTIONS + sys_error_t sys; +#endif + } error_code_; + +#endif // XSDE_PARSER_VALIDATION || !XSDE_EXCEPTIONS + + public: + parser_state current_; + + protected: + XML_Parser xml_parser_; + }; + } + } +} + +#include <xsde/cxx/parser/context.ixx> + +#endif // XSDE_CXX_PARSER_CONTEXT_HXX diff --git a/libxsde/xsde/cxx/parser/context.ixx b/libxsde/xsde/cxx/parser/context.ixx new file mode 100644 index 0000000..00093d6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/context.ixx @@ -0,0 +1,91 @@ +// file : xsde/cxx/parser/context.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // parser_state + // + inline parser_state:: + parser_state () + : parser_ (0), depth_ (0), any_ (false) + { + } + + // context + // + inline context:: + context (XML_Parser xml_parser) + : xml_parser_ (xml_parser) + { +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + error_type_ = error_none; +#endif + } + + inline XML_Parser context:: + xml_parser () + { + return xml_parser_; + } + + // + // +#ifndef XSDE_EXCEPTIONS + inline int context:: + app_error () const + { + return error_code_.app; + } + + inline void context:: + app_error (int e) + { + error_type_ = error_app; + error_code_.app = e; + } + + inline void context:: + sys_error (sys_error_t e) + { + error_type_ = error_sys; + error_code_.sys = e; + } + + inline context::sys_error_t context:: + sys_error () const + { + return error_code_.sys; + } +#endif + +#ifdef XSDE_PARSER_VALIDATION + inline context::schema_error_t context:: + schema_error () const + { + return error_code_.schema; + } + + inline void context:: + schema_error (schema_error_t e) + { + error_type_ = error_schema; + error_code_.schema = e; + } +#endif + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + inline context::error_type_t context:: + error_type () const + { + return error_type_; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/parser/elements.cxx b/libxsde/xsde/cxx/parser/elements.cxx new file mode 100644 index 0000000..4273ab8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/elements.cxx @@ -0,0 +1,201 @@ +// file : xsde/cxx/parser/elements.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <assert.h> + +#include <xsde/cxx/parser/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // parser_base + // + parser_base:: + ~parser_base () + { + } + + void parser_base:: + pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->pre (); +#endif + } + + void parser_base:: + _pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_pre (); +#endif + } + + void parser_base:: + _post () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_post (); +#endif + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + +#ifdef XSDE_POLYMORPHIC + void parser_base:: + _start_any_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (impl_) + impl_->_start_any_element (ns, name, type); + } +#else + void parser_base:: + _start_any_element (const ro_string& ns, + const ro_string& name) + { + if (impl_) + impl_->_start_any_element (ns, name); + } +#endif + + void parser_base:: + _end_any_element (const ro_string& ns, + const ro_string& name) + { + if (impl_) + impl_->_end_any_element (ns, name); + } + + void parser_base:: + _any_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + if (impl_) + impl_->_any_attribute (ns, name, value); + } + + void parser_base:: + _any_characters (const ro_string& s) + { + if (impl_) + impl_->_any_characters (s); + } +#else // !XSDE_REUSE_STYLE_TIEIN + +#ifdef XSDE_POLYMORPHIC + void parser_base:: + _start_any_element (const ro_string&, + const ro_string&, + const char*) + { + } +#else + void parser_base:: + _start_any_element (const ro_string&, + const ro_string&) + { + } +#endif + + void parser_base:: + _end_any_element (const ro_string&, + const ro_string&) + { + } + + void parser_base:: + _any_attribute (const ro_string&, + const ro_string&, + const ro_string&) + { + } + + void parser_base:: + _any_characters (const ro_string&) + { + } +#endif // XSDE_REUSE_STYLE_TIEIN + + + void parser_base:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + context_ = &c; + + previous_ = c.current_; + + c.current_.parser_ = this; + c.current_.depth_ = 0; + c.current_.any_ = false; + + _pre (); + } + + void parser_base:: + _post_impl () + { +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (!context_->error_type ()) +#endif + _post (); + + context_->current_ = previous_; + context_ = 0; + } + +#ifdef XSDE_POLYMORPHIC + const char* parser_base:: + _dynamic_type () const + { + return 0; + } +#endif + + void parser_base:: + _reset () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_reset (); +#endif + +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif + context_ = 0; + + previous_.parser_ = 0; + previous_.depth_ = 0; + previous_.any_ = false; + } + +#if defined (XSDE_REUSE_STYLE_TIEIN) && !defined (XSDE_EXCEPTIONS) + const parser_base* parser_base:: + _ultimate_impl () const + { + const parser_base* p = impl_; + for (; p->impl_ != 0; p = p->impl_) /*noop*/; + return p; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/parser/elements.hxx b/libxsde/xsde/cxx/parser/elements.hxx new file mode 100644 index 0000000..5ce1e09 --- /dev/null +++ b/libxsde/xsde/cxx/parser/elements.hxx @@ -0,0 +1,248 @@ +// file : xsde/cxx/parser/elements.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_ELEMENTS_HXX +#define XSDE_CXX_PARSER_ELEMENTS_HXX + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> + +#ifdef XSDE_PARSER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/sys-error.hxx> +# include <xsde/cxx/parser/error.hxx> +#endif + +#include <xsde/cxx/parser/context.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // pre() and post() are overridable pre/post callbacks, i.e., the + // derived parser can override them without calling the base version. + // _pre() and _post() are not overridable pre/post callbacks in the + // sense that the derived parser may override them but has to call + // the base version. The call sequence is as shown below: + // + // pre () + // _pre () + // _post () + // post () + // + struct parser_base + { + virtual + ~parser_base (); + + parser_base (); + +#ifdef XSDE_REUSE_STYLE_TIEIN + parser_base (parser_base* impl, void*); +#endif + + public: + virtual void + pre (); + + virtual void + _pre (); + + // The type argument is a type name and namespace from the + // xsi:type attribute in the form "<name> <namespace>" with + // the space and namespace part absent if the type does not + // have a namespace or 0 if xsi:type is not present. + // +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) = 0; +#else + virtual void + _start_element (const ro_string& ns, + const ro_string& name) = 0; +#endif + + virtual void + _end_element (const ro_string& ns, + const ro_string& name) = 0; + + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) = 0; + + virtual void + _characters (const ro_string&) = 0; + + virtual void + _post (); + + // The post() signature varies depending on the parser return + // type. + // + + public: + // The following functions are called when wildcard content is + // encountered. Override them to handle mixed content models, + // any/anyAttribute, and anyType/anySimpleType. By default + // these functions do nothing. + // +#ifdef XSDE_POLYMORPHIC + virtual void + _start_any_element (const ro_string& ns, + const ro_string& name, + const char* type); +#else + virtual void + _start_any_element (const ro_string& ns, + const ro_string& name); +#endif + + virtual void + _end_any_element (const ro_string& ns, + const ro_string& name); + + virtual void + _any_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _any_characters (const ro_string&); + + public: + // Implementation callbacks for _pre and _post. The _pre and _post + // callbacks should never be called directly. Instead, the *_impl + // versions should be used. By default _pre_impl and _post_impl + // simply call _pre and _post respectively. + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + +#ifdef XSDE_POLYMORPHIC + public: + // Dynamic type in the form "<name> <namespace>" with + // the space and namespace part absent if the type does + // not have a namespace. + // + virtual const char* + _dynamic_type () const; +#endif + + public: + context& + _context (); + + // Reset the parser state after an error. + // + virtual void + _reset (); + + // Error handling via codes. If the error is set while parser + // is in the context, the error is set in the context, instead + // of the parser. Since pre() and post() calls are not in + // context, the parser stores application and system errors + // locally for this case. + // + +#ifndef XSDE_EXCEPTIONS + public: + error + _error () const; + + // Set application error. + // + void + _app_error (int); + + int + _app_error () const; +#endif + + // Schema error. + // +#ifdef XSDE_PARSER_VALIDATION + public: + void + _schema_error (context::schema_error_t); +#endif + + // System error. + // +#ifndef XSDE_EXCEPTIONS + public: + context::sys_error_t + _sys_error () const; + + void + _sys_error (context::sys_error_t); +#endif + + // Implementation. + // + +#ifndef XSDE_EXCEPTIONS + public: + enum error_type_t + { + error_none = 0, + error_app, + error_sys + }; + + error_type_t + _error_type () const; + + void + _copy_error (context&) const; + + private: + error_type_t error_type_; + + union + { + int app; + context::sys_error_t sys; + } error_code_; +#endif + + protected: + bool resetting_; + context* context_; + +#ifdef XSDE_REUSE_STYLE_TIEIN + protected: + parser_base* parent_; + parser_base* impl_; + + void + _set_parent_chain (); + +#ifndef XSDE_EXCEPTIONS + const parser_base* + _ultimate_impl () const; +#endif +#endif + + protected: + parser_state previous_; + }; + } + } +} + +#include <xsde/cxx/parser/elements.ixx> + +#endif // XSDE_CXX_PARSER_ELEMENTS_HXX diff --git a/libxsde/xsde/cxx/parser/elements.ixx b/libxsde/xsde/cxx/parser/elements.ixx new file mode 100644 index 0000000..ef47209 --- /dev/null +++ b/libxsde/xsde/cxx/parser/elements.ixx @@ -0,0 +1,221 @@ +// file : xsde/cxx/parser/elements.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + inline parser_base:: + parser_base () + : resetting_ (false), context_ (0) + { +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + parent_ = 0; + impl_ = 0; +#endif + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline parser_base:: + parser_base (parser_base* impl, void*) + : resetting_ (false), context_ (0) + { +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif + parent_ = 0; + impl_ = impl; + } +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline void parser_base:: + _set_parent_chain () + { + if (impl_ && impl_->parent_ == 0) + { + for (parser_base* p = impl_; p != 0; p = p->impl_) + p->parent_ = this; + } + } +#endif + + inline context& parser_base:: + _context () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + return *(parent_ ? parent_->context_ : context_); +#else + return *context_; +#endif + } + + // Error handling. + // +#ifndef XSDE_EXCEPTIONS + inline error parser_base:: + _error () const + { + // Unlike context, which is stored in the top-level + // parser, error state is stored in the "bottom-level" + // implementation. It is done this way since the error + // handling mechanism can be used in constructors which + // would otherwise require passing the pointer to parent + // parser to each implementation's c-tor. + // +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + switch (p->error_type_) + { + case error_sys: + { + return error (p->error_code_.sys); + } + case error_app: + { + return error (p->error_code_.app, 0, 0); + } + default: + { + return error (); + } + } + } + + inline void parser_base:: + _app_error (int e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + parser_base* p = parent_ ? parent_ : this; +#else + parser_base* p = this; +#endif + + if (p->context_ != 0) + { + p->context_->app_error (e); + } + else + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (!impl_) + p = this; + else + for (p = impl_; p->impl_ != 0; p = p->impl_) /*noop*/ ; +#endif + p->error_type_ = error_app; + p->error_code_.app = e; + } + } + + inline int parser_base:: + _app_error () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + return p->error_code_.app; + } + + inline void parser_base:: + _sys_error (context::sys_error_t e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + parser_base* p = parent_ ? parent_ : this; +#else + parser_base* p = this; +#endif + if (p->context_ != 0) + { + p->context_->sys_error (e); + } + else + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (!impl_) + p = this; + else + for (p = impl_; p->impl_ != 0; p = p->impl_) /*noop*/; +#endif + p->error_type_ = error_sys; + p->error_code_.sys = e; + } + } + + inline context::sys_error_t parser_base:: + _sys_error () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + return p->error_code_.sys; + } + + inline parser_base::error_type_t parser_base:: + _error_type () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + return p->error_type_; + } + + inline void parser_base:: + _copy_error (context& ctx) const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + + switch (p->error_type_) + { + case error_app: + { + ctx.app_error (p->error_code_.app); + break; + } + case error_sys: + { + ctx.sys_error (p->error_code_.sys); + break; + } + default: + break; + } + } +#endif // XSDE_EXCEPTIONS + +#ifdef XSDE_PARSER_VALIDATION + inline void parser_base:: + _schema_error (context::schema_error_t e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + parser_base* p = parent_ ? parent_ : this; +#else + parser_base* p = this; +#endif + p->context_->schema_error (e); + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/parser/error.cxx b/libxsde/xsde/cxx/parser/error.cxx new file mode 100644 index 0000000..94e2534 --- /dev/null +++ b/libxsde/xsde/cxx/parser/error.cxx @@ -0,0 +1,20 @@ +// file : xsde/cxx/parser/error.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + void error:: + true_ () + { + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/error.hxx b/libxsde/xsde/cxx/parser/error.hxx new file mode 100644 index 0000000..47ca489 --- /dev/null +++ b/libxsde/xsde/cxx/parser/error.hxx @@ -0,0 +1,135 @@ +// file : xsde/cxx/parser/error.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_ERROR_HXX +#define XSDE_CXX_PARSER_ERROR_HXX + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/sys-error.hxx> + +#include <xsde/cxx/parser/expat/xml-error.hxx> + +#ifdef XSDE_PARSER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace parser + { + using expat::xml_error; + + // This type is only used when C++ exceptions are not used. + // + struct error + { + enum error_type + { + none, + sys, + xml, + schema, + app + }; + + public: + error_type + type () const; + + + // Line and column are only available for xml, schema, and + // app errors. + // + unsigned long + line () const; + + unsigned long + column () const; + + + // Returns true if there is an error so that you can write + // if (p.error ()) or if (error e = p.error ()). + // + typedef void (error::*bool_convertible) (); + operator bool_convertible () const; + + + // sys + // + public: + error (sys_error); + + sys_error + sys_code () const; + + const char* + sys_text () const; + + + // xml + // + public: + error (xml_error, unsigned long line, unsigned long column); + + xml_error + xml_code () const; + + const char* + xml_text () const; + + + // schema + // +#ifdef XSDE_PARSER_VALIDATION + public: + error (schema_error::value, unsigned long line, unsigned long column); + + schema_error + schema_code () const; + + const char* + schema_text () const; +#endif + + // app + // + public: + error (int app_code, unsigned long line, unsigned long column); + + int + app_code () const; + + + public: + error (); + + private: + void + true_ (); + + private: + error_type type_; + unsigned long line_; + unsigned long column_; + + union + { + sys_error::value sys; + xml_error xml; +#ifdef XSDE_PARSER_VALIDATION + schema_error::value schema; +#endif + int app; + } code_; + }; + } + } +} + +#include <xsde/cxx/parser/error.ixx> + +#endif // XSDE_CXX_PARSER_ERROR_HXX diff --git a/libxsde/xsde/cxx/parser/error.ixx b/libxsde/xsde/cxx/parser/error.ixx new file mode 100644 index 0000000..dbb57bb --- /dev/null +++ b/libxsde/xsde/cxx/parser/error.ixx @@ -0,0 +1,143 @@ +// file : xsde/cxx/parser/error.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + inline + error::error_type error:: + type () const + { + return type_; + } + + inline + unsigned long error:: + line () const + { + return line_; + } + + inline + unsigned long error:: + column () const + { + return column_; + } + + inline + error:: + operator error::bool_convertible () const + { + return type_ != none ? &error::true_ : 0; + } + + // sys + // + + inline + error:: + error (sys_error e) + : type_ (sys), line_ (0), column_ (0) + { + code_.sys = e; + } + + inline + sys_error error:: + sys_code () const + { + return code_.sys; + } + + inline + const char* error:: + sys_text () const + { + return sys_error::text (code_.sys); + } + + // xml + // + + inline + error:: + error (xml_error e, unsigned long l, unsigned long c) + : type_ (xml), line_ (l), column_ (c) + { + code_.xml = e; + } + + inline + xml_error error:: + xml_code () const + { + return code_.xml; + } + + inline + const char* error:: + xml_text () const + { + return expat::xml_error_text (code_.xml); + } + + // schema + // + +#ifdef XSDE_PARSER_VALIDATION + inline + error:: + error (schema_error::value e, unsigned long l, unsigned long c) + : type_ (schema), line_ (l), column_ (c) + { + code_.schema = e; + } + + inline + schema_error error:: + schema_code () const + { + return code_.schema; + } + + inline + const char* error:: + schema_text () const + { + return schema_error::text (code_.schema); + } +#endif + + // app + // + + inline + error:: + error (int e, unsigned long l, unsigned long c) + : type_ (app), line_ (l), column_ (c) + { + code_.app = e; + } + + inline + int error:: + app_code () const + { + return code_.app; + } + + inline + error:: + error () + : type_ (none) + { + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/exceptions.cxx b/libxsde/xsde/cxx/parser/exceptions.cxx new file mode 100644 index 0000000..0046266 --- /dev/null +++ b/libxsde/xsde/cxx/parser/exceptions.cxx @@ -0,0 +1,64 @@ +// file : xsde/cxx/parser/exceptions.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_IOSTREAM +# include <iostream> +#endif + +#include <xsde/cxx/parser/exceptions.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // exception + // + +#ifdef XSDE_IOSTREAM + std::ostream& + operator<< (std::ostream& os, const exception& e) + { + return os << e.text (); + } +#endif + + + // xml + // + const char* xml:: + text () const + { + return expat::xml_error_text (code_); + } + + const char* xml:: + what () const throw () + { + return "xml error"; + } + + + // schema + // +#ifdef XSDE_PARSER_VALIDATION + const char* schema:: + text () const + { + return schema_error::text (code_); + } + + const char* schema:: + what () const throw () + { + return "schema error"; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/parser/exceptions.hxx b/libxsde/xsde/cxx/parser/exceptions.hxx new file mode 100644 index 0000000..d02eeb3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/exceptions.hxx @@ -0,0 +1,103 @@ +// file : xsde/cxx/parser/exceptions.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_EXCEPTIONS_HXX +#define XSDE_CXX_PARSER_EXCEPTIONS_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_IOSTREAM +# include <iosfwd> +#endif + +#include <xsde/cxx/exceptions.hxx> // xsde::cxx::exception + +#ifdef XSDE_PARSER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +#include <xsde/cxx/parser/expat/xml-error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // exception + // + struct exception: xsde::cxx::exception + { + exception (unsigned long line, unsigned long column); + + unsigned long + line () const; + + unsigned long + column () const; + + virtual const char* + text () const = 0; + + private: + unsigned long line_; + unsigned long column_; + }; + +#ifdef XSDE_IOSTREAM + std::ostream& + operator<< (std::ostream&, const exception&); +#endif + + + // xml + // + using expat::xml_error; + + struct xml: exception + { + xml (xml_error, unsigned long line, unsigned long column); + + xml_error + code () const; + + virtual const char* + text () const; + + virtual const char* + what () const throw (); + + private: + xml_error code_; + }; + + + // schema + // +#ifdef XSDE_PARSER_VALIDATION + struct schema: exception + { + schema (schema_error, unsigned long line, unsigned long column); + + schema_error + code () const; + + virtual const char* + text () const; + + virtual const char* + what () const throw (); + + private: + schema_error code_; + }; +#endif + } + } +} + +#include <xsde/cxx/parser/exceptions.ixx> + +#endif // XSDE_CXX_PARSER_EXCEPTIONS_HXX diff --git a/libxsde/xsde/cxx/parser/exceptions.ixx b/libxsde/xsde/cxx/parser/exceptions.ixx new file mode 100644 index 0000000..77ca9e5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/exceptions.ixx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/exceptions.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // exception + // + inline exception:: + exception (unsigned long line, unsigned long column) + : line_ (line), column_ (column) + { + } + + inline unsigned long exception:: + line () const + { + return line_; + } + + inline unsigned long exception:: + column () const + { + return column_; + } + + + // xml + // + inline xml:: + xml (xml_error code, unsigned long line, unsigned long column) + : exception (line, column), code_ (code) + { + } + + inline xml_error xml:: + code () const + { + return code_; + } + + + // schema + // +#ifdef XSDE_PARSER_VALIDATION + inline schema:: + schema (schema_error code, unsigned long line, unsigned long column) + : exception (line, column), code_ (code) + { + } + + inline schema_error schema:: + code () const + { + return code_; + } +#endif + } + } +} + diff --git a/libxsde/xsde/cxx/parser/expat/document.cxx b/libxsde/xsde/cxx/parser/expat/document.cxx new file mode 100644 index 0000000..0e30a2a --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/document.cxx @@ -0,0 +1,1044 @@ +// file : xsde/cxx/parser/expat/document.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <assert.h> +#include <string.h> // strchr, strlen + +#ifdef XSDE_EXCEPTIONS +# include <new> // std::bad_alloc +#endif + +#ifdef XSDE_IOSTREAM +# include <iostream> +# include <fstream> +#endif + +#ifdef XSDE_EXCEPTIONS +# include <xsde/cxx/parser/exceptions.hxx> +#endif + +#ifdef XSDE_POLYMORPHIC +# include <xsde/cxx/parser/substitution-map.hxx> +#endif + +#include <xsde/cxx/parser/expat/document.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { +#ifdef XSDE_POLYMORPHIC + static substitution_map_init substitution_map_init_; +#endif + + // document_pimpl + // + + document_pimpl:: + ~document_pimpl () + { + // Prevents auto-generation of this dtor. + } + +#ifdef XSDE_STL + + document_pimpl:: +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base& p, const std::string& n, bool poly) +#else + document_pimpl (parser_base& p, const std::string& n) +#endif + : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = poly; +#endif + init_root_name (0, n.c_str ()); + } + + document_pimpl:: +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base& p, + const std::string& ns, + const std::string& n, + bool poly) +#else + document_pimpl (parser_base& p, + const std::string& ns, + const std::string& n) +#endif + : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = poly; +#endif + init_root_name (ns.c_str (), n.c_str ()); + } + +#endif // XSDE_STL + + document_pimpl:: +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base& p, const char* n, bool poly) +#else + document_pimpl (parser_base& p, const char* n) +#endif + : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = poly; +#endif + init_root_name (0, n); + } + + document_pimpl:: +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base& p, + const char* ns, + const char* n, + bool poly) +#else + document_pimpl (parser_base& p, const char* ns, const char* n) +#endif + : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = poly; +#endif + init_root_name (ns, n); + } + + document_pimpl:: + document_pimpl () + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = false; +#endif + } + +#ifdef XSDE_POLYMORPHIC + document_pimpl:: + document_pimpl (const char* n) + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + polymorphic_ (true) + { + init_root_name (0, n); + } + + document_pimpl:: + document_pimpl (const char* ns, const char* n) + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + polymorphic_ (true) + { + init_root_name (ns, n); + } + +#ifdef XSDE_STL + document_pimpl:: + document_pimpl (const std::string& n) + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + polymorphic_ (true) + { + init_root_name (0, n.c_str ()); + } + + document_pimpl:: + document_pimpl (const std::string& ns, const std::string& n) + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + polymorphic_ (true) + { + init_root_name (ns.c_str (), n.c_str ()); + } +#endif // XSDE_STL +#endif // XSDE_POLYMORPHIC + + void document_pimpl:: + init_root_name (const char* ns, const char* name) + { +#ifdef XSDE_EXCEPTIONS + root_ns_.assign (ns ? ns : ""); + root_name_.assign (name); +#else + if (root_ns_.assign (ns ? ns : "") || root_name_.assign (name)) + error_ = error (sys_error::no_memory); +#endif + } + + // + // + parser_base* document_pimpl:: +#ifdef XSDE_POLYMORPHIC + start_root_element (const ro_string& ns, + const ro_string& name, + const char*) +#else + start_root_element (const ro_string& ns, const ro_string& name) +#endif + { + if (root_name_ == name && root_ns_ == ns) + { + return parser_; + } + else + { +#ifdef XSDE_PARSER_VALIDATION + context_.schema_error (schema_error::unexpected_element); +#endif + return 0; + } + } + + void document_pimpl:: + end_root_element (const ro_string&, const ro_string&, parser_base*) + { + } + + void document_pimpl:: + reset () + { +#ifndef XSDE_EXCEPTIONS + error_ = error (); +#endif + first_ = true; + + if (parser_) + parser_->_reset (); + } + + // file + // + +#ifdef XSDE_IOSTREAM + void document_pimpl:: + parse (const char* file) + { + std::ifstream ifs; + +#ifdef XSDE_EXCEPTIONS + ifs.exceptions (std::ifstream::badbit | std::ifstream::failbit); +#endif + + ifs.open (file, std::ifstream::in | std::ifstream::binary); + +#ifndef XSDE_EXCEPTIONS + if (ifs.fail ()) + { + error_ = error (sys_error::open_failed); + return; + } +#endif + parse (ifs); + } + +#ifdef XSDE_STL + void document_pimpl:: + parse (const std::string& file) + { + parse (file.c_str ()); + } +#endif + + // istream + // + +#ifdef XSDE_EXCEPTIONS + namespace bits + { + struct stream_exception_controller + { + ~stream_exception_controller () + { + std::istream::iostate s = is_.rdstate (); + s &= ~std::istream::failbit; + + // If our error state (sans failbit) intersects with the + // exception state then that means we have an active + // exception and changing error/exception state will + // cause another to be thrown. + // + if (!(old_state_ & s)) + { + // Clear failbit if it was caused by eof. + // + if (is_.fail () && is_.eof ()) + is_.clear (s); + + is_.exceptions (old_state_); + } + } + + stream_exception_controller (std::istream& is) + : is_ (is), old_state_ (is_.exceptions ()) + { + is_.exceptions (old_state_ & ~std::istream::failbit); + } + + private: + stream_exception_controller (const stream_exception_controller&); + + stream_exception_controller& + operator= (const stream_exception_controller&); + + private: + std::istream& is_; + std::istream::iostate old_state_; + }; + } +#endif + + void document_pimpl:: + parse (std::istream& is) + { +#ifdef XSDE_EXCEPTIONS + // Temporarily unset the exception failbit. Also clear the + // fail bit when we reset the old state if it was caused + // by eof. + // + bits::stream_exception_controller sec (is); +#endif + + char buf[4096]; // Page size. + + do + { + is.read (buf, sizeof (buf)); + +#ifndef XSDE_EXCEPTIONS + if (is.bad () || (is.fail () && !is.eof ())) + { + error_ = error (sys_error::read_failed); + break; + } +#endif + parse (buf, is.gcount (), is.eof ()); + +#ifndef XSDE_EXCEPTIONS + if (error_) + break; +#endif + } while (!is.eof ()); + } +#endif // XSDE_IOSTREAM + + + void document_pimpl:: + parse (const void* data, size_t size, bool last) + { + // First call. + // + if (first_) + { + if (auto_xml_parser_ == 0) + { + auto_xml_parser_ = XML_ParserCreateNS (0, XML_Char (' ')); + + if (auto_xml_parser_ == 0) + { +#ifdef XSDE_EXCEPTIONS + throw std::bad_alloc (); +#else + error_ = error (sys_error::no_memory); + return; +#endif + } + } + else + XML_ParserReset (auto_xml_parser_, 0); + + parse_begin (auto_xml_parser_); + first_ = false; + } + + + if (XML_Parse (xml_parser_, + static_cast<const char*> (data), + static_cast<int> (size), + last) == XML_STATUS_ERROR || + last) + { + first_ = true; + parse_end (); + } + } + + + // XML_Parser + // + + void document_pimpl:: + parse_begin (XML_Parser parser) + { + context_ = context (parser); + + xml_parser_ = parser; + set (); + } + + void document_pimpl:: + parse_end () + { + XML_Error e (XML_GetErrorCode (xml_parser_)); + + if (e == XML_ERROR_NONE) + { + clear (); + xml_parser_ = 0; + } + else + { + unsigned long l = XML_GetCurrentLineNumber (xml_parser_); + unsigned long c = XML_GetCurrentColumnNumber (xml_parser_); + + clear (); + xml_parser_ = 0; + + // See if the parser was aborted. + // + if (e == XML_ERROR_ABORTED) + { + // Got to be either a system, schema, or application + // level error. + // +#if defined(XSDE_PARSER_VALIDATION) || !defined (XSDE_EXCEPTIONS) + switch (context_.error_type ()) + { +#ifndef XSDE_EXCEPTIONS + case context::error_sys: + { + error_ = error (context_.sys_error ()); + break; + } +#endif +#ifdef XSDE_PARSER_VALIDATION + case context::error_schema: + { +#ifdef XSDE_EXCEPTIONS + throw schema (context_.schema_error (), l, c); +#else + error_ = error (context_.schema_error (), l, c); + break; +#endif + } +#endif +#ifndef XSDE_EXCEPTIONS + case context::error_app: + { + error_ = error (context_.app_error (), l, c); + break; + } +#endif + default: + { + // Someone aborted the parser without setting an + // error. Oh well, let them sort this one out. + // + break; + } + } +#endif // XSDE_PARSER_VALIDATION || !XSDE_EXCEPTIONS + } + else if (e == XML_ERROR_NO_MEMORY) + { +#ifdef XSDE_EXCEPTIONS + throw std::bad_alloc (); +#else + error_ = error (sys_error::no_memory); +#endif + } + else + { +#ifdef XSDE_EXCEPTIONS + throw xml (e, l, c); +#else + error_ = error (e, l, c); +#endif + } + } + } + + + // + // + void document_pimpl:: + set () + { + assert (xml_parser_ != 0); + + XML_SetUserData(xml_parser_, this); + XML_SetStartElementHandler (xml_parser_, &start_element); + XML_SetEndElementHandler (xml_parser_, &end_element); + XML_SetCharacterDataHandler (xml_parser_, &characters); + +#ifdef XSDE_POLYMORPHIC + if (polymorphic_) + XML_SetNamespaceDeclHandler ( + xml_parser_, &start_namespace_decl, &end_namespace_decl); +#endif + } + + void document_pimpl:: + clear () + { + assert (xml_parser_ != 0); + + XML_SetUserData (xml_parser_, 0); + XML_SetStartElementHandler (xml_parser_, 0); + XML_SetEndElementHandler (xml_parser_, 0); + XML_SetCharacterDataHandler (xml_parser_, 0); + +#ifdef XSDE_POLYMORPHIC + if (polymorphic_) + XML_SetNamespaceDeclHandler (xml_parser_, 0, 0); +#endif + } + + + // Expat thunks. + // + + void XMLCALL document_pimpl:: + start_element (void* p, const XML_Char* name, const XML_Char** ats) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.start_element_ (name, ats); + } + + void XMLCALL document_pimpl:: + end_element (void* p, const XML_Char* name) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.end_element_ (name); + } + + void XMLCALL document_pimpl:: + characters (void* p, const XML_Char* s, int n) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.characters_ (s, static_cast<size_t> (n)); + } + +#ifdef XSDE_POLYMORPHIC + void XMLCALL document_pimpl:: + start_namespace_decl (void* p, + const XML_Char* prefix, + const XML_Char* ns) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.start_namespace_decl_ (prefix, ns); + } + + void XMLCALL document_pimpl:: + end_namespace_decl (void* p, const XML_Char* prefix) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.end_namespace_decl_ (prefix); + } +#endif // XSDE_POLYMORPHIC + + namespace bits + { + inline void + split_name (const XML_Char* s, + const char*& ns, size_t& ns_s, + const char*& name, size_t& name_s) + { + const char* p = strchr (s, ' '); + + if (p) + { + ns = s; + ns_s = p - s; + name = p + 1; + } + else + { + ns = s; + ns_s = 0; + name = s; + } + + name_s = strlen (name); + } + } + + void document_pimpl:: + start_element_ (const XML_Char* ns_name, const XML_Char** atts) + { + // Current Expat (2.0.0) has a (mis)-feature of a possibility of + // calling callbacks even after the non-resumable XML_StopParser + // call. The following code accounts for this. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + const char* ns_p; + const char* name_p; + size_t ns_s, name_s; + + bits::split_name (ns_name, ns_p, ns_s, name_p, name_s); + + parser_state& cur = context_.current_; + + { + const ro_string ns (ns_p, ns_s); + const ro_string name (name_p, name_s); + +#ifdef XSDE_POLYMORPHIC + const char* type = 0; + string type_holder; + + if (polymorphic_) + { + // Search for the xsi:type attribute. + // + const XML_Char** p = atts; // VC8 can't handle p (atts) + for (; *p != 0; p += 2) + { + bits::split_name (*p, ns_p, ns_s, name_p, name_s); + const ro_string ns (ns_p, ns_s), name (name_p, name_s); + + if (name.compare ("type", 4) == 0 && + ns.compare ( + "http://www.w3.org/2001/XMLSchema-instance", 41) == 0) + break; + } + + if (*p != 0) + { + bool valid = true; + + // @@ Need proper QName validation. + // + // Get the qualified type name and try to resolve it. + // + ro_string qn (*(p + 1)); + + ro_string tp, tn; + size_t pos = qn.find (':'); + + if (pos != ro_string::npos) + { + tp.assign (qn.data (), pos); + tn.assign (qn.data () + pos + 1); + + if (tp.empty ()) + { +#ifdef XSDE_PARSER_VALIDATION + context_.schema_error (schema_error::invalid_xsi_type); +#endif + valid = false; + } + } + else + tn.assign (qn.data (), qn.size ()); + + if (valid && tn.empty ()) + { +#ifdef XSDE_PARSER_VALIDATION + context_.schema_error (schema_error::invalid_xsi_type); +#endif + valid = false; + } + + if (valid) + { + // Search our namespace declaration stack. Note that + // we need to do this even if prefix is empty. + // + const char* tns = 0; + + for (size_t i = 0; i < prefixes_.size (); ++i) + { + if (tp == prefixes_[i]) + { +#ifdef XSDE_STL + tns = prefix_namespaces_[i].c_str (); +#else + tns = prefix_namespaces_[i]; +#endif + break; + } + } + + if (!tp.empty () && tns == 0) + { + // The 'xml' prefix requires special handling. + // + if (tp.compare ("xml", 3) == 0) + tns = "http://www.w3.org/XML/1998/namespace"; + else + { +#ifdef XSDE_PARSER_VALIDATION + context_.schema_error (schema_error::invalid_xsi_type); +#endif + valid = false; + } + } + + // Construct the compound name. + // + if (valid) + { + if (tns) + { +#ifdef XSDE_EXCEPTIONS + type_holder.assign (tn.data (), tn.size ()); + type_holder.append (" ", 1); + type_holder.append (tns); +#else + if (type_holder.assign (tn.data (), tn.size ()) || + type_holder.append (" ", 1) || + type_holder.append (tns)) + { + context_.sys_error (sys_error::no_memory); + XML_StopParser (xml_parser_, false); + } +#endif + type = type_holder.data (); + } + else + { + // We know that tn is '\0'-terminated. + // + type = tn.data (); + } + } + } + +#ifdef XSDE_PARSER_VALIDATION + if (!valid) + { + XML_StopParser (xml_parser_, false); + return; + } +#endif + } + } +#endif // XSDE_POLYMORPHIC + + // Dispatch. + // + if (cur.depth_ > 0) + { + if (cur.any_) + { + // Handling content matched by a wildcard. + // + cur.depth_++; + +#ifdef XSDE_POLYMORPHIC + cur.parser_->_start_any_element (ns, name, type); +#else + cur.parser_->_start_any_element (ns, name); +#endif + } + else + { + // Ignoring content for which there is no parser. + // + cur.depth_++; + } + } + else if (cur.parser_) + { + // The "normal" case: call _start_element which will + // call pre() and _pre_impl() (which will push the + // new parser). + // +#ifdef XSDE_POLYMORPHIC + cur.parser_->_start_element (ns, name, type); +#else + cur.parser_->_start_element (ns, name); +#endif + } + else + { + // Root element. Assume the user will report errors via + // context. + // +#ifdef XSDE_POLYMORPHIC + parser_base* p = 0; + + if (polymorphic_ && (root_name_ != name || root_ns_ != ns)) + { + // See if we can translate this element into type using + // substitution map. + // + if (substitution_map_instance ().check ( + ns, + name, + root_ns_.size () ? root_ns_.data () : 0, + root_name_.data (), + type)) + { + ro_string ro_ns (root_ns_); + ro_string ro_name (root_name_); + p = start_root_element (ro_ns, ro_name, type); + } + else + p = start_root_element (ns, name, type); + } + else + p = start_root_element (ns, name, type); +#else + parser_base* p = start_root_element (ns, name); +#endif + +#ifndef XSDE_EXCEPTIONS + if (!context_.error_type ()) + { +#endif + if (p) + { + // pre() is called by the user. + // + p->_pre_impl (context_); + } + else + { + // Ignoring. + // + cur.depth_++; + } + +#ifndef XSDE_EXCEPTIONS + } +#endif + } + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (context_.error_type ()) + { + XML_StopParser (xml_parser_, false); + return; + } +#endif + } + + // Dispatch attributes if we are not ignoring. + // + if (cur.depth_ == 0 || cur.any_) + { + for (; *atts != 0; atts += 2) + { + bits::split_name (*atts, ns_p, ns_s, name_p, name_s); + + const ro_string ns (ns_p, ns_s), name (name_p, name_s); + const ro_string value (*(atts + 1)); + + if (!cur.any_) + cur.parser_->_attribute (ns, name, value); + else + cur.parser_->_any_attribute (ns, name, value); + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (context_.error_type ()) + { + XML_StopParser (xml_parser_, false); + break; + } +#endif + } + } + } + + void document_pimpl:: + end_element_ (const XML_Char* ns_name) + { + // See the comment in start_element_ for what's going on here. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + const char* ns_p; + const char* name_p; + size_t ns_s, name_s; + + bits::split_name (ns_name, ns_p, ns_s, name_p, name_s); + + const ro_string ns (ns_p, ns_s); + const ro_string name (name_p, name_s); + + parser_state& cur = context_.current_; + + // @@ Error propagation. + // + if (cur.depth_ == 0) + { + // The "normal" case: call _post to pop the parser and then + // call _end_element on the "outer" parser which calls post(). + // + parser_base* p = cur.parser_; + cur.parser_->_post_impl (); + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (!context_.error_type ()) + { +#endif + // This case is a bit complicated by the fact that we can be + // popped up into a wildcard. + // + if (cur.depth_ == 0) + { + if (cur.parser_) + cur.parser_->_end_element (ns, name); + else + { + // End of the root element. post() is called by the user. + // + end_root_element (ns, name, p); + } + } + else + { + // Handling content matched by a wildcard. + // + if (--cur.depth_ > 0) + cur.parser_->_end_any_element (ns, name); + else + { + cur.parser_->_end_element (ns, name); + cur.any_ = false; + } + } + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + } +#endif + } + else + { + if (cur.any_) + { + // Handling content matched by a wildcard. + // + if (--cur.depth_ > 0) + cur.parser_->_end_any_element (ns, name); + else + { + cur.parser_->_end_element (ns, name); + cur.any_ = false; + } + } + else + { + // Ignoring content for which there is no parser. + // + if (--cur.depth_ == 0) + { + if (cur.parser_) + cur.parser_->_end_element (ns, name); + else + { + // End of the root element for which there was + // no parser. + // + end_root_element (ns, name, 0); + } + } + } + } + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (context_.error_type ()) + XML_StopParser (xml_parser_, false); +#endif + } + + void document_pimpl:: + characters_ (const XML_Char* s, size_t n) + { + // See the comment in start_element_ for what's going on here. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + // Dispatch characters if we are not ignoring. + // + parser_state& cur = context_.current_; + + if (n != 0 && (cur.depth_ == 0 || cur.any_)) + { + const ro_string str (s, n); + + if (!cur.any_) + cur.parser_->_characters (str); + else + cur.parser_->_any_characters (str); + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (context_.error_type ()) + XML_StopParser (xml_parser_, false); +#endif + } + } + +#ifdef XSDE_POLYMORPHIC + void document_pimpl:: + start_namespace_decl_ (const XML_Char* p, const XML_Char* ns) + { + // prefix is 0 for default namespace + // namespace is 0 when unsetting default namespace + // + if (polymorphic_) + { +#if defined (XSDE_STL) + prefixes_.push_back (p ? p : ""); + prefix_namespaces_.push_back (ns ? ns : ""); +#else +#if defined (XSDE_EXCEPTIONS) + prefixes_.push_back_copy (p ? p : ""); + prefix_namespaces_.push_back_copy (ns ? ns : ""); +#else + if (prefixes_.push_back_copy (p ? p : "" ) || + prefix_namespaces_.push_back_copy (ns ? ns : "")) + { + context_.sys_error (sys_error::no_memory); + XML_StopParser (xml_parser_, false); + } +#endif +#endif + } + } + + void document_pimpl:: + end_namespace_decl_ (const XML_Char*) + { + // prefix is 0 for default namespace + // + if (polymorphic_) + { + // Here we assume the prefixes are removed in the reverse + // order of them being added. This appears to how every + // sensible implementation works. + // + prefixes_.pop_back (); + prefix_namespaces_.pop_back (); + } + } +#endif // XSDE_POLYMORPHIC + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/expat/document.hxx b/libxsde/xsde/cxx/parser/expat/document.hxx new file mode 100644 index 0000000..2f87686 --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/document.hxx @@ -0,0 +1,337 @@ +// file : xsde/cxx/parser/expat/document.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_EXPAT_DOCUMENT_HXX +#define XSDE_CXX_PARSER_EXPAT_DOCUMENT_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#ifdef XSDE_STL +# include <string> +#endif + +#ifdef XSDE_IOSTREAM +# include <iosfwd> +#endif + +#include <xsde/c/expat/expat.h> + +// We only support UTF-8 expat for now. +// +#ifdef XML_UNICODE +#error UTF-16 expat (XML_UNICODE defined) is not supported +#endif + +#include <xsde/cxx/string.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/string-sequence.hxx> +#endif + +#include <xsde/cxx/parser/context.hxx> +#include <xsde/cxx/parser/elements.hxx> + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/parser/error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { + // Simple auto pointer for Expat's XML_Parser object. + // + struct parser_auto_ptr + { + ~parser_auto_ptr (); + + explicit + parser_auto_ptr (XML_Parser = 0); + + parser_auto_ptr& + operator= (XML_Parser); + + public: + operator XML_Parser () + { + return parser_; + } + + private: + parser_auto_ptr (const parser_auto_ptr&); + + parser_auto_ptr& + operator= (const parser_auto_ptr&); + + private: + XML_Parser parser_; + }; + + // + // + class document_pimpl + { + public: + virtual + ~document_pimpl (); + +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base&, + const char* root_element_name, + bool polymorphic = false); + + document_pimpl (parser_base&, + const char* root_element_namespace, + const char* root_element_name, + bool polymorphic = false); + +#ifdef XSDE_STL + document_pimpl (parser_base&, + const std::string& root_element_name, + bool polymorphic = false); + + document_pimpl (parser_base&, + const std::string& root_element_namespace, + const std::string& root_element_name, + bool polymorphic = false); + +#endif // XSDE_STL + protected: + document_pimpl (); // Non-polymorphic parsing. + + document_pimpl (const char* root_element_name); + + document_pimpl (const char* root_element_namespace, + const char* root_element_name); + +#ifdef XSDE_STL + document_pimpl (const std::string& root_element_name); + + document_pimpl (const std::string& root_element_namespace, + const std::string& root_element_name); +#endif + + +#else // XSDE_POLYMORPHIC + + document_pimpl (parser_base&, + const char* root_element_name); + + document_pimpl (parser_base&, + const char* root_element_namespace, + const char* root_element_name); + +#ifdef XSDE_STL + document_pimpl (parser_base&, + const std::string& root_element_name); + + document_pimpl (parser_base&, + const std::string& root_element_namespace, + const std::string& root_element_name); +#endif + protected: + document_pimpl (); + +#endif // XSDE_POLYMORPHIC + + // This function is called to obtain the root element type parser. + // If the returned pointed is 0 then the whole document content + // is ignored. + // + // The type argument contains the type name and namespace if + // xsi:type attribute or an element that substitutes the root + // was specified and 0 otherwise. The type argument is in the + // form "<name> <namespace>" with the space and namespace part + // absent if the type does not have a namespace. + // + // +#ifdef XSDE_POLYMORPHIC + virtual parser_base* + start_root_element (const ro_string& ns, + const ro_string& name, + const char* type); +#else + virtual parser_base* + start_root_element (const ro_string& ns, const ro_string& name); +#endif + + + // This function is called to indicate the completion of document + // parsing. The parser argument contains the pointer returned by + // start_root_element. + // + virtual void + end_root_element (const ro_string& ns, + const ro_string& name, + parser_base* parser); + + public: + // If you override start_root_element() then you will most + // likely also want to override reset() in order to reset + // root element parser(s). + // + virtual void + reset (); + +#ifdef XSDE_IOSTREAM + public: + // Parse a local file. The file is accessed with std::ifstream + // in binary mode. The std::ios_base::failure exception is used + // to report io errors (badbit and failbit) if XSDE_EXCEPTIONS + // is defined. Otherwise error codes are used. + // + void + parse (const char* file); + +#ifdef XSDE_STL + void + parse (const std::string& file); +#endif + + // Parse std::istream. std::ios_base::failure exception is used + // to report io errors (badbit and failbit) if XSDE_EXCEPTIONS + // is defined. Otherwise error codes are used. + // + void + parse (std::istream&); +#endif + + public: + // Parse a chunk of input. You can call this function multiple + // times with the last call having the last argument true. + // + void + parse (const void* data, size_t size, bool last); + + public: + // Low-level Expat-specific parsing API. A typical use case + // would look like this (pseudo-code): + // + // XML_Parser xml_parser (XML_ParserCreateNS (0, ' ')); + // + // xxx_pimpl root; + // document_pimpl doc (root, "root"); + // + // root.pre (); + // doc.parse_begin (xml_parser); + // + // while (more_stuff_to_parse) + // { + // // Call XML_Parse or XML_ParseBuffer: + // // + // if (XML_Parse (...) != XML_STATUS_ERROR) + // break; + // } + // + // doc.parse_end (); + // result_type result (root.post_xxx ()); + // + // Notes: + // + // 1. If your XML instances use XML namespaces, XML_ParserCreateNS + // functions should be used to create the XML parser. Space + // (XML_Char (' ')) should be used as a separator (the second + // argument to XML_ParserCreateNS). + // + // 2. If XML_Parse or XML_ParseBuffer fail, call parse_end to + // determine the error which is indicated either via exception + // or set as an error code. + // + void + parse_begin (XML_Parser); + + void + parse_end (); + +#ifndef XSDE_EXCEPTIONS + public: + const error& + _error () const; +#endif + + protected: + void + set (); + + void + clear (); + + protected: + static void XMLCALL + start_element (void*, const XML_Char*, const XML_Char**); + + static void XMLCALL + end_element (void*, const XML_Char*); + + static void XMLCALL + characters (void*, const XML_Char*, int); + +#ifdef XSDE_POLYMORPHIC + static void XMLCALL + start_namespace_decl (void*, const XML_Char*, const XML_Char*); + + static void XMLCALL + end_namespace_decl (void*, const XML_Char*); +#endif + + protected: + void + start_element_ (const XML_Char* ns_name, const XML_Char** atts); + + void + end_element_ (const XML_Char* ns_name); + + void + characters_ (const XML_Char* s, size_t n); + +#ifdef XSDE_POLYMORPHIC + void + start_namespace_decl_ (const XML_Char* prefix, const XML_Char* ns); + + void + end_namespace_decl_ (const XML_Char* prefix); +#endif + + protected: + bool first_; + XML_Parser xml_parser_; + parser_auto_ptr auto_xml_parser_; + + context context_; + + parser_base* parser_; + string root_name_; + string root_ns_; + +#ifdef XSDE_POLYMORPHIC + bool polymorphic_; + string_sequence prefixes_; + string_sequence prefix_namespaces_; +#endif + +#ifndef XSDE_EXCEPTIONS + error error_; +#endif + + private: + void + init_root_name (const char* ns, const char* name); + }; + } + } + } +} + +#include <xsde/cxx/parser/expat/document.ixx> + +#endif // XSDE_CXX_PARSER_EXPAT_DOCUMENT_HXX diff --git a/libxsde/xsde/cxx/parser/expat/document.ixx b/libxsde/xsde/cxx/parser/expat/document.ixx new file mode 100644 index 0000000..0c3d34d --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/document.ixx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/expat/document.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { + // parser_auto_ptr + // + inline parser_auto_ptr:: + ~parser_auto_ptr () + { + if (parser_ != 0) + XML_ParserFree (parser_); + } + + inline parser_auto_ptr:: + parser_auto_ptr (XML_Parser parser) + : parser_ (parser) + { + } + + inline parser_auto_ptr& parser_auto_ptr:: + operator= (XML_Parser parser) + { + if (parser_ != 0) + XML_ParserFree (parser_); + + parser_ = parser; + return *this; + } + + + // document_pimpl + // +#ifndef XSDE_EXCEPTIONS + inline const error& document_pimpl:: + _error () const + { + return error_; + } +#endif + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/expat/xml-error.cxx b/libxsde/xsde/cxx/parser/expat/xml-error.cxx new file mode 100644 index 0000000..a24059c --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/xml-error.cxx @@ -0,0 +1,25 @@ +// file : xsde/cxx/parser/expat/xml-error.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/expat/xml-error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { + const char* + xml_error_text (xml_error e) + { + return XML_ErrorString (e); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/expat/xml-error.hxx b/libxsde/xsde/cxx/parser/expat/xml-error.hxx new file mode 100644 index 0000000..4028590 --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/xml-error.hxx @@ -0,0 +1,28 @@ +// file : xsde/cxx/parser/expat/xml-error.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_EXPAT_XML_ERROR_HXX +#define XSDE_CXX_PARSER_EXPAT_XML_ERROR_HXX + +#include <xsde/c/expat/expat.h> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { + typedef XML_Error xml_error; + + const char* + xml_error_text (xml_error); + } + } + } +} + +#endif // XSDE_CXX_PARSER_EXPAT_XML_ERROR_HXX diff --git a/libxsde/xsde/cxx/parser/map.cxx b/libxsde/xsde/cxx/parser/map.cxx new file mode 100644 index 0000000..b21c41e --- /dev/null +++ b/libxsde/xsde/cxx/parser/map.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/parser/map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/map.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // parser_map + // + parser_map:: + ~parser_map () + { + } + + // parser_map_impl + // + void parser_map_impl:: + reset () const + { + for (hashmap::const_iterator i (map_.begin ()), e (map_.end ()); + i != e; ++i) + { + parser_base* p = *static_cast<parser_base* const*> (*i); + p->_reset (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/map.hxx b/libxsde/xsde/cxx/parser/map.hxx new file mode 100644 index 0000000..400de27 --- /dev/null +++ b/libxsde/xsde/cxx/parser/map.hxx @@ -0,0 +1,87 @@ +// file : xsde/cxx/parser/map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_MAP_HXX +#define XSDE_CXX_PARSER_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/hashmap.hxx> + +#include <xsde/cxx/parser/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // Parser map. Used in the polymorphic document parsing. + // + class parser_map + { + public: + // The type argument is the type name and namespace from the + // xsi:type attribute or substitution group map in the form + // "<name> <namespace>" with the space and namespace part + // absent if the type does not have a namespace. + // + virtual parser_base* + find (const char* type) const = 0; + + // Reset the parsers this map contains. + // + virtual void + reset () const = 0; + + virtual + ~parser_map (); + }; + + // Default parser map implementation. + // + class parser_map_impl: public parser_map + { + public: +#ifndef XSDE_EXCEPTIONS + enum error + { + error_none, + error_no_memory + }; + + error + _error () const; +#endif + + public: + parser_map_impl (size_t buckets); + + void + insert (parser_base&); + + virtual parser_base* + find (const char* type) const; + + virtual void + reset () const; + + private: + parser_map_impl (const parser_map_impl&); + + parser_map_impl& + operator= (const parser_map_impl&); + + private: + hashmap map_; + }; + } + } +} + +#include <xsde/cxx/parser/map.ixx> + +#endif // XSDE_CXX_PARSER_MAP_HXX diff --git a/libxsde/xsde/cxx/parser/map.ixx b/libxsde/xsde/cxx/parser/map.ixx new file mode 100644 index 0000000..3a1f931 --- /dev/null +++ b/libxsde/xsde/cxx/parser/map.ixx @@ -0,0 +1,41 @@ +// file : xsde/cxx/parser/map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { +#ifndef XSDE_EXCEPTIONS + inline parser_map_impl::error parser_map_impl:: + _error () const + { + return map_._error () ? error_no_memory : error_none; + } +#endif + + inline parser_map_impl:: + parser_map_impl (size_t buckets) + : map_ (buckets, sizeof (parser_base*)) + { + } + + inline void parser_map_impl:: + insert (parser_base& p) + { + parser_base* tmp = &p; + map_.insert (p._dynamic_type (), &tmp); + } + + inline parser_base* parser_map_impl:: + find (const char* type) const + { + const void* p = map_.find (type); + return p ? *static_cast<parser_base* const*> (p) : 0; + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/any-type.hxx b/libxsde/xsde/cxx/parser/non-validating/any-type.hxx new file mode 100644 index 0000000..37e1d6f --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/any-type.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/parser/non-validating/any-type.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_ANY_TYPE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_ANY_TYPE_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // any_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_type_pimpl: virtual any_type_pskel +#else + struct any_type_pimpl: any_type_pskel +#endif + { + }; + + // any_simple_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_simple_type_pimpl: virtual any_simple_type_pskel +#else + struct any_simple_type_pimpl: any_simple_type_pskel +#endif + { + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_ANY_TYPE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/base64-binary.cxx b/libxsde/xsde/cxx/parser/non-validating/base64-binary.cxx new file mode 100644 index 0000000..95588a2 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/base64-binary.cxx @@ -0,0 +1,241 @@ +// file : xsde/cxx/parser/non-validating/base64-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/base64-binary.hxx> + +static unsigned char +base64_decode (char c) +{ + unsigned char r = 0xFF; + + if (c >= 'A' && c <= 'Z') + r = static_cast<unsigned char> (c - 'A'); + else if (c >= 'a' && c <= 'z') + r = static_cast<unsigned char> (c - 'a' + 26); + else if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0' + 52); + else if (c == '+') + r = 62; + else if (c == '/') + r = 63; + + return r; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + base64_binary_pimpl:: + ~base64_binary_pimpl () + { + if (!base_) + delete buf_; + } + + void base64_binary_pimpl:: + _reset () + { + base64_binary_pskel::_reset (); + + if (!base_) + { + delete buf_; + buf_ = 0; + } + } + + base64_binary_pimpl:: + base64_binary_pimpl (bool base) + : base_ (base), buf_ (0) + { + } + + void base64_binary_pimpl:: + pre_impl (buffer* b) + { + buf_ = b; + } + + void base64_binary_pimpl:: + _pre () + { + if (buf_ == 0) + { + buf_ = new buffer (); + +#ifndef XSDE_EXCEPTIONS + if (buf_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void base64_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + buffer* base64_binary_pimpl:: + post_base64_binary () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + const char* src = str_.data (); + + // Remove all whitespaces. + // + { + size_type j = 0; + bool subs = false; + + for (size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + subs = false; + + str_[j++] = c; + } + } + + size = j; + str_.truncate (size); + } + + // Our length should be a multiple of four. + // + size_type quad_count = size / 4; + size_type capacity = quad_count * 3 + 1; + +#ifdef XSDE_EXCEPTIONS + buf_->size (capacity); +#else + if (buf_->size (capacity)) + { + _sys_error (sys_error::no_memory); + return 0; + } +#endif + char* dst = buf_->data (); + + // Source and destination indexes. + // + size_type si = 0; + size_type di = 0; + + // Process all quads except the last one. + // + unsigned char b1, b2, b3, b4; + + for (size_type q = 0; q < quad_count - 1; ++q) + { + b1 = base64_decode (src[si++]); + b2 = base64_decode (src[si++]); + b3 = base64_decode (src[si++]); + b4 = base64_decode (src[si++]); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Process the last quad. The first two octets are always there. + // + b1 = base64_decode (src[si++]); + b2 = base64_decode (src[si++]); + + char e3 = src[si++]; + char e4 = src[si++]; + + if (e4 == '=') + { + if (e3 == '=') + { + // Two pads. Last 4 bits in b2 should be zero. + // + dst[di++] = (b1 << 2) | (b2 >> 4); + } + else + { + // One pad. Last 2 bits in b3 should be zero. + // + b3 = base64_decode (e3); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + } + } + else + { + // No pads. + // + b3 = base64_decode (e3); + b4 = base64_decode (e4); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Set the real size. + // + buf_->size (di); + + buffer* r = buf_; + buf_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/base64-binary.hxx b/libxsde/xsde/cxx/parser/non-validating/base64-binary.hxx new file mode 100644 index 0000000..fef946b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/base64-binary.hxx @@ -0,0 +1,55 @@ +// file : xsde/cxx/parser/non-validating/base64-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_BASE64_BINARY_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_BASE64_BINARY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct base64_binary_pimpl: virtual base64_binary_pskel +#else + struct base64_binary_pimpl: base64_binary_pskel +#endif + { + ~base64_binary_pimpl (); + base64_binary_pimpl (bool base = false); + + void + pre_impl (buffer*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual buffer* + post_base64_binary (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + buffer* buf_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_BASE64_BINARY_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/boolean.cxx b/libxsde/xsde/cxx/parser/non-validating/boolean.cxx new file mode 100644 index 0000000..af5ee41 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/boolean.cxx @@ -0,0 +1,80 @@ +// file : xsde/cxx/parser/non-validating/boolean.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/boolean.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void boolean_pimpl:: + _pre () + { + size_ = 0; + state_ = leading_ws; + } + + void boolean_pimpl:: + _characters (const ro_string& s) + { + ro_string tmp (s.data (), s.size ()); + + size_t size = tmp.size (); + + switch (state_) + { + case leading_ws: + { + size = trim_left (tmp); + + if (size != 0) + state_ = literal; + else + break; + // Fall through. + } + case literal: + { + // If this chunk is too long then it has to be the last so trim + // trailing ws. + // + if ((5 - size_) < size) + { + size = trim_right (tmp); + state_ = trailing_ws; // It either had ws or is too large. + } + + if ((5 - size_) >= size) + { + memcpy (str_ + size_, tmp.data (), size); + size_ += size; + } + + break; + } + case trailing_ws: + { + // We don't really care if it is not. + break; + } + } + } + + bool boolean_pimpl:: + post_boolean () + { + ro_string tmp (str_, size_); + trim_right (tmp); + + return (tmp == "1" || tmp == "true"); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/boolean.hxx b/libxsde/xsde/cxx/parser/non-validating/boolean.hxx new file mode 100644 index 0000000..eeb9068 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/boolean.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_BOOLEAN_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_BOOLEAN_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct boolean_pimpl: virtual boolean_pskel +#else + struct boolean_pimpl: boolean_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual bool + post_boolean (); + + protected: + // We only need strlen("false") + 1 characters to hold all valid + // and trimmed string representations of boolean. + // + char str_[6]; + size_t size_; + enum { leading_ws, literal, trailing_ws } state_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_BOOLEAN_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/byte.cxx b/libxsde/xsde/cxx/parser/non-validating/byte.cxx new file mode 100644 index 0000000..47fa839 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/byte.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void byte_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void byte_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 4); + } + + signed char byte_pimpl:: + post_byte () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? static_cast<signed char> (-static_cast<short> (ul)) + : static_cast<signed char> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/byte.hxx b/libxsde/xsde/cxx/parser/non-validating/byte.hxx new file mode 100644 index 0000000..a6bbffc --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/byte.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_BYTE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_BYTE_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 8-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct byte_pimpl: virtual byte_pskel, number +#else + struct byte_pimpl: byte_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual signed char + post_byte (); + + protected: + // We only need strlen("0128") + 1 characters to hold all valid + // and trimmed string representations of signed byte. + // + char str_[5]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_BYTE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/date-time.cxx b/libxsde/xsde/cxx/parser/non-validating/date-time.cxx new file mode 100644 index 0000000..59d8c11 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/date-time.cxx @@ -0,0 +1,154 @@ +// file : xsde/cxx/parser/non-validating/date-time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul, strtod + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/date-time.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void date_time_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void date_time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + date_time date_time_pimpl:: + post_date_time () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + int year = 0; + unsigned short month = 0; + unsigned short day = 0; + unsigned short hours = 0; + unsigned short minutes = 0; + double seconds = 0.0; + bool zone = false; + short zh, zm; + + if (n >= 19) + { + // Find the end of the year token. + // + ro_string::size_type yp = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (yp != ro_string::npos && (n - yp - 1) >= 14) + { + // Find the end of the seconds fragment. + // + ro_string::size_type sp = yp + 15; + for (; sp < n; ++sp) + { + char c = s[sp]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // Parse it backwards so that we can truncate and reuse + // the string. + // + + // zone + // + if (sp < n) + { + bits::parse_time_zone (s + sp, n - sp, zh, zm); + zone = true; + } + + // seconds + // + str_.truncate (sp); + + seconds = strtod (s + yp + 13, 0); + + // minutes + // + minutes = 10 * (s[yp + 10] - '0') + (s[yp + 11] - '0'); + + // hours + // + hours = 10 * (s[yp + 7] - '0') + (s[yp + 8] - '0'); + + // day + // + day = 10 * (s[yp + 4] - '0') + (s[yp + 5] - '0'); + + // month + // + month = 10 * (s[yp + 1] - '0') + (s[yp + 2] - '0'); + + // year + // + str_.truncate (yp); + + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, 0, 10); + + year = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + + return zone + ? date_time (year, month, day, hours, minutes, seconds, zh, zm) + : date_time (year, month, day, hours, minutes, seconds); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/date-time.hxx b/libxsde/xsde/cxx/parser/non-validating/date-time.hxx new file mode 100644 index 0000000..bb329af --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/date-time.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/date-time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DATE_TIME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DATE_TIME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_time_pimpl: virtual date_time_pskel +#else + struct date_time_pimpl: date_time_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual date_time + post_date_time (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DATE_TIME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/date.cxx b/libxsde/xsde/cxx/parser/non-validating/date.cxx new file mode 100644 index 0000000..0364ac1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/date.cxx @@ -0,0 +1,126 @@ +// file : xsde/cxx/parser/non-validating/date.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/date.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void date_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void date_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + date date_pimpl:: + post_date () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] + // + + int year = 0; + unsigned short month = 0; + unsigned short day = 0; + bool zone = false; + short zh, zm; + + if (n >= 10) + { + // Find the end of the year token. + // + ro_string::size_type pos = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (pos != ro_string::npos && (n - pos - 1) >= 5) + { + // Parse the month, day values and time zone first so that we + // can truncate and reuse the string. + // + + // month + // + month = 10 * (s[pos + 1] - '0') + (s[pos + 2] - '0'); + + // day + // + day = 10 * (s[pos + 4] - '0') + (s[pos + 5] - '0'); + + // zone + // + if ((pos + 6) < n) + { + bits::parse_time_zone (s + pos + 6, n - pos - 6, zh, zm); + zone = true; + } + + // year + // + str_.truncate (pos); + + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, 0, 10); + + year = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + + return zone + ? date (year, month, day, zh, zm) + : date (year, month, day); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/date.hxx b/libxsde/xsde/cxx/parser/non-validating/date.hxx new file mode 100644 index 0000000..174de7d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/date.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/date.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DATE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DATE_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_pimpl: virtual date_pskel +#else + struct date_pimpl: date_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual date + post_date (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DATE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/decimal.cxx b/libxsde/xsde/cxx/parser/non-validating/decimal.cxx new file mode 100644 index 0000000..401800b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/decimal.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/decimal.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/parser/non-validating/decimal.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void decimal_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void decimal_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 127); + } + + double decimal_pimpl:: + post_decimal () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + double r = strtod (str_, 0); + + if (sign_ == minus) + r = -r; + + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/decimal.hxx b/libxsde/xsde/cxx/parser/non-validating/decimal.hxx new file mode 100644 index 0000000..fd1cf4e --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/decimal.hxx @@ -0,0 +1,46 @@ +// file : xsde/cxx/parser/non-validating/decimal.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DECIMAL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DECIMAL_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct decimal_pimpl: virtual decimal_pskel, number +#else + struct decimal_pimpl: decimal_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual double + post_decimal (); + + protected: + // Assume decimal values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DECIMAL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/double.cxx b/libxsde/xsde/cxx/parser/non-validating/double.cxx new file mode 100644 index 0000000..8c7ab9a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/double.cxx @@ -0,0 +1,62 @@ +// file : xsde/cxx/parser/non-validating/double.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/parser/non-validating/double.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void double_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void double_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 127); + } + + double double_pimpl:: + post_double () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + double r; + + if (tmp == "INF") + { + r = strtod (sign_ == minus ? "-INF" : "INF", 0); + } + else if (tmp == "NaN") + { + r = strtod ("NAN", 0); + } + else + { + r = strtod (str_, 0); + + if (sign_ == minus) + r = -r; + } + + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/double.hxx b/libxsde/xsde/cxx/parser/non-validating/double.hxx new file mode 100644 index 0000000..1e5f299 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/double.hxx @@ -0,0 +1,46 @@ +// file : xsde/cxx/parser/non-validating/double.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DOUBLE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DOUBLE_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct double_pimpl: virtual double_pskel, number +#else + struct double_pimpl: double_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual double + post_double (); + + protected: + // Assume double values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DOUBLE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/duration.cxx b/libxsde/xsde/cxx/parser/non-validating/duration.cxx new file mode 100644 index 0000000..d7cbb3b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/duration.cxx @@ -0,0 +1,166 @@ +// file : xsde/cxx/parser/non-validating/duration.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul, strtod + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/duration.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void duration_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void duration_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + static ro_string::size_type + rfind_delim (const char* s, ro_string::size_type pos) + { + const char* p = s + pos; + for (; p >= s; --p) + { + if (*p == 'Y' || *p == 'D' || *p == 'M' || + *p == 'H' || *p == 'M' || *p == 'S' || + *p == 'T' || *p == 'P') + break; + } + + return p >= s ? p - s : ro_string::npos; + } + + duration duration_pimpl:: + post_duration () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + bool negative = false; + unsigned int years = 0; + unsigned int months = 0; + unsigned int days = 0; + unsigned int hours = 0; + unsigned int minutes = 0; + double seconds = 0.0; + + // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] + // + + if (n >= 3 && s[s[0] == '-' ? 1 : 0] == 'P') + { + if (s[0] == '-') + negative = true; + + // Parse it backwards so that we can truncate and reuse + // the string. + // + ro_string::size_type pos = n - 1; + ro_string::size_type t_pos = tmp.find ('T'); + + if (s[pos] == 'S') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + seconds = strtod (s + pos + 1, 0); + } + + if (s[pos] == 'M' && t_pos != ro_string::npos && t_pos < pos) + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + minutes = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + + if (s[pos] == 'H') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + hours = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + + if (s[pos] == 'T') + pos = rfind_delim (s, pos - 1); + + if (s[pos] == 'D') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + days = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + + if (s[pos] == 'M') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + months = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + + if (s[pos] == 'Y') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + years = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + } + + return duration ( + negative, years, months, days, hours, minutes, seconds); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/duration.hxx b/libxsde/xsde/cxx/parser/non-validating/duration.hxx new file mode 100644 index 0000000..ebbd210 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/duration.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/duration.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DURATION_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DURATION_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct duration_pimpl: virtual duration_pskel +#else + struct duration_pimpl: duration_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual duration + post_duration (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DURATION_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/float.cxx b/libxsde/xsde/cxx/parser/non-validating/float.cxx new file mode 100644 index 0000000..9c90b32 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/float.cxx @@ -0,0 +1,76 @@ +// file : xsde/cxx/parser/non-validating/float.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtof, strtod + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/float.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void float_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void float_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 127); + } + + float float_pimpl:: + post_float () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + float r; + + if (tmp == "INF") + { +#ifdef XSDE_STRTOF + r = strtof (sign_ == minus ? "-INF" : "INF", 0); +#else + r = static_cast<float> (strtod (sign_ == minus ? "-INF" : "INF", 0)); +#endif + } + else if (tmp == "NaN") + { +#ifdef XSDE_STRTOF + r = strtof ("NAN", 0); +#else + r = static_cast<float> (strtod ("NAN", 0)); +#endif + } + else + { +#ifdef XSDE_STRTOF + r = strtof (str_, 0); +#else + r = static_cast<float> (strtod (str_, 0)); +#endif + + if (sign_ == minus) + r = -r; + } + + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/float.hxx b/libxsde/xsde/cxx/parser/non-validating/float.hxx new file mode 100644 index 0000000..cae4fa7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/float.hxx @@ -0,0 +1,46 @@ +// file : xsde/cxx/parser/non-validating/float.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_FLOAT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_FLOAT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct float_pimpl: virtual float_pskel, number +#else + struct float_pimpl: float_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual float + post_float (); + + protected: + // Assume float values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_FLOAT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gday.cxx b/libxsde/xsde/cxx/parser/non-validating/gday.cxx new file mode 100644 index 0000000..64c9cd9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gday.cxx @@ -0,0 +1,88 @@ +// file : xsde/cxx/parser/non-validating/gday.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gday.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gday_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gday_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gday gday_pimpl:: + post_gday () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gday := ---DD[Z|(+|-)HH:MM] + // + + unsigned short day = 0; + bool zone = false; + short zh, zm; + + if (n >= 5) + { + day = 10 * (s[3] - '0') + (s[4] - '0'); + + if (n > 5) + { + bits::parse_time_zone (s + 5, n - 5, zh, zm); + zone = true; + } + } + + return zone ? gday (day, zh, zm) : gday (day); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gday.hxx b/libxsde/xsde/cxx/parser/non-validating/gday.hxx new file mode 100644 index 0000000..7af0c19 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gday.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gday.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GDAY_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GDAY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gday_pimpl: virtual gday_pskel +#else + struct gday_pimpl: gday_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gday + post_gday (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GDAY_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gmonth-day.cxx b/libxsde/xsde/cxx/parser/non-validating/gmonth-day.cxx new file mode 100644 index 0000000..223b73f --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gmonth-day.cxx @@ -0,0 +1,100 @@ +// file : xsde/cxx/parser/non-validating/gmonth-day.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gmonth-day.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gmonth_day_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gmonth_day_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gmonth_day gmonth_day_pimpl:: + post_gmonth_day () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gmonth_day := --MM-DD[Z|(+|-)HH:MM] + // + + unsigned short month = 0; + unsigned short day = 0; + bool zone = false; + short zh, zm; + + if (n >= 7) + { + // month + // + month = 10 * (s[2] - '0') + (s[3] - '0'); + + // day + // + day = 10 * (s[5] - '0') + (s[6] - '0'); + + // zone + // + if (n > 7) + { + bits::parse_time_zone (s + 7, n - 7, zh, zm); + zone = true; + + } + } + + return zone + ? gmonth_day (month, day, zh, zm) + : gmonth_day (month, day); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gmonth-day.hxx b/libxsde/xsde/cxx/parser/non-validating/gmonth-day.hxx new file mode 100644 index 0000000..75fb3fb --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gmonth-day.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gmonth-day.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_DAY_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_DAY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_day_pimpl: virtual gmonth_day_pskel +#else + struct gmonth_day_pimpl: gmonth_day_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gmonth_day + post_gmonth_day (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_DAY_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gmonth.cxx b/libxsde/xsde/cxx/parser/non-validating/gmonth.cxx new file mode 100644 index 0000000..f203c70 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gmonth.cxx @@ -0,0 +1,88 @@ +// file : xsde/cxx/parser/non-validating/gmonth.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gmonth.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gmonth_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gmonth_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gmonth gmonth_pimpl:: + post_gmonth () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gmonth := --MM[Z|(+|-)HH:MM] + // + + unsigned short month = 0; + bool zone = false; + short zh, zm; + + if (n >= 4) + { + month = 10 * (s[2] - '0') + (s[3] - '0'); + + if (n > 4) + { + bits::parse_time_zone (s + 4, n - 4, zh, zm); + zone = true; + } + } + + return zone ? gmonth (month, zh, zm) : gmonth (month); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gmonth.hxx b/libxsde/xsde/cxx/parser/non-validating/gmonth.hxx new file mode 100644 index 0000000..dfa9b33 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gmonth.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gmonth.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_pimpl: virtual gmonth_pskel +#else + struct gmonth_pimpl: gmonth_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gmonth + post_gmonth (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gyear-month.cxx b/libxsde/xsde/cxx/parser/non-validating/gyear-month.cxx new file mode 100644 index 0000000..4492246 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gyear-month.cxx @@ -0,0 +1,121 @@ +// file : xsde/cxx/parser/non-validating/gyear-month.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gyear-month.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gyear_month_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gyear_month_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gyear_month gyear_month_pimpl:: + post_gyear_month () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] + // + + int year = 0; + unsigned short month = 0; + bool zone = false; + short zh, zm; + + if (n >= 7) + { + // Find the end of the year token. + // + ro_string::size_type pos = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (pos != ro_string::npos && (n - pos - 1) >= 2) + { + // Parse the month value and time zone first so that we can + // truncate and reuse the string. + // + + // month + // + month = 10 * (s[pos + 1] - '0') + (s[pos + 2] - '0'); + + // zone + // + if ((pos + 3) < n) + { + bits::parse_time_zone (s + pos + 3, n - pos - 3, zh, zm); + zone = true; + } + + // year + // + str_.truncate (pos); + + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, 0, 10); + + year = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + + return zone + ? gyear_month (year, month, zh, zm) + : gyear_month (year, month); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gyear-month.hxx b/libxsde/xsde/cxx/parser/non-validating/gyear-month.hxx new file mode 100644 index 0000000..23b7378 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gyear-month.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gyear-month.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_MONTH_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_MONTH_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_month_pimpl: virtual gyear_month_pskel +#else + struct gyear_month_pimpl: gyear_month_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gyear_month + post_gyear_month (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_MONTH_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gyear.cxx b/libxsde/xsde/cxx/parser/non-validating/gyear.cxx new file mode 100644 index 0000000..351ac4c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gyear.cxx @@ -0,0 +1,115 @@ +// file : xsde/cxx/parser/non-validating/gyear.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gyear.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gyear_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gyear_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gyear gyear_pimpl:: + post_gyear () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] + // + + int year = 0; + bool zone = false; + short zh, zm; + + if (n >= 4) + { + // Find the end of the year token. + // + ro_string::size_type pos = (s[0] == '-' ? 5 : 4); + for (; pos < n; ++pos) + { + char c = s[pos]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // Parse the time zone first so that we can truncate and + // reuse the string. + // + if (pos < n) + { + bits::parse_time_zone (s + pos, n - pos, zh, zm); + zone = true; + } + + // Parse the year value. + // + str_.truncate (pos); + + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, 0, 10); + + year = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + return zone ? gyear (year, zh, zm) : gyear (year); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gyear.hxx b/libxsde/xsde/cxx/parser/non-validating/gyear.hxx new file mode 100644 index 0000000..528b368 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gyear.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gyear.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_pimpl: virtual gyear_pskel +#else + struct gyear_pimpl: gyear_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gyear + post_gyear (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/hex-binary.cxx b/libxsde/xsde/cxx/parser/non-validating/hex-binary.cxx new file mode 100644 index 0000000..a7cc8b4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/hex-binary.cxx @@ -0,0 +1,159 @@ +// file : xsde/cxx/parser/non-validating/hex-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/hex-binary.hxx> + +static unsigned char +hex_decode (char c) +{ + unsigned char r = 0xFF; + + if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0'); + else if (c >= 'A' && c <= 'F') + r = static_cast<unsigned char> (10 + (c - 'A')); + else if (c >= 'a' && c <= 'f') + r = static_cast<unsigned char> (10 + (c - 'a')); + + return r; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + hex_binary_pimpl:: + ~hex_binary_pimpl () + { + if (!base_) + delete buf_; + } + + void hex_binary_pimpl:: + _reset () + { + hex_binary_pskel::_reset (); + + if (!base_) + { + delete buf_; + buf_ = 0; + } + } + + hex_binary_pimpl:: + hex_binary_pimpl (bool base) + : base_ (base), buf_ (0) + { + } + + void hex_binary_pimpl:: + pre_impl (buffer* b) + { + buf_ = b; + } + + void hex_binary_pimpl:: + _pre () + { + if (buf_ == 0) + { + buf_ = new buffer (); + +#ifndef XSDE_EXCEPTIONS + if (buf_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void hex_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + buffer* hex_binary_pimpl:: + post_hex_binary () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + size_t n = size / 2; + +#ifdef XSDE_EXCEPTIONS + buf_->size (n); +#else + if (buf_->size (n)) + { + _sys_error (sys_error::no_memory); + return 0; + } +#endif + + if (n != 0) + { + const char* src = tmp.data (); + char* dst = buf_->data (); + size_t i = 0; + + for (; i < n; ++i) + { + unsigned char h = hex_decode (src[2 * i]); + unsigned char l = hex_decode (src[2 * i + 1]); + + if (h == 0xFF || l == 0xFF) + break; + + dst[i] = (h << 4) | l; + } + } + + buffer* r = buf_; + buf_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/hex-binary.hxx b/libxsde/xsde/cxx/parser/non-validating/hex-binary.hxx new file mode 100644 index 0000000..3b7a4b3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/hex-binary.hxx @@ -0,0 +1,55 @@ +// file : xsde/cxx/parser/non-validating/hex-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_HEX_BINARY_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_HEX_BINARY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct hex_binary_pimpl: virtual hex_binary_pskel +#else + struct hex_binary_pimpl: hex_binary_pskel +#endif + { + ~hex_binary_pimpl (); + hex_binary_pimpl (bool base = false); + + void + pre_impl (buffer*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual buffer* + post_hex_binary (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + buffer* buf_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_HEX_BINARY_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/id-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/id-stl.cxx new file mode 100644 index 0000000..15a611b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/id-stl.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/id-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/id-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void id_pimpl:: + _pre () + { + str_.erase (); + } + + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string id_pimpl:: + post_id () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/non-validating/id-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/id-stl.hxx new file mode 100644 index 0000000..5109ba1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/id-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/id-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_ID_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_ID_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_pimpl: virtual id_pskel +#else + struct id_pimpl: id_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_id (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_ID_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/id.cxx b/libxsde/xsde/cxx/parser/non-validating/id.cxx new file mode 100644 index 0000000..5230305 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/id.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/id.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/id.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void id_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* id_pimpl:: + post_id () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/id.hxx b/libxsde/xsde/cxx/parser/non-validating/id.hxx new file mode 100644 index 0000000..d762271 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/id.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/id.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_ID_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_ID_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_pimpl: virtual id_pskel +#else + struct id_pimpl: id_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_id (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_ID_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/idref-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/idref-stl.cxx new file mode 100644 index 0000000..e3be5af --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idref-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/idref-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void idref_pimpl:: + _pre () + { + str_.erase (); + } + + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string idref_pimpl:: + post_idref () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/idref-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/idref-stl.hxx new file mode 100644 index 0000000..e65375c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idref-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/idref-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_IDREF_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_IDREF_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_pimpl: virtual idref_pskel +#else + struct idref_pimpl: idref_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_idref (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_IDREF_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/idref.cxx b/libxsde/xsde/cxx/parser/non-validating/idref.cxx new file mode 100644 index 0000000..f6ac060 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idref.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/idref.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void idref_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* idref_pimpl:: + post_idref () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/idref.hxx b/libxsde/xsde/cxx/parser/non-validating/idref.hxx new file mode 100644 index 0000000..b76318c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idref.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/idref.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_IDREF_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_IDREF_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_pimpl: virtual idref_pskel +#else + struct idref_pimpl: idref_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_idref (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_IDREF_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.cxx new file mode 100644 index 0000000..a62ea47 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.cxx @@ -0,0 +1,94 @@ +// file : xsde/cxx/parser/non-validating/idrefs-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/pre.hxx> + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/idrefs-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + idrefs_pimpl:: + ~idrefs_pimpl () + { + if (!base_) + delete seq_; + } + + void idrefs_pimpl:: + _reset () + { + idrefs_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + idrefs_pimpl:: + idrefs_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void idrefs_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void idrefs_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + idrefs_pskel::_pre (); + } + + string_sequence* idrefs_pimpl:: + post_idrefs () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre_impl (_context ()); + parser_._characters (s); + parser_._post_impl (); + seq_->push_back (parser_.post_idref ()); + } + } + } + } +} + +#include <xsde/cxx/post.hxx> diff --git a/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.hxx new file mode 100644 index 0000000..193b764 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/non-validating/idrefs-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_STL_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/non-validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_pimpl: virtual idrefs_pskel +#else + struct idrefs_pimpl: idrefs_pskel +#endif + { + ~idrefs_pimpl (); + idrefs_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual string_sequence* + post_idrefs (); + + virtual void + _reset (); + + protected: + bool base_; + idref_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/idrefs.cxx b/libxsde/xsde/cxx/parser/non-validating/idrefs.cxx new file mode 100644 index 0000000..15a6947 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idrefs.cxx @@ -0,0 +1,133 @@ +// file : xsde/cxx/parser/non-validating/idrefs.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/pre.hxx> + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/idrefs.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + idrefs_pimpl:: + ~idrefs_pimpl () + { + if (!base_) + delete seq_; + } + + void idrefs_pimpl:: + _reset () + { + idrefs_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + idrefs_pimpl:: + idrefs_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void idrefs_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void idrefs_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + idrefs_pskel::_pre (); + } + + string_sequence* idrefs_pimpl:: + post_idrefs () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + +#ifdef XSDE_EXCEPTIONS + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre_impl (_context ()); + parser_._characters (s); + parser_._post_impl (); + + // push_back() frees the string if it throws. + // + seq_->push_back (parser_.post_idref ()); + } +#else + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); + + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + char* x = parser_.post_idref (); + + if (!parser_._error_type ()) + { + // push_back() frees the string if it fails. + // + if (seq_->push_back (x)) + _sys_error (sys_error::no_memory); + } + else + parser_._copy_error (ctx); + } + } +#endif + } + } + } +} + +#include <xsde/cxx/post.hxx> diff --git a/libxsde/xsde/cxx/parser/non-validating/idrefs.hxx b/libxsde/xsde/cxx/parser/non-validating/idrefs.hxx new file mode 100644 index 0000000..f3d9b99 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idrefs.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/non-validating/idrefs.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/non-validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_pimpl: virtual idrefs_pskel +#else + struct idrefs_pimpl: idrefs_pskel +#endif + { + ~idrefs_pimpl (); + idrefs_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual string_sequence* + post_idrefs (); + + virtual void + _reset (); + + protected: + bool base_; + idref_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/int.cxx b/libxsde/xsde/cxx/parser/non-validating/int.cxx new file mode 100644 index 0000000..86a9a8b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/int.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void int_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void int_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 11); + } + + int int_pimpl:: + post_int () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/int.hxx b/libxsde/xsde/cxx/parser/non-validating/int.hxx new file mode 100644 index 0000000..8543909 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/int.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_INT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_INT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 32-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct int_pimpl: virtual int_pskel, number +#else + struct int_pimpl: int_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual int + post_int (); + + protected: + // We only need strlen("02147483648") + 1 characters to hold all + // valid and trimmed string representations of int. + // + char str_[12]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_INT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/integer.cxx b/libxsde/xsde/cxx/parser/non-validating/integer.cxx new file mode 100644 index 0000000..dbad0e6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/integer.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN, LONG_MAX + +#include <xsde/cxx/parser/non-validating/integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long integer_pimpl:: + post_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? (ul == static_cast<unsigned long> (LONG_MIN) + ? LONG_MIN : -static_cast<long> (ul)) + : static_cast<long> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/integer.hxx b/libxsde/xsde/cxx/parser/non-validating/integer.hxx new file mode 100644 index 0000000..94e1754 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/integer.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct integer_pimpl: virtual integer_pskel, number +#else + struct integer_pimpl: integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long + post_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/language-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/language-stl.cxx new file mode 100644 index 0000000..80128ea --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/language-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/language-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/language-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void language_pimpl:: + _pre () + { + str_.erase (); + } + + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string language_pimpl:: + post_language () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/language-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/language-stl.hxx new file mode 100644 index 0000000..01dda2d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/language-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/language-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_pimpl: virtual language_pskel +#else + struct language_pimpl: language_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_language (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/language.cxx b/libxsde/xsde/cxx/parser/non-validating/language.cxx new file mode 100644 index 0000000..bcf41b0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/language.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/language.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/language.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void language_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* language_pimpl:: + post_language () + { + ro_string tmp (str_); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/language.hxx b/libxsde/xsde/cxx/parser/non-validating/language.hxx new file mode 100644 index 0000000..cfefe25 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/language.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/language.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_pimpl: virtual language_pskel +#else + struct language_pimpl: language_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_language (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/long-long.cxx b/libxsde/xsde/cxx/parser/non-validating/long-long.cxx new file mode 100644 index 0000000..5501925 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/long-long.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoull + +#include <xsde/cxx/parser/non-validating/long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void long_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long long long_pimpl:: + post_long () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long long ull = strtoull (str_, 0, 10); + + return (sign_ == minus) + ? (ull == 9223372036854775808ULL + ? (-9223372036854775807LL - 1) + : -static_cast<long long> (ull)) + : static_cast<long long> (ull); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/long-long.hxx b/libxsde/xsde/cxx/parser/non-validating/long-long.hxx new file mode 100644 index 0000000..44669d0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/long-long.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_LONG_LONG_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_LONG_LONG_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 64-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_pimpl: virtual long_pskel, number +#else + struct long_pimpl: long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long long + post_long (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long long. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/long.cxx b/libxsde/xsde/cxx/parser/non-validating/long.cxx new file mode 100644 index 0000000..e1a3beb --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/long.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void long_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long long_pimpl:: + post_long () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/long.hxx b/libxsde/xsde/cxx/parser/non-validating/long.hxx new file mode 100644 index 0000000..b51ecd0f --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/long.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_LONG_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_LONG_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_pimpl: virtual long_pskel, number +#else + struct long_pimpl: long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long + post_long (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long long. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/name-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/name-stl.cxx new file mode 100644 index 0000000..65c3e0a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/name-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/name-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/name-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void name_pimpl:: + _pre () + { + str_.erase (); + } + + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string name_pimpl:: + post_name () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/name-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/name-stl.hxx new file mode 100644 index 0000000..75bbf03 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/name-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/name-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NAME_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_pimpl: virtual name_pskel +#else + struct name_pimpl: name_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_name (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/name.cxx b/libxsde/xsde/cxx/parser/non-validating/name.cxx new file mode 100644 index 0000000..bbc7a2e --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/name.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/name.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/name.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void name_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* name_pimpl:: + post_name () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/name.hxx b/libxsde/xsde/cxx/parser/non-validating/name.hxx new file mode 100644 index 0000000..d10d34d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/name.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/name.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NAME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_pimpl: virtual name_pskel +#else + struct name_pimpl: name_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_name (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NAME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/ncname-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/ncname-stl.cxx new file mode 100644 index 0000000..50f2df8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/ncname-stl.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/ncname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/ncname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void ncname_pimpl:: + _pre () + { + str_.erase (); + } + + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string ncname_pimpl:: + post_ncname () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/non-validating/ncname-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/ncname-stl.hxx new file mode 100644 index 0000000..a1a1c69 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/ncname-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/ncname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_pimpl: virtual ncname_pskel +#else + struct ncname_pimpl: ncname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_ncname (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/ncname.cxx b/libxsde/xsde/cxx/parser/non-validating/ncname.cxx new file mode 100644 index 0000000..0fffa19 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/ncname.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/ncname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/ncname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void ncname_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* ncname_pimpl:: + post_ncname () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/ncname.hxx b/libxsde/xsde/cxx/parser/non-validating/ncname.hxx new file mode 100644 index 0000000..61a6a65 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/ncname.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/ncname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_pimpl: virtual ncname_pskel +#else + struct ncname_pimpl: ncname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_ncname (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/negative-integer.cxx b/libxsde/xsde/cxx/parser/non-validating/negative-integer.cxx new file mode 100644 index 0000000..7121020 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/negative-integer.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN + +#include <xsde/cxx/parser/non-validating/negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void negative_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void negative_integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long negative_integer_pimpl:: + post_negative_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long ul = strtoul (str_, 0, 10); + + return (ul == static_cast<unsigned long> (LONG_MIN)) + ? LONG_MIN : -static_cast<long> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/negative-integer.hxx b/libxsde/xsde/cxx/parser/non-validating/negative-integer.hxx new file mode 100644 index 0000000..b7ee9e0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/negative-integer.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length negative integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct negative_integer_pimpl: virtual negative_integer_pskel, number +#else + struct negative_integer_pimpl: negative_integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long + post_negative_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.cxx new file mode 100644 index 0000000..ce9df4b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/nmtoken-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void nmtoken_pimpl:: + _pre () + { + str_.erase (); + } + + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string nmtoken_pimpl:: + post_nmtoken () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.hxx new file mode 100644 index 0000000..770bfba --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/nmtoken-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_pimpl: virtual nmtoken_pskel +#else + struct nmtoken_pimpl: nmtoken_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_nmtoken (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtoken.cxx b/libxsde/xsde/cxx/parser/non-validating/nmtoken.cxx new file mode 100644 index 0000000..63888c7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtoken.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/nmtoken.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void nmtoken_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* nmtoken_pimpl:: + post_nmtoken () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtoken.hxx b/libxsde/xsde/cxx/parser/non-validating/nmtoken.hxx new file mode 100644 index 0000000..a76eead --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtoken.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/nmtoken.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_pimpl: virtual nmtoken_pskel +#else + struct nmtoken_pimpl: nmtoken_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_nmtoken (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.cxx new file mode 100644 index 0000000..5b8186d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.cxx @@ -0,0 +1,90 @@ +// file : xsde/cxx/parser/non-validating/nmtokens-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/nmtokens-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + nmtokens_pimpl:: + ~nmtokens_pimpl () + { + if (!base_) + delete seq_; + } + + void nmtokens_pimpl:: + _reset () + { + nmtokens_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + nmtokens_pimpl:: + nmtokens_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void nmtokens_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void nmtokens_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + nmtokens_pskel::_pre (); + } + + string_sequence* nmtokens_pimpl:: + post_nmtokens () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre_impl (_context ()); + parser_._characters (s); + parser_._post_impl (); + seq_->push_back (parser_.post_nmtoken ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.hxx new file mode 100644 index 0000000..8c90877 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/non-validating/nmtokens-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_STL_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/non-validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_pimpl: virtual nmtokens_pskel +#else + struct nmtokens_pimpl: nmtokens_pskel +#endif + { + ~nmtokens_pimpl (); + nmtokens_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual string_sequence* + post_nmtokens (); + + virtual void + _reset (); + + protected: + bool base_; + nmtoken_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtokens.cxx b/libxsde/xsde/cxx/parser/non-validating/nmtokens.cxx new file mode 100644 index 0000000..4cf41be --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtokens.cxx @@ -0,0 +1,129 @@ +// file : xsde/cxx/parser/non-validating/nmtokens.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/nmtokens.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + nmtokens_pimpl:: + ~nmtokens_pimpl () + { + if (!base_) + delete seq_; + } + + void nmtokens_pimpl:: + _reset () + { + nmtokens_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + nmtokens_pimpl:: + nmtokens_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void nmtokens_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void nmtokens_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + nmtokens_pskel::_pre (); + } + + string_sequence* nmtokens_pimpl:: + post_nmtokens () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + +#ifdef XSDE_EXCEPTIONS + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre_impl (_context ()); + parser_._characters (s); + parser_._post_impl (); + + // push_back() frees the string if it throws. + // + seq_->push_back (parser_.post_nmtoken ()); + } +#else + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); + + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + char* x = parser_.post_nmtoken (); + + if (!parser_._error_type ()) + { + // push_back() frees the string if it fails. + // + if (seq_->push_back (x)) + _sys_error (sys_error::no_memory); + } + else + parser_._copy_error (ctx); + } + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtokens.hxx b/libxsde/xsde/cxx/parser/non-validating/nmtokens.hxx new file mode 100644 index 0000000..f8b3a19 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtokens.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/non-validating/nmtokens.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/non-validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_pimpl: virtual nmtokens_pskel +#else + struct nmtokens_pimpl: nmtokens_pskel +#endif + { + ~nmtokens_pimpl (); + nmtokens_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual string_sequence* + post_nmtokens (); + + virtual void + _reset (); + + protected: + bool base_; + nmtoken_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.cxx b/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.cxx new file mode 100644 index 0000000..463c6c6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/non-negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/non-negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void non_negative_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void non_negative_integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 21); + } + + unsigned long non_negative_integer_pimpl:: + post_non_negative_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return strtoul (str_, 0, 10); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.hxx b/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.hxx new file mode 100644 index 0000000..b7cf3f7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/non-negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length non-negative integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_negative_integer_pimpl: virtual non_negative_integer_pskel, +#else + struct non_negative_integer_pimpl: non_negative_integer_pskel, +#endif + number + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long + post_non_negative_integer (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long, assuming we are on a 64 bit machine. + // + char str_[22]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.cxx b/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.cxx new file mode 100644 index 0000000..c218a77 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/non-positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN + +#include <xsde/cxx/parser/non-validating/non-positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void non_positive_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void non_positive_integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long non_positive_integer_pimpl:: + post_non_positive_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long ul = strtoul (str_, 0, 10); + + return (ul == static_cast<unsigned long> (LONG_MIN)) + ? LONG_MIN : -static_cast<long> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.hxx b/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.hxx new file mode 100644 index 0000000..a6cefab --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/non-positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length non-positive integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_positive_integer_pimpl: virtual non_positive_integer_pskel, +#else + struct non_positive_integer_pimpl: non_positive_integer_pskel, +#endif + number + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long + post_non_positive_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.cxx new file mode 100644 index 0000000..2b1ff1a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/normalized-string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/normalized-string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void normalized_string_pimpl:: + _pre () + { + str_.erase (); + } + + void normalized_string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + std::string normalized_string_pimpl:: + post_normalized_string () + { + std::string::size_type size = str_.size (); + + for (std::string::size_type i = 0; i < size; ++i) + { + char& c = str_[i]; + + if (c == 0x0A || c == 0x0D || c == 0x09) + c = 0x20; + } + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.hxx new file mode 100644 index 0000000..8544ac3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/normalized-string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_pimpl: virtual normalized_string_pskel +#else + struct normalized_string_pimpl: normalized_string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_normalized_string (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/normalized-string.cxx b/libxsde/xsde/cxx/parser/non-validating/normalized-string.cxx new file mode 100644 index 0000000..b00b6c7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/normalized-string.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/non-validating/normalized-string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/normalized-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void normalized_string_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void normalized_string_pimpl:: + _characters (const ro_string& s) + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + + char* normalized_string_pimpl:: + post_normalized_string () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + + for (size_type i = 0; i < size; ++i) + { + char& c = str_[i]; + + if (c == 0x0A || c == 0x0D || c == 0x09) + c = 0x20; + } + + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/normalized-string.hxx b/libxsde/xsde/cxx/parser/non-validating/normalized-string.hxx new file mode 100644 index 0000000..8953729 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/normalized-string.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/normalized-string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_pimpl: virtual normalized_string_pskel +#else + struct normalized_string_pimpl: normalized_string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_normalized_string (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/number.cxx b/libxsde/xsde/cxx/parser/non-validating/number.cxx new file mode 100644 index 0000000..c271ab5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/number.cxx @@ -0,0 +1,127 @@ +// file : xsde/cxx/parser/non-validating/number.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy + +#include <xsde/cxx/parser/non-validating/number.hxx> + +using xsde::cxx::ro_string; + +static bool +trim_leading_zeros (ro_string& s) +{ + ro_string::size_type size = s.size (); + + if (size != 0) + { + const char* f = s.data (); + const char* l = f + size; + const char* of = f; + + while (f < l && *f == '0') + ++f; + + if (f != of) + { + s.assign ((f <= l ? f : 0), (f <= l ? l - f : 0)); + return true; + } + } + + return false; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void number:: + parse (const ro_string& s, char* str, size_t max) + { + ro_string tmp (s.data (), s.size ()); + size_t size = tmp.size (); + + switch (state_) + { + case leading_ws: + { + size = trim_left (tmp); + + if (size != 0) + state_ = sign; + else + break; + // Fall through. + } + case sign: + { + if (tmp[0] == '-') + sign_ = minus; + else if (tmp[0] == '+') + sign_ = plus; + + if (sign_ != none) + tmp.assign (tmp.data () + 1, --size); + + if (size != 0) + state_ = leading_zeros; + else + break; + + // Fall through. + } + case leading_zeros: + { + if (trim_leading_zeros (tmp)) + { + if (size_ == 0) + { + str[0] = '0'; + size_ = 1; + } + + size = tmp.size (); + } + + if (size != 0) + state_ = literal; + else + break; + // Fall through. + } + case literal: + { + // If this chunk is too long then it has to be the last so trim + // trailing ws. + // + if ((max - size_) < size) + { + size = trim_right (tmp); + state_ = trailing_ws; // It either had ws or is too large. + } + + if ((max - size_) >= size) + { + memcpy (str + size_, tmp.data (), size); + size_ += size; + } + + break; + } + case trailing_ws: + { + // We don't really care if it is not. + break; + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/number.hxx b/libxsde/xsde/cxx/parser/non-validating/number.hxx new file mode 100644 index 0000000..793f9b9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/number.hxx @@ -0,0 +1,37 @@ +// file : xsde/cxx/parser/non-validating/number.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NUMBER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NUMBER_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/ro-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + class number + { + protected: + void + parse (const ro_string&, char* str, size_t max); + + protected: + size_t size_; + enum {leading_ws, sign, leading_zeros, literal, trailing_ws} state_; + enum {none, plus, minus} sign_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NUMBER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/parser.cxx b/libxsde/xsde/cxx/parser/non-validating/parser.cxx new file mode 100644 index 0000000..21a15e7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/parser.cxx @@ -0,0 +1,473 @@ +// file : xsde/cxx/parser/non-validating/parser.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <assert.h> + +#include <xsde/cxx/parser/non-validating/parser.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // empty_content + // + +#ifdef XSDE_POLYMORPHIC + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&, + const char*) + { + return false; + } +#else + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&) + { + return false; + } +#endif + + bool empty_content:: + _end_element_impl (const ro_string&, + const ro_string&) + { + return false; + } + + bool empty_content:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool empty_content:: + _characters_impl (const ro_string&) + { + return false; + } + + // + // +#ifdef XSDE_POLYMORPHIC + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (!_start_element_impl (ns, name, type)) + _start_any_element (ns, name, type); + } +#else + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name) + { + if (!_start_element_impl (ns, name)) + _start_any_element (ns, name); + } +#endif + + void empty_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _end_any_element (ns, name); + } + + static const char + xmlns_namespace_[] = "http://www.w3.org/2000/xmlns/"; + + static const char + xsi_namespace_[] = "http://www.w3.org/2001/XMLSchema-instance"; + + static const char + type_[] = "type"; + + static const char + nil_[] = "nil"; + + static const char + schema_location_[] = "schemaLocation"; + + static const char + no_namespace_schema_location_[] = "noNamespaceSchemaLocation"; + + void empty_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + + void empty_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + _any_characters (s); + } + + + // simple_content + // + + void simple_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + + void simple_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + _any_characters (s); + } + + + // complex_content + // + +#ifdef XSDE_POLYMORPHIC + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (!_start_element_impl (ns, name, type)) + { + context& c = _context (); + + c.current_.any_ = true; + c.current_.depth_++; + + _start_any_element (ns, name, type); + } + } +#else + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name) + { + if (!_start_element_impl (ns, name)) + { + context& c = _context (); + + c.current_.any_ = true; + c.current_.depth_++; + + _start_any_element (ns, name); + } + } +#endif + + void complex_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _end_any_element (ns, name); + } + + void complex_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + + void complex_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + _any_characters (s); + } + + void complex_content:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + if (depth_++ == 0) + context_ = &c; + +#ifdef XSDE_EXCEPTIONS + parser_stack_.push (c.current_); +#else + if (parser_stack_.push (c.current_)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + c.current_.parser_ = this; + c.current_.depth_ = 0; + c.current_.any_ = false; + + _pre (); + } + + void complex_content:: + _post_impl () + { +#ifndef XSDE_EXCEPTIONS + if (!context_->error_type ()) +#endif + _post (); + + context_->current_ = parser_stack_.top (); + parser_stack_.pop (); + + if (--depth_ == 0) + context_ = 0; + } + + void complex_content:: + _reset () + { + empty_content::_reset (); + + depth_ = 0; + parser_stack_.clear (); + } + + // list_base + // + + // Find first non-space character. + // + static ro_string::size_type + find_ns (const char* s, + ro_string::size_type size, + ro_string::size_type pos) + { + while (pos < size && + (s[pos] == 0x20 || s[pos] == 0x0A || + s[pos] == 0x0D || s[pos] == 0x09)) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Find first space character. + // + static ro_string::size_type + find_s (const char* s, + ro_string::size_type size, + ro_string::size_type pos) + { + while (pos < size && + s[pos] != 0x20 && s[pos] != 0x0A && + s[pos] != 0x0D && s[pos] != 0x09) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Relevant XML Schema Part 2: Datatypes sections: 4.2.1.2, 4.3.6. + // + + void list_base:: + _pre_impl (context& c) + { + simple_content::_pre_impl (c); + +#ifdef XSDE_EXCEPTIONS + buf_.assign ("", 0); +#else + if (!c.error_type ()) + { + if (buf_.assign ("", 0)) + _sys_error (sys_error::no_memory); + } +#endif + } + + void list_base:: + _characters (const ro_string& s) + { + typedef ro_string::size_type size_type; + + const char* data = s.data (); + size_type size = s.size (); + + // Handle the previous chunk if we start with a ws. + // + if (!buf_.empty () && + (data[0] == 0x20 || data[0] == 0x0A || + data[0] == 0x0D || data[0] == 0x09)) + { + ro_string tmp (buf_); // Private copy ctor. + _xsde_parse_item (tmp); + buf_.assign ("", 0); // Can't fail. + } + +#ifndef XSDE_EXCEPTIONS + context& ctx = _context (); +#endif + + // Traverse the data while logically collapsing spaces. + // + for (size_type i = find_ns (data, size, 0); i != ro_string::npos;) + { + size_type j = find_s (data, size, i); + + if (j != ro_string::npos) + { + if (buf_.empty ()) + { + ro_string tmp (data + i, j - i); // Private copy ctor. + _xsde_parse_item (tmp); + } + else + { + // Assemble the first item in str from buf_ and s. + // + string str; + str.swap (buf_); + +#ifdef XSDE_EXCEPTIONS + str.append (data + i, j - i); +#else + if (str.append (data + i, j - i)) + { + _sys_error (sys_error::no_memory); + break; + } +#endif + ro_string tmp (str); // Private copy ctor. + _xsde_parse_item (tmp); + } + +#ifndef XSDE_EXCEPTIONS + if (ctx.error_type ()) + break; +#endif + + i = find_ns (data, size, j); + } + else + { + // Last fragment, append it to buf_. + // +#ifdef XSDE_EXCEPTIONS + buf_.append (data + i, size - i); +#else + if (buf_.append (data + i, size - i)) + _sys_error (sys_error::no_memory); +#endif + break; + } + } + } + + void list_base:: + _xsde_parse_item (const ro_string&) + { + } + + void list_base:: + _post_impl () + { + // Handle the last item. + // + if (!buf_.empty ()) + { + ro_string tmp (buf_); // Private copy ctor. + _xsde_parse_item (tmp); + } + + simple_content::_post_impl (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/parser.hxx b/libxsde/xsde/cxx/parser/non-validating/parser.hxx new file mode 100644 index 0000000..6b9889a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/parser.hxx @@ -0,0 +1,196 @@ +// file : xsde/cxx/parser/non-validating/parser.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_PARSER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_PARSER_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/cxx/string.hxx> +#include <xsde/cxx/ro-string.hxx> + +#include <xsde/cxx/parser/elements.hxx> +#include <xsde/cxx/parser/state.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + struct empty_content: parser_base + { + // + // +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, + const ro_string&); +#endif + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + + // + // +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string&, + const ro_string&, + const char*); +#else + virtual void + _start_element (const ro_string&, + const ro_string&); +#endif + + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + empty_content (); + empty_content (empty_content* impl, void*); +#endif + }; + + + // + // + struct simple_content: empty_content + { + // + // + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + simple_content (); + simple_content (simple_content* impl, void*); +#endif + }; + + + // + // + struct complex_content: empty_content + { +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string&, + const ro_string&, + const char*); +#else + virtual void + _start_element (const ro_string&, + const ro_string&); +#endif + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + + // + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + + // + // + virtual void + _reset (); + + // + // + complex_content (); + +#ifdef XSDE_REUSE_STYLE_TIEIN + complex_content (complex_content* impl, void*); +#endif + protected: + size_t depth_; + parser_stack parser_stack_; + }; + + // Base for xsd:list. + // + struct list_base: simple_content + { + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _pre_impl (context&); + + virtual void + _characters (const ro_string&); + + virtual void + _post_impl (); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + list_base (); + list_base (list_base* impl, void*); +#endif + protected: + string buf_; + }; + } + } + } +} + +#include <xsde/cxx/parser/non-validating/parser.ixx> + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_PARSER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/parser.ixx b/libxsde/xsde/cxx/parser/non-validating/parser.ixx new file mode 100644 index 0000000..95f085d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/parser.ixx @@ -0,0 +1,77 @@ +// file : xsde/cxx/parser/non-validating/parser.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // empty_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline empty_content:: + empty_content () + { + } + + inline empty_content:: + empty_content (empty_content* impl, void*) + : parser_base (impl, 0) + { + } +#endif + + // simple_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline simple_content:: + simple_content () + { + } + + inline simple_content:: + simple_content (simple_content* impl, void*) + : empty_content (impl, 0) + { + } +#endif + + // complex_content + // + inline complex_content:: + complex_content () + : depth_ (0), parser_stack_ (previous_) + { + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline complex_content:: + complex_content (complex_content* impl, void*) + : empty_content (impl, 0), depth_ (0), parser_stack_ (previous_) + { + } +#endif + + // list_base + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline list_base:: + list_base () + { + } + + inline list_base:: + list_base (list_base* impl, void*) + : simple_content (impl, 0) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/positive-integer.cxx b/libxsde/xsde/cxx/parser/non-validating/positive-integer.cxx new file mode 100644 index 0000000..47f9852 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/positive-integer.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void positive_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void positive_integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 21); + } + + unsigned long positive_integer_pimpl:: + post_positive_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return strtoul (str_, 0, 10); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/positive-integer.hxx b/libxsde/xsde/cxx/parser/non-validating/positive-integer.hxx new file mode 100644 index 0000000..fc326e4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/positive-integer.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_POSITIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length positive integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct positive_integer_pimpl: virtual positive_integer_pskel, number +#else + struct positive_integer_pimpl: positive_integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long + post_positive_integer (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long, assuming we are on a 64 bit machine. + // + char str_[22]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/qname-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/qname-stl.cxx new file mode 100644 index 0000000..746959a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/qname-stl.cxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/parser/non-validating/qname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/qname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void qname_pimpl:: + _pre () + { + str_.erase (); + } + + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + qname qname_pimpl:: + post_qname () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + ro_string::size_type pos = tmp.find (':'); + + if (pos != ro_string::npos) + { + std::string prefix (tmp.data (), pos); + std::string name (tmp.data () + pos + 1, size - pos - 1); + return qname (prefix, name); + } + else + { + str_.resize (size); + return qname (str_); + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/qname-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/qname-stl.hxx new file mode 100644 index 0000000..7671400 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/qname-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/qname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_QNAME_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_QNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_pimpl: virtual qname_pskel +#else + struct qname_pimpl: qname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual qname + post_qname (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_QNAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/qname.cxx b/libxsde/xsde/cxx/parser/non-validating/qname.cxx new file mode 100644 index 0000000..87f03e8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/qname.cxx @@ -0,0 +1,153 @@ +// file : xsde/cxx/parser/non-validating/qname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/qname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + qname_pimpl:: + ~qname_pimpl () + { + if (!base_) + delete qn_; + } + + void qname_pimpl:: + _reset () + { + qname_pskel::_reset (); + + if (!base_) + { + delete qn_; + qn_ = 0; + } + } + + qname_pimpl:: + qname_pimpl (bool base) + : base_ (base), qn_ (0) + { + } + + void qname_pimpl:: + pre_impl (qname* qn) + { + qn_ = qn; + } + + void qname_pimpl:: + _pre () + { + if (qn_ == 0) + { + qn_ = new qname (); + +#ifndef XSDE_EXCEPTIONS + if (qn_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + qname* qname_pimpl:: + post_qname () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + ro_string::size_type pos = tmp.find (':'); + + const char* s = tmp.data (); + + string prefix; + string name; + + if (pos != ro_string::npos) + { +#ifdef XSDE_EXCEPTIONS + prefix.assign (s, pos); + name.assign (s + pos + 1, size - pos - 1); +#else + if (prefix.assign (s, pos) || + name.assign (s + pos + 1, size - pos - 1)) + { + _sys_error (sys_error::no_memory); + return 0; + } +#endif + } + else + { +#ifdef XSDE_EXCEPTIONS + prefix.assign ("", 0); +#else + if (prefix.assign ("", 0)) + { + _sys_error (sys_error::no_memory); + return 0; + } +#endif + str_.truncate (size); + name.swap (str_); + } + + qn_->prefix (prefix.detach ()); + qn_->name (name.detach ()); + + qname* r = qn_; + qn_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/qname.hxx b/libxsde/xsde/cxx/parser/non-validating/qname.hxx new file mode 100644 index 0000000..257eaf4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/qname.hxx @@ -0,0 +1,55 @@ +// file : xsde/cxx/parser/non-validating/qname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_QNAME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_QNAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_pimpl: virtual qname_pskel +#else + struct qname_pimpl: qname_pskel +#endif + { + ~qname_pimpl (); + qname_pimpl (bool base = false); + + void + pre_impl (qname*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual qname* + post_qname (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + qname* qn_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_QNAME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/short.cxx b/libxsde/xsde/cxx/parser/non-validating/short.cxx new file mode 100644 index 0000000..70f401d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/short.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void short_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void short_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 6); + } + + short short_pimpl:: + post_short () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? static_cast<short> (-static_cast<int> (ul)) + : static_cast<short> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/short.hxx b/libxsde/xsde/cxx/parser/non-validating/short.hxx new file mode 100644 index 0000000..8417a94 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/short.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_SHORT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_SHORT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 16-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct short_pimpl: virtual short_pskel, number +#else + struct short_pimpl: short_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual short + post_short (); + + protected: + // We only need strlen("032768") + 1 characters to hold all valid + // and trimmed string representations of short. + // + char str_[7]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_SHORT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/string-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/string-stl.cxx new file mode 100644 index 0000000..7864648 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/string-stl.cxx @@ -0,0 +1,38 @@ +// file : xsde/cxx/parser/non-validating/string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void string_pimpl:: + _pre () + { + str_.erase (); + } + + void string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + std::string string_pimpl:: + post_string () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/string-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/string-stl.hxx new file mode 100644 index 0000000..aaab4ba --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/string-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_STRING_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_pimpl: virtual string_pskel +#else + struct string_pimpl: string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_string (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/string.cxx b/libxsde/xsde/cxx/parser/non-validating/string.cxx new file mode 100644 index 0000000..9d5f083 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/string.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void string_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void string_pimpl:: + _characters (const ro_string& s) + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + + char* string_pimpl:: + post_string () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/string.hxx b/libxsde/xsde/cxx/parser/non-validating/string.hxx new file mode 100644 index 0000000..de48551 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/string.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_STRING_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_STRING_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_pimpl: virtual string_pskel +#else + struct string_pimpl: string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_string (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_STRING_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/time-zone.cxx b/libxsde/xsde/cxx/parser/non-validating/time-zone.cxx new file mode 100644 index 0000000..3465045 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/time-zone.cxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/non-validating/time-zone.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + namespace bits + { + void + parse_time_zone (const char* s, size_t n, short& h, short& m) + { + // time_zone := Z|(+|-)HH:MM + // + if (n == 0) + { + return; + } + else if (s[0] == 'Z') + { + h = 0; + m = 0; + } + else if (n == 6) + { + // Parse hours. + // + h = 10 * (s[1] - '0') + (s[2] - '0'); + + // Parse minutes. + // + m = 10 * (s[4] - '0') + (s[5] - '0'); + + if (s[0] == '-') + { + h = -h; + m = -m; + } + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/time-zone.hxx b/libxsde/xsde/cxx/parser/non-validating/time-zone.hxx new file mode 100644 index 0000000..9a3363c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/time-zone.hxx @@ -0,0 +1,32 @@ +// file : xsde/cxx/parser/non-validating/time-zone.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_TIME_ZONE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_TIME_ZONE_HXX + +#include <stddef.h> // size_t + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + namespace bits + { + void + parse_time_zone (const char* s, + size_t size, + short& hours, + short& minutes); + } + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_TIME_ZONE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/time.cxx b/libxsde/xsde/cxx/parser/non-validating/time.cxx new file mode 100644 index 0000000..a2ad5d3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/time.cxx @@ -0,0 +1,118 @@ +// file : xsde/cxx/parser/non-validating/time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/time.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void time_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + time time_pimpl:: + post_time () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] + // + unsigned short hours = 0; + unsigned short minutes = 0; + double seconds = 0.0; + bool zone = false; + short zh, zm; + + if (n >= 8) + { + // hours + // + hours = 10 * (s[0] - '0') + (s[1] - '0'); + + // minutes + // + minutes = 10 * (s[3] - '0') + (s[4] - '0'); + + // Find the end of the seconds fragment. + // + ro_string::size_type pos = 8; + for (; pos < n; ++pos) + { + char c = s[pos]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // Parse the time zone first so that we can truncate and + // reuse the string. + // + if (pos < n) + { + bits::parse_time_zone (s + pos, n - pos, zh, zm); + zone = true; + } + + // seconds + // + str_.truncate (pos); + seconds = strtod (s + 6, 0); + } + + return zone + ? time (hours, minutes, seconds, zh, zm) + : time (hours, minutes, seconds); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/time.hxx b/libxsde/xsde/cxx/parser/non-validating/time.hxx new file mode 100644 index 0000000..7526414 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/time.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_TIME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_TIME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct time_pimpl: virtual time_pskel +#else + struct time_pimpl: time_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual time + post_time (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_TIME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/token-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/token-stl.cxx new file mode 100644 index 0000000..e975ae3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/token-stl.cxx @@ -0,0 +1,73 @@ +// file : xsde/cxx/parser/non-validating/token-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/token-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void token_pimpl:: + _pre () + { + str_.erase (); + } + + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string token_pimpl:: + post_token () + { + std::string::size_type size = str_.size (); + std::string::size_type j = 0; + + bool subs = false; + + for (std::string::size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = 0x20; + } + + str_[j++] = c; + } + } + + str_.resize (j); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/token-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/token-stl.hxx new file mode 100644 index 0000000..0f3a288 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/token-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/token-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_pimpl: virtual token_pskel +#else + struct token_pimpl: token_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_token (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/token.cxx b/libxsde/xsde/cxx/parser/non-validating/token.cxx new file mode 100644 index 0000000..ffc1b4d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/token.cxx @@ -0,0 +1,94 @@ +// file : xsde/cxx/parser/non-validating/token.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/token.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void token_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* token_pimpl:: + post_token () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + size_type j = 0; + + bool subs = false; + + for (size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = 0x20; + } + + str_[j++] = c; + } + } + + str_.truncate (j); + + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/token.hxx b/libxsde/xsde/cxx/parser/non-validating/token.hxx new file mode 100644 index 0000000..22d9f59 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/token.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/token.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_pimpl: virtual token_pskel +#else + struct token_pimpl: token_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_token (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.cxx new file mode 100644 index 0000000..11e6dd5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/unsigned-byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_byte_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_byte_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 4); + } + + unsigned char unsigned_byte_pimpl:: + post_unsigned_byte () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + return static_cast<unsigned char> (strtoul (str_, 0, 10)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.hxx new file mode 100644 index 0000000..ed54cd0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/unsigned-byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_BYTE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_BYTE_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 8-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_byte_pimpl: virtual unsigned_byte_pskel, number +#else + struct unsigned_byte_pimpl: unsigned_byte_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned char + post_unsigned_byte (); + + protected: + // We only need strlen("0256") + 1 characters to hold all valid + // and trimmed string representations of unsigned byte. + // + char str_[5]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_BYTE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-int.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-int.cxx new file mode 100644 index 0000000..e14e091 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-int.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/unsigned-int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_int_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_int_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 11); + } + + unsigned int unsigned_int_pimpl:: + post_unsigned_int () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return static_cast<unsigned int> (strtoul (str_, 0, 10)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-int.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-int.hxx new file mode 100644 index 0000000..4cce2b0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-int.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/unsigned-int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_INT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_INT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 32-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_int_pimpl: virtual unsigned_int_pskel, number +#else + struct unsigned_int_pimpl: unsigned_int_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned int + post_unsigned_int (); + + protected: + // We only need strlen("04294967295") + 1 characters to hold all + // valid and trimmed string representations of unsigned int. + // + char str_[12]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_INT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.cxx new file mode 100644 index 0000000..908066c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoull + +#include <xsde/cxx/parser/non-validating/unsigned-long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 21); + } + + unsigned long long unsigned_long_pimpl:: + post_unsigned_long () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return strtoull (str_, 0, 10); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.hxx new file mode 100644 index 0000000..8957135 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/unsigned-long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 64-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_pimpl: virtual unsigned_long_pskel, number +#else + struct unsigned_long_pimpl: unsigned_long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long long + post_unsigned_long (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long long. + // + char str_[22]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-long.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-long.cxx new file mode 100644 index 0000000..8f70812 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-long.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/unsigned-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 21); + } + + unsigned long unsigned_long_pimpl:: + post_unsigned_long () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return strtoul (str_, 0, 10); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-long.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-long.hxx new file mode 100644 index 0000000..45c976f --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-long.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/unsigned-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_pimpl: virtual unsigned_long_pskel, number +#else + struct unsigned_long_pimpl: unsigned_long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long + post_unsigned_long (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long long. + // + char str_[22]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-short.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-short.cxx new file mode 100644 index 0000000..2044611 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-short.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/unsigned-short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_short_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_short_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 6); + } + + unsigned short unsigned_short_pimpl:: + post_unsigned_short () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + return static_cast<unsigned short> (strtoul (str_, 0, 10)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-short.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-short.hxx new file mode 100644 index 0000000..26b97ce --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-short.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/unsigned-short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_SHORT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_SHORT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 16-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_short_pimpl: virtual unsigned_short_pskel, number +#else + struct unsigned_short_pimpl: unsigned_short_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned short + post_unsigned_short (); + + protected: + // We only need strlen("065535") + 1 characters to hold all valid + // and trimmed string representations of unsigned short. + // + char str_[7]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_SHORT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/uri-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/uri-stl.cxx new file mode 100644 index 0000000..369f448 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/uri-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/uri-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/uri-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void uri_pimpl:: + _pre () + { + str_.erase (); + } + + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string uri_pimpl:: + post_uri () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/uri-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/uri-stl.hxx new file mode 100644 index 0000000..351c513 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/uri-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/uri-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_URI_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_URI_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_pimpl: virtual uri_pskel +#else + struct uri_pimpl: uri_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_uri (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_URI_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/uri.cxx b/libxsde/xsde/cxx/parser/non-validating/uri.cxx new file mode 100644 index 0000000..2edb794 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/uri.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/uri.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/uri.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void uri_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* uri_pimpl:: + post_uri () + { + ro_string tmp (str_); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/uri.hxx b/libxsde/xsde/cxx/parser/non-validating/uri.hxx new file mode 100644 index 0000000..245c493 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/uri.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/uri.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_URI_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_URI_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_pimpl: virtual uri_pskel +#else + struct uri_pimpl: uri_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_uri (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_URI_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/xml-schema-pimpl.hxx b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pimpl.hxx new file mode 100644 index 0000000..e51cff0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pimpl.hxx @@ -0,0 +1,82 @@ +// file : xsde/cxx/parser/non-validating/xml-schema-pimpl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +#include <xsde/cxx/parser/non-validating/any-type.hxx> +#include <xsde/cxx/parser/non-validating/boolean.hxx> +#include <xsde/cxx/parser/non-validating/byte.hxx> +#include <xsde/cxx/parser/non-validating/unsigned-byte.hxx> +#include <xsde/cxx/parser/non-validating/byte.hxx> +#include <xsde/cxx/parser/non-validating/unsigned-byte.hxx> +#include <xsde/cxx/parser/non-validating/short.hxx> +#include <xsde/cxx/parser/non-validating/unsigned-short.hxx> +#include <xsde/cxx/parser/non-validating/int.hxx> +#include <xsde/cxx/parser/non-validating/unsigned-int.hxx> + +#ifdef XSDE_LONGLONG +# include <xsde/cxx/parser/non-validating/long-long.hxx> +# include <xsde/cxx/parser/non-validating/unsigned-long-long.hxx> +#else +# include <xsde/cxx/parser/non-validating/long.hxx> +# include <xsde/cxx/parser/non-validating/unsigned-long.hxx> +#endif + +#include <xsde/cxx/parser/non-validating/integer.hxx> +#include <xsde/cxx/parser/non-validating/negative-integer.hxx> +#include <xsde/cxx/parser/non-validating/non-positive-integer.hxx> +#include <xsde/cxx/parser/non-validating/positive-integer.hxx> +#include <xsde/cxx/parser/non-validating/non-negative-integer.hxx> +#include <xsde/cxx/parser/non-validating/float.hxx> +#include <xsde/cxx/parser/non-validating/double.hxx> +#include <xsde/cxx/parser/non-validating/decimal.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/parser/non-validating/string-stl.hxx> +# include <xsde/cxx/parser/non-validating/normalized-string-stl.hxx> +# include <xsde/cxx/parser/non-validating/token-stl.hxx> +# include <xsde/cxx/parser/non-validating/name-stl.hxx> +# include <xsde/cxx/parser/non-validating/nmtoken-stl.hxx> +# include <xsde/cxx/parser/non-validating/nmtokens-stl.hxx> +# include <xsde/cxx/parser/non-validating/ncname-stl.hxx> +# include <xsde/cxx/parser/non-validating/id-stl.hxx> +# include <xsde/cxx/parser/non-validating/idref-stl.hxx> +# include <xsde/cxx/parser/non-validating/idrefs-stl.hxx> +# include <xsde/cxx/parser/non-validating/language-stl.hxx> +# include <xsde/cxx/parser/non-validating/uri-stl.hxx> +# include <xsde/cxx/parser/non-validating/qname-stl.hxx> +#else +# include <xsde/cxx/parser/non-validating/string.hxx> +# include <xsde/cxx/parser/non-validating/normalized-string.hxx> +# include <xsde/cxx/parser/non-validating/token.hxx> +# include <xsde/cxx/parser/non-validating/name.hxx> +# include <xsde/cxx/parser/non-validating/nmtoken.hxx> +# include <xsde/cxx/parser/non-validating/nmtokens.hxx> +# include <xsde/cxx/parser/non-validating/ncname.hxx> +# include <xsde/cxx/parser/non-validating/id.hxx> +# include <xsde/cxx/parser/non-validating/idref.hxx> +# include <xsde/cxx/parser/non-validating/idrefs.hxx> +# include <xsde/cxx/parser/non-validating/language.hxx> +# include <xsde/cxx/parser/non-validating/uri.hxx> +# include <xsde/cxx/parser/non-validating/qname.hxx> +#endif + +#include <xsde/cxx/parser/non-validating/base64-binary.hxx> +#include <xsde/cxx/parser/non-validating/hex-binary.hxx> + +#include <xsde/cxx/parser/non-validating/gday.hxx> +#include <xsde/cxx/parser/non-validating/gmonth.hxx> +#include <xsde/cxx/parser/non-validating/gyear.hxx> +#include <xsde/cxx/parser/non-validating/gmonth-day.hxx> +#include <xsde/cxx/parser/non-validating/gyear-month.hxx> +#include <xsde/cxx/parser/non-validating/date.hxx> +#include <xsde/cxx/parser/non-validating/time.hxx> +#include <xsde/cxx/parser/non-validating/date-time.hxx> +#include <xsde/cxx/parser/non-validating/duration.hxx> + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.cxx b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.cxx new file mode 100644 index 0000000..39138a1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.cxx @@ -0,0 +1,612 @@ +// file : xsde/cxx/parser/non-validating/xml-schema-pskel.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // any_type and any_simple_type + // + // In non-validating case we can simply return false from *_impl + // functions which will result in calls to the corresponding + // _any_* callbacks. + // + // + +#ifdef XSDE_POLYMORPHIC + bool any_type_pskel:: + _start_element_impl (const ro_string&, + const ro_string&, + const char*) + { + return false; + } +#else + bool any_type_pskel:: + _start_element_impl (const ro_string&, const ro_string&) + { + return false; + } +#endif + + + bool any_type_pskel:: + _end_element_impl (const ro_string&, const ro_string&) + { + return false; + } + + bool any_type_pskel:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool any_type_pskel:: + _characters_impl (const ro_string&) + { + return false; + } + + void any_type_pskel:: + post_any_type () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_type_impl_) + any_type_impl_->post_any_type (); +#endif + } + + // any_simple_type + // + + bool any_simple_type_pskel:: + _characters_impl (const ro_string&) + { + return false; + } + + void any_simple_type_pskel:: + post_any_simple_type () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_simple_type_impl_) + any_simple_type_impl_->post_any_simple_type (); +#endif + } + + // static/dynamic_type function implementations. + // + +#ifdef XSDE_POLYMORPHIC + const char* any_type_pskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* any_simple_type_pskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* boolean_pskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + const char* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* byte_pskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + const char* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_byte_pskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* short_pskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + const char* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_short_pskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* int_pskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + const char* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_int_pskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* long_pskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + const char* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_long_pskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* integer_pskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + const char* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* negative_integer_pskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_positive_integer_pskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* positive_integer_pskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_negative_integer_pskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* float_pskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + const char* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* double_pskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + const char* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* decimal_pskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + const char* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* string_pskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + const char* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* normalized_string_pskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + const char* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* token_pskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + const char* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* name_pskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + const char* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtoken_pskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtokens_pskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* ncname_pskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + const char* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* id_pskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + const char* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idref_pskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + const char* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idrefs_pskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + const char* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* language_pskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + const char* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* uri_pskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + const char* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* qname_pskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + const char* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* base64_binary_pskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + const char* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* hex_binary_pskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + const char* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gday_pskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_pskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_pskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_day_pskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_month_pskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_pskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + const char* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* time_pskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + const char* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_time_pskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + const char* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* duration_pskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + const char* duration_pskel:: + _dynamic_type () const + { + return _static_type (); + } +#endif // XSDE_POLYMORPHIC + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.hxx b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.hxx new file mode 100644 index 0000000..0792936 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.hxx @@ -0,0 +1,1388 @@ +// file : xsde/cxx/parser/non-validating/xml-schema-pskel.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_STL +# include <string> +#endif + +#include <xsde/cxx/parser/xml-schema.hxx> + +#include <xsde/cxx/parser/non-validating/parser.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // anyType and anySimpleType. All events are routed to the + // _any_* callbacks. + // + + struct any_type_pskel: complex_content + { +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, + const ro_string&); +#endif + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_type (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_type_pskel (); + any_type_pskel (any_type_pskel* impl, void*); + + protected: + any_type_pskel* any_type_impl_; +#endif + }; + + struct any_simple_type_pskel: simple_content + { + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_simple_type (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_simple_type_pskel (); + any_simple_type_pskel (any_simple_type_pskel* impl, void*); + + protected: + any_simple_type_pskel* any_simple_type_impl_; +#endif + }; + + + // Boolean. + // + + struct boolean_pskel: simple_content + { + virtual bool + post_boolean () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + boolean_pskel (); + boolean_pskel (boolean_pskel* impl, void*); + + protected: + boolean_pskel* boolean_impl_; +#endif + }; + + + // 8-bit + // + struct byte_pskel: simple_content + { + virtual signed char + post_byte () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + byte_pskel (); + byte_pskel (byte_pskel* impl, void*); + + protected: + byte_pskel* byte_impl_; +#endif + }; + + struct unsigned_byte_pskel: simple_content + { + virtual unsigned char + post_unsigned_byte () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_byte_pskel (); + unsigned_byte_pskel (unsigned_byte_pskel* impl, void*); + + protected: + unsigned_byte_pskel* unsigned_byte_impl_; +#endif + }; + + + // 16-bit + // + + struct short_pskel: simple_content + { + virtual short + post_short () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + short_pskel (); + short_pskel (short_pskel* impl, void*); + + protected: + short_pskel* short_impl_; +#endif + }; + + struct unsigned_short_pskel: simple_content + { + virtual unsigned short + post_unsigned_short () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_short_pskel (); + unsigned_short_pskel (unsigned_short_pskel* impl, void*); + + protected: + unsigned_short_pskel* unsigned_short_impl_; +#endif + }; + + + // 32-bit + // + + struct int_pskel: simple_content + { + virtual int + post_int () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + int_pskel (); + int_pskel (int_pskel* impl, void*); + + protected: + int_pskel* int_impl_; +#endif + }; + + struct unsigned_int_pskel: simple_content + { + virtual unsigned int + post_unsigned_int () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_int_pskel (); + unsigned_int_pskel (unsigned_int_pskel* impl, void*); + + protected: + unsigned_int_pskel* unsigned_int_impl_; +#endif + }; + + + // 64-bit + // +#ifdef XSDE_LONGLONG + + struct long_pskel: simple_content + { + virtual long long + post_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_pskel (); + long_pskel (long_pskel* impl, void*); + + protected: + long_pskel* long_impl_; +#endif + }; + + struct unsigned_long_pskel: simple_content + { + virtual unsigned long long + post_unsigned_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_pskel (); + unsigned_long_pskel (unsigned_long_pskel* impl, void*); + + protected: + unsigned_long_pskel* unsigned_long_impl_; +#endif + }; + +#else + + struct long_pskel: simple_content + { + virtual long + post_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_pskel (); + long_pskel (long_pskel* impl, void*); + + protected: + long_pskel* long_impl_; +#endif + }; + + struct unsigned_long_pskel: simple_content + { + virtual unsigned long + post_unsigned_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_pskel (); + unsigned_long_pskel (unsigned_long_pskel* impl, void*); + + protected: + unsigned_long_pskel* unsigned_long_impl_; +#endif + }; +#endif + + + // Arbitrary-length integers. + // + + struct integer_pskel: simple_content + { + virtual long + post_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + integer_pskel (); + integer_pskel (integer_pskel* impl, void*); + + protected: + integer_pskel* integer_impl_; +#endif + }; + + struct negative_integer_pskel: simple_content + { + virtual long + post_negative_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + negative_integer_pskel (); + negative_integer_pskel (negative_integer_pskel* impl, void*); + + protected: + negative_integer_pskel* negative_integer_impl_; +#endif + }; + + struct non_positive_integer_pskel: simple_content + { + virtual long + post_non_positive_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_positive_integer_pskel (); + non_positive_integer_pskel (non_positive_integer_pskel* impl, void*); + + protected: + non_positive_integer_pskel* non_positive_integer_impl_; +#endif + }; + + struct positive_integer_pskel: simple_content + { + virtual unsigned long + post_positive_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + positive_integer_pskel (); + positive_integer_pskel (positive_integer_pskel* impl, void*); + + protected: + positive_integer_pskel* positive_integer_impl_; +#endif + }; + + struct non_negative_integer_pskel: simple_content + { + virtual unsigned long + post_non_negative_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_negative_integer_pskel (); + non_negative_integer_pskel (non_negative_integer_pskel* impl, void*); + + protected: + non_negative_integer_pskel* non_negative_integer_impl_; +#endif + }; + + + // Floats. + // + + struct float_pskel: simple_content + { + virtual float + post_float () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + float_pskel (); + float_pskel (float_pskel* impl, void*); + + protected: + float_pskel* float_impl_; +#endif + }; + + struct double_pskel: simple_content + { + virtual double + post_double () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + double_pskel (); + double_pskel (double_pskel* impl, void*); + + protected: + double_pskel* double_impl_; +#endif + }; + + struct decimal_pskel: simple_content + { + virtual double + post_decimal () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + decimal_pskel (); + decimal_pskel (decimal_pskel* impl, void*); + + protected: + decimal_pskel* decimal_impl_; +#endif + }; + + + // String-based types. + // +#ifdef XSDE_STL + + struct string_pskel: simple_content + { + virtual std::string + post_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_pskel (); + string_pskel (string_pskel* impl, void*); + + protected: + string_pskel* string_impl_; +#endif + }; + + struct normalized_string_pskel: simple_content + { + virtual std::string + post_normalized_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_pskel (); + normalized_string_pskel (normalized_string_pskel* impl, void*); + + protected: + normalized_string_pskel* normalized_string_impl_; +#endif + }; + + struct token_pskel: simple_content + { + virtual std::string + post_token () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_pskel (); + token_pskel (token_pskel* impl, void*); + + protected: + token_pskel* token_impl_; +#endif + }; + + struct name_pskel: simple_content + { + virtual std::string + post_name () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_pskel (); + name_pskel (name_pskel* impl, void*); + + protected: + name_pskel* name_impl_; +#endif + }; + + struct nmtoken_pskel: simple_content + { + virtual std::string + post_nmtoken () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_pskel (); + nmtoken_pskel (nmtoken_pskel* impl, void*); + + protected: + nmtoken_pskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_pskel: list_base + { + virtual string_sequence* + post_nmtokens () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_pskel (); + nmtokens_pskel (nmtokens_pskel* impl, void*); + + protected: + nmtokens_pskel* nmtokens_impl_; +#endif + }; + + struct ncname_pskel: simple_content + { + virtual std::string + post_ncname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_pskel (); + ncname_pskel (ncname_pskel* impl, void*); + + protected: + ncname_pskel* ncname_impl_; +#endif + }; + + struct id_pskel: simple_content + { + virtual std::string + post_id () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_pskel (); + id_pskel (id_pskel* impl, void*); + + protected: + id_pskel* id_impl_; +#endif + }; + + struct idref_pskel: simple_content + { + virtual std::string + post_idref () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_pskel (); + idref_pskel (idref_pskel* impl, void*); + + protected: + idref_pskel* idref_impl_; +#endif + }; + + struct idrefs_pskel: list_base + { + virtual string_sequence* + post_idrefs () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_pskel (); + idrefs_pskel (idrefs_pskel* impl, void*); + + protected: + idrefs_pskel* idrefs_impl_; +#endif + }; + + struct language_pskel: simple_content + { + virtual std::string + post_language () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_pskel (); + language_pskel (language_pskel* impl, void*); + + protected: + language_pskel* language_impl_; +#endif + }; + + struct uri_pskel: simple_content + { + virtual std::string + post_uri () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_pskel (); + uri_pskel (uri_pskel* impl, void*); + + protected: + uri_pskel* uri_impl_; +#endif + }; + + struct qname_pskel: simple_content + { + virtual qname + post_qname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_pskel (); + qname_pskel (qname_pskel* impl, void*); + + protected: + qname_pskel* qname_impl_; +#endif + }; + +#else // XSDE_STL + + // Note that in this case you are getting a C string that you + // have to delete with delete[]. + // + + struct string_pskel: simple_content + { + virtual char* + post_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_pskel (); + string_pskel (string_pskel* impl, void*); + + protected: + string_pskel* string_impl_; +#endif + }; + + struct normalized_string_pskel: simple_content + { + virtual char* + post_normalized_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_pskel (); + normalized_string_pskel (normalized_string_pskel* impl, void*); + + protected: + normalized_string_pskel* normalized_string_impl_; +#endif + }; + + struct token_pskel: simple_content + { + virtual char* + post_token () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_pskel (); + token_pskel (token_pskel* impl, void*); + + protected: + token_pskel* token_impl_; +#endif + }; + + struct name_pskel: simple_content + { + virtual char* + post_name () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_pskel (); + name_pskel (name_pskel* impl, void*); + + protected: + name_pskel* name_impl_; +#endif + }; + + struct nmtoken_pskel: simple_content + { + virtual char* + post_nmtoken () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_pskel (); + nmtoken_pskel (nmtoken_pskel* impl, void*); + + protected: + nmtoken_pskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_pskel: list_base + { + virtual string_sequence* + post_nmtokens () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_pskel (); + nmtokens_pskel (nmtokens_pskel* impl, void*); + + protected: + nmtokens_pskel* nmtokens_impl_; +#endif + }; + + struct ncname_pskel: simple_content + { + virtual char* + post_ncname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_pskel (); + ncname_pskel (ncname_pskel* impl, void*); + + protected: + ncname_pskel* ncname_impl_; +#endif + }; + + struct id_pskel: simple_content + { + virtual char* + post_id () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_pskel (); + id_pskel (id_pskel* impl, void*); + + protected: + id_pskel* id_impl_; +#endif + }; + + struct idref_pskel: simple_content + { + virtual char* + post_idref () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_pskel (); + idref_pskel (idref_pskel* impl, void*); + + protected: + idref_pskel* idref_impl_; +#endif + }; + + struct idrefs_pskel: list_base + { + virtual string_sequence* + post_idrefs () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_pskel (); + idrefs_pskel (idrefs_pskel* impl, void*); + + protected: + idrefs_pskel* idrefs_impl_; +#endif + }; + + struct language_pskel: simple_content + { + virtual char* + post_language () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_pskel (); + language_pskel (language_pskel* impl, void*); + + protected: + language_pskel* language_impl_; +#endif + }; + + struct uri_pskel: simple_content + { + virtual char* + post_uri () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_pskel (); + uri_pskel (uri_pskel* impl, void*); + + protected: + uri_pskel* uri_impl_; +#endif + }; + + struct qname_pskel: simple_content + { + virtual qname* + post_qname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_pskel (); + qname_pskel (qname_pskel* impl, void*); + + protected: + qname_pskel* qname_impl_; +#endif + }; +#endif // XSDE_STL + + + // base64Binary + // + struct base64_binary_pskel: simple_content + { + virtual buffer* + post_base64_binary () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + base64_binary_pskel (); + base64_binary_pskel (base64_binary_pskel* impl, void*); + + protected: + base64_binary_pskel* base64_binary_impl_; +#endif + }; + + // hexBinary + // + struct hex_binary_pskel: simple_content + { + virtual buffer* + post_hex_binary () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + hex_binary_pskel (); + hex_binary_pskel (hex_binary_pskel* impl, void*); + + protected: + hex_binary_pskel* hex_binary_impl_; +#endif + }; + + // Time and date types. + // + struct gday_pskel: simple_content + { + virtual gday + post_gday () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gday_pskel (); + gday_pskel (gday_pskel* impl, void*); + + protected: + gday_pskel* gday_impl_; +#endif + }; + + struct gmonth_pskel: simple_content + { + virtual gmonth + post_gmonth () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_pskel (); + gmonth_pskel (gmonth_pskel* impl, void*); + + protected: + gmonth_pskel* gmonth_impl_; +#endif + }; + + struct gyear_pskel: simple_content + { + virtual gyear + post_gyear () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_pskel (); + gyear_pskel (gyear_pskel* impl, void*); + + protected: + gyear_pskel* gyear_impl_; +#endif + }; + + struct gmonth_day_pskel: simple_content + { + virtual gmonth_day + post_gmonth_day () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_day_pskel (); + gmonth_day_pskel (gmonth_day_pskel* impl, void*); + + protected: + gmonth_day_pskel* gmonth_day_impl_; +#endif + }; + + struct gyear_month_pskel: simple_content + { + virtual gyear_month + post_gyear_month () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_month_pskel (); + gyear_month_pskel (gyear_month_pskel* impl, void*); + + protected: + gyear_month_pskel* gyear_month_impl_; +#endif + }; + + struct date_pskel: simple_content + { + virtual date + post_date () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_pskel (); + date_pskel (date_pskel* impl, void*); + + protected: + date_pskel* date_impl_; +#endif + }; + + struct time_pskel: simple_content + { + virtual time + post_time () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + time_pskel (); + time_pskel (time_pskel* impl, void*); + + protected: + time_pskel* time_impl_; +#endif + }; + + struct date_time_pskel: simple_content + { + virtual date_time + post_date_time () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_time_pskel (); + date_time_pskel (date_time_pskel* impl, void*); + + protected: + date_time_pskel* date_time_impl_; +#endif + }; + + struct duration_pskel: simple_content + { + virtual duration + post_duration () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + duration_pskel (); + duration_pskel (duration_pskel* impl, void*); + + protected: + duration_pskel* duration_impl_; +#endif + }; + } + } + } +} + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.ixx> + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.ixx b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.ixx new file mode 100644 index 0000000..220464c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.ixx @@ -0,0 +1,704 @@ +// file : xsde/cxx/parser/non-validating/xml-schema-pskel.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // any_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_type_pskel:: + any_type_pskel () + : any_type_impl_ (0) + { + } + + inline any_type_pskel:: + any_type_pskel (any_type_pskel* impl, void*) + : complex_content (impl, 0), any_type_impl_ (impl) + { + } +#endif + + // any_simple_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_simple_type_pskel:: + any_simple_type_pskel () + : any_simple_type_impl_ (0) + { + } + + inline any_simple_type_pskel:: + any_simple_type_pskel (any_simple_type_pskel* impl, void*) + : simple_content (impl, 0), any_simple_type_impl_ (impl) + { + } +#endif + + // boolean_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline boolean_pskel:: + boolean_pskel () + : boolean_impl_ (0) + { + } + + inline boolean_pskel:: + boolean_pskel (boolean_pskel* impl, void*) + : simple_content (impl, 0), boolean_impl_ (impl) + { + } +#endif + + // byte_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline byte_pskel:: + byte_pskel () + : byte_impl_ (0) + { + } + + inline byte_pskel:: + byte_pskel (byte_pskel* impl, void*) + : simple_content (impl, 0), byte_impl_ (impl) + { + } +#endif + + // unsigned_byte_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_byte_pskel:: + unsigned_byte_pskel () + : unsigned_byte_impl_ (0) + { + } + + inline unsigned_byte_pskel:: + unsigned_byte_pskel (unsigned_byte_pskel* impl, void*) + : simple_content (impl, 0), unsigned_byte_impl_ (impl) + { + } +#endif + + // short_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline short_pskel:: + short_pskel () + : short_impl_ (0) + { + } + + inline short_pskel:: + short_pskel (short_pskel* impl, void*) + : simple_content (impl, 0), short_impl_ (impl) + { + } +#endif + + // unsigned_short_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_short_pskel:: + unsigned_short_pskel () + : unsigned_short_impl_ (0) + { + } + + inline unsigned_short_pskel:: + unsigned_short_pskel (unsigned_short_pskel* impl, void*) + : simple_content (impl, 0), unsigned_short_impl_ (impl) + { + } +#endif + + // int_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline int_pskel:: + int_pskel () + : int_impl_ (0) + { + } + + inline int_pskel:: + int_pskel (int_pskel* impl, void*) + : simple_content (impl, 0), int_impl_ (impl) + { + } +#endif + + // unsigned_int_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_int_pskel:: + unsigned_int_pskel () + : unsigned_int_impl_ (0) + { + } + + inline unsigned_int_pskel:: + unsigned_int_pskel (unsigned_int_pskel* impl, void*) + : simple_content (impl, 0), unsigned_int_impl_ (impl) + { + } +#endif + + // long_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline long_pskel:: + long_pskel () + : long_impl_ (0) + { + } + + inline long_pskel:: + long_pskel (long_pskel* impl, void*) + : simple_content (impl, 0), long_impl_ (impl) + { + } +#endif + + // unsigned_long_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_long_pskel:: + unsigned_long_pskel () + : unsigned_long_impl_ (0) + { + } + + inline unsigned_long_pskel:: + unsigned_long_pskel (unsigned_long_pskel* impl, void*) + : simple_content (impl, 0), unsigned_long_impl_ (impl) + { + } +#endif + + // integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline integer_pskel:: + integer_pskel () + : integer_impl_ (0) + { + } + + inline integer_pskel:: + integer_pskel (integer_pskel* impl, void*) + : simple_content (impl, 0), integer_impl_ (impl) + { + } +#endif + + // negative_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline negative_integer_pskel:: + negative_integer_pskel () + : negative_integer_impl_ (0) + { + } + + inline negative_integer_pskel:: + negative_integer_pskel (negative_integer_pskel* impl, void*) + : simple_content (impl, 0), negative_integer_impl_ (impl) + { + } +#endif + + // non_positive_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_positive_integer_pskel:: + non_positive_integer_pskel () + : non_positive_integer_impl_ (0) + { + } + + inline non_positive_integer_pskel:: + non_positive_integer_pskel (non_positive_integer_pskel* impl, void*) + : simple_content (impl, 0), non_positive_integer_impl_ (impl) + { + } +#endif + + // positive_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline positive_integer_pskel:: + positive_integer_pskel () + : positive_integer_impl_ (0) + { + } + + inline positive_integer_pskel:: + positive_integer_pskel (positive_integer_pskel* impl, void*) + : simple_content (impl, 0), positive_integer_impl_ (impl) + { + } +#endif + + // non_negative_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_negative_integer_pskel:: + non_negative_integer_pskel () + : non_negative_integer_impl_ (0) + { + } + + inline non_negative_integer_pskel:: + non_negative_integer_pskel (non_negative_integer_pskel* impl, void*) + : simple_content (impl, 0), non_negative_integer_impl_ (impl) + { + } +#endif + + // float_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline float_pskel:: + float_pskel () + : float_impl_ (0) + { + } + + inline float_pskel:: + float_pskel (float_pskel* impl, void*) + : simple_content (impl, 0), float_impl_ (impl) + { + } +#endif + + // double_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline double_pskel:: + double_pskel () + : double_impl_ (0) + { + } + + inline double_pskel:: + double_pskel (double_pskel* impl, void*) + : simple_content (impl, 0), double_impl_ (impl) + { + } +#endif + + // decimal_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline decimal_pskel:: + decimal_pskel () + : decimal_impl_ (0) + { + } + + inline decimal_pskel:: + decimal_pskel (decimal_pskel* impl, void*) + : simple_content (impl, 0), decimal_impl_ (impl) + { + } +#endif + + // string_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline string_pskel:: + string_pskel () + : string_impl_ (0) + { + } + + inline string_pskel:: + string_pskel (string_pskel* impl, void*) + : simple_content (impl, 0), string_impl_ (impl) + { + } +#endif + + // normalized_string_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline normalized_string_pskel:: + normalized_string_pskel () + : normalized_string_impl_ (0) + { + } + + inline normalized_string_pskel:: + normalized_string_pskel (normalized_string_pskel* impl, void*) + : simple_content (impl, 0), normalized_string_impl_ (impl) + { + } +#endif + + // token_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline token_pskel:: + token_pskel () + : token_impl_ (0) + { + } + + inline token_pskel:: + token_pskel (token_pskel* impl, void*) + : simple_content (impl, 0), token_impl_ (impl) + { + } +#endif + + // name_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline name_pskel:: + name_pskel () + : name_impl_ (0) + { + } + + inline name_pskel:: + name_pskel (name_pskel* impl, void*) + : simple_content (impl, 0), name_impl_ (impl) + { + } +#endif + + // nmtoken_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtoken_pskel:: + nmtoken_pskel () + : nmtoken_impl_ (0) + { + } + + inline nmtoken_pskel:: + nmtoken_pskel (nmtoken_pskel* impl, void*) + : simple_content (impl, 0), nmtoken_impl_ (impl) + { + } +#endif + + // nmtokens_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtokens_pskel:: + nmtokens_pskel () + : nmtokens_impl_ (0) + { + } + + inline nmtokens_pskel:: + nmtokens_pskel (nmtokens_pskel* impl, void*) + : list_base (impl, 0), nmtokens_impl_ (impl) + { + } +#endif + + // ncname_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline ncname_pskel:: + ncname_pskel () + : ncname_impl_ (0) + { + } + + inline ncname_pskel:: + ncname_pskel (ncname_pskel* impl, void*) + : simple_content (impl, 0), ncname_impl_ (impl) + { + } +#endif + + // id_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline id_pskel:: + id_pskel () + : id_impl_ (0) + { + } + + inline id_pskel:: + id_pskel (id_pskel* impl, void*) + : simple_content (impl, 0), id_impl_ (impl) + { + } +#endif + + // idref_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idref_pskel:: + idref_pskel () + : idref_impl_ (0) + { + } + + inline idref_pskel:: + idref_pskel (idref_pskel* impl, void*) + : simple_content (impl, 0), idref_impl_ (impl) + { + } +#endif + + // idrefs_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idrefs_pskel:: + idrefs_pskel () + : idrefs_impl_ (0) + { + } + + inline idrefs_pskel:: + idrefs_pskel (idrefs_pskel* impl, void*) + : list_base (impl, 0), idrefs_impl_ (impl) + { + } +#endif + + // language_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline language_pskel:: + language_pskel () + : language_impl_ (0) + { + } + + inline language_pskel:: + language_pskel (language_pskel* impl, void*) + : simple_content (impl, 0), language_impl_ (impl) + { + } +#endif + + // uri_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline uri_pskel:: + uri_pskel () + : uri_impl_ (0) + { + } + + inline uri_pskel:: + uri_pskel (uri_pskel* impl, void*) + : simple_content (impl, 0), uri_impl_ (impl) + { + } +#endif + + // qname_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline qname_pskel:: + qname_pskel () + : qname_impl_ (0) + { + } + + inline qname_pskel:: + qname_pskel (qname_pskel* impl, void*) + : simple_content (impl, 0), qname_impl_ (impl) + { + } +#endif + + // base64_binary_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline base64_binary_pskel:: + base64_binary_pskel () + : base64_binary_impl_ (0) + { + } + + inline base64_binary_pskel:: + base64_binary_pskel (base64_binary_pskel* impl, void*) + : simple_content (impl, 0), base64_binary_impl_ (impl) + { + } +#endif + + // hex_binary_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline hex_binary_pskel:: + hex_binary_pskel () + : hex_binary_impl_ (0) + { + } + + inline hex_binary_pskel:: + hex_binary_pskel (hex_binary_pskel* impl, void*) + : simple_content (impl, 0), hex_binary_impl_ (impl) + { + } +#endif + + // gday_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gday_pskel:: + gday_pskel () + : gday_impl_ (0) + { + } + + inline gday_pskel:: + gday_pskel (gday_pskel* impl, void*) + : simple_content (impl, 0), gday_impl_ (impl) + { + } +#endif + + // gmonth_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_pskel:: + gmonth_pskel () + : gmonth_impl_ (0) + { + } + + inline gmonth_pskel:: + gmonth_pskel (gmonth_pskel* impl, void*) + : simple_content (impl, 0), gmonth_impl_ (impl) + { + } +#endif + + // gyear_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_pskel:: + gyear_pskel () + : gyear_impl_ (0) + { + } + + inline gyear_pskel:: + gyear_pskel (gyear_pskel* impl, void*) + : simple_content (impl, 0), gyear_impl_ (impl) + { + } +#endif + + // gmonth_day_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_day_pskel:: + gmonth_day_pskel () + : gmonth_day_impl_ (0) + { + } + + inline gmonth_day_pskel:: + gmonth_day_pskel (gmonth_day_pskel* impl, void*) + : simple_content (impl, 0), gmonth_day_impl_ (impl) + { + } +#endif + + // gyear_month_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_month_pskel:: + gyear_month_pskel () + : gyear_month_impl_ (0) + { + } + + inline gyear_month_pskel:: + gyear_month_pskel (gyear_month_pskel* impl, void*) + : simple_content (impl, 0), gyear_month_impl_ (impl) + { + } +#endif + + // date_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_pskel:: + date_pskel () + : date_impl_ (0) + { + } + + inline date_pskel:: + date_pskel (date_pskel* impl, void*) + : simple_content (impl, 0), date_impl_ (impl) + { + } +#endif + + // time_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline time_pskel:: + time_pskel () + : time_impl_ (0) + { + } + + inline time_pskel:: + time_pskel (time_pskel* impl, void*) + : simple_content (impl, 0), time_impl_ (impl) + { + } +#endif + + // date_time_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_time_pskel:: + date_time_pskel () + : date_time_impl_ (0) + { + } + + inline date_time_pskel:: + date_time_pskel (date_time_pskel* impl, void*) + : simple_content (impl, 0), date_time_impl_ (impl) + { + } +#endif + + // duration_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline duration_pskel:: + duration_pskel () + : duration_impl_ (0) + { + } + + inline duration_pskel:: + duration_pskel (duration_pskel* impl, void*) + : simple_content (impl, 0), duration_impl_ (impl) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/state.cxx b/libxsde/xsde/cxx/parser/state.cxx new file mode 100644 index 0000000..756190e --- /dev/null +++ b/libxsde/xsde/cxx/parser/state.cxx @@ -0,0 +1,37 @@ +// file : xsde/cxx/parser/state.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy + +#include <xsde/cxx/parser/state.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + stack::error stack:: + grow () + { + size_t c = capacity_ ? capacity_ * 2 : 8; + char* d = new char[c * el_size_]; + + if (d == 0) + return error_no_memory; + + if (size_ > 1) + memcpy (d, data_, (size_ - 1) * el_size_); + + delete[] data_; + + data_ = d; + capacity_ = c; + + return error_none; + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/state.hxx b/libxsde/xsde/cxx/parser/state.hxx new file mode 100644 index 0000000..11ace8d --- /dev/null +++ b/libxsde/xsde/cxx/parser/state.hxx @@ -0,0 +1,89 @@ +// file : xsde/cxx/parser/state.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_STATE_HXX +#define XSDE_CXX_PARSER_STATE_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/parser/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // POD stack with pre-allocated first element. You may + // need to pad your elements to get the proper alignment. + // + struct stack + { + enum error + { + error_none, + error_no_memory + }; + + ~stack (); + stack (size_t element_size, void* first_element); + + public: + void + pop (); + + error + push (); + + void* + top (); + + size_t + element_size () const; + + void + clear (); + + private: + error + grow (); + + private: + size_t el_size_; + void* first_; + char* data_; + size_t size_; + size_t capacity_; + }; + + // Optimized state stack for non-recursive case (one element). + // + struct parser_stack + { + parser_stack (parser_state& first); + + stack::error + push (parser_state&); + + void + pop (); + + parser_state& + top (); + + void + clear (); + + private: + stack stack_; + }; + } + } +} + + +#include <xsde/cxx/parser/state.ixx> + +#endif // XSDE_CXX_PARSER_STATE_HXX diff --git a/libxsde/xsde/cxx/parser/state.ixx b/libxsde/xsde/cxx/parser/state.ixx new file mode 100644 index 0000000..6f9c4b7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/state.ixx @@ -0,0 +1,102 @@ +// file : xsde/cxx/parser/state.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // stack + // + + inline stack:: + ~stack () + { + delete[] data_; + } + + inline stack:: + stack (size_t el_size, void* first_el) + : el_size_ (el_size), first_ (first_el), + data_ (0), size_ (0), capacity_ (0) + { + } + + inline void stack:: + pop () + { + --size_; + } + + inline stack::error stack:: + push () + { + if (size_ > capacity_) + if (error e = grow ()) + return e; + + ++size_; + + return error_none; + } + + inline void* stack:: + top () + { + return size_ == 1 ? first_ : data_ + (size_ - 1) * el_size_; + } + + inline size_t stack:: + element_size () const + { + return el_size_; + } + + inline void stack:: + clear () + { + size_ = 0; + } + + // parser_stack + // + inline parser_stack:: + parser_stack (parser_state& first) + : stack_ (sizeof (parser_state), &first) + { + } + + inline stack::error parser_stack:: + push (parser_state& s) + { + if (stack::error e = stack_.push ()) + return e; + + *static_cast<parser_state*> (stack_.top ()) = s; + return stack::error_none; + } + + inline void parser_stack:: + pop () + { + stack_.pop (); + } + + inline parser_state& parser_stack:: + top () + { + return *static_cast<parser_state*> (stack_.top ()); + } + + inline void parser_stack:: + clear () + { + stack_.clear (); + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/substitution-map-load.hxx b/libxsde/xsde/cxx/parser/substitution-map-load.hxx new file mode 100644 index 0000000..4efa2ad --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map-load.hxx @@ -0,0 +1,31 @@ +// file : xsde/cxx/parser/substitution-map-load.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_SUBSTITUTION_MAP_LOAD_HXX +#define XSDE_CXX_PARSER_SUBSTITUTION_MAP_LOAD_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + size_t + parser_smap_elements (); + + inline size_t + parser_smap_buckets () + { + return XSDE_PARSER_SMAP_BUCKETS; + } + } + } +} + +#endif // XSDE_CXX_PARSER_SUBSTITUTION_MAP_LOAD_HXX diff --git a/libxsde/xsde/cxx/parser/substitution-map.cxx b/libxsde/xsde/cxx/parser/substitution-map.cxx new file mode 100644 index 0000000..950d07d --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map.cxx @@ -0,0 +1,236 @@ +// file : xsde/cxx/parser/substitution-map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <string.h> // strlen, strcmp, strncmp + +#ifndef XSDE_EXCEPTIONS +# include <assert.h> // assert +# include <stdlib.h> // exit +#endif + +#include <xsde/cxx/parser/substitution-map.hxx> +#include <xsde/cxx/parser/substitution-map-load.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + substitution_map* substitution_map_init::map = 0; + size_t substitution_map_init::count = 0; + + bool substitution_map:: + check_ (const ro_string& ns, + const ro_string& name, + const char* root, + const char** type) const + { + bool r = false; + + if (const value* v = find_ (ns, name)) + { + if (strcmp (root, v->root_) == 0) + r = true; + else + r = check_ (v->root_, root); + + if (r && type != 0 && *type == 0) + *type = v->type_; + } + + return r; + } + + bool substitution_map:: + check_ (const ro_string& ns, + const ro_string& name, + const char* root_ns, + const char* root_name, + const char** type) const + { + bool r = false; + + if (const value* v = find_ (ns, name)) + { + if (root_ns == 0) + r = strcmp (v->root_, root_name) == 0; + else + { + size_t n = strlen (root_name); + + r = strncmp (v->root_, root_name, n) == 0 && v->root_[n] == ' ' && + strcmp (v->root_ + n + 1, root_ns) == 0; + } + + if (!r) + r = check_ (v->root_, root_ns, root_name); + + if (r && type != 0 && *type == 0) + *type = v->type_; + } + + return r; + } + + bool substitution_map:: + check_ (const char* member, const char* root) const + { + const value* v = static_cast<const value*> (find (member)); + + if (v == 0) + return false; + + return strcmp (root, v->root_) == 0 ? true : check_ (v->root_, root); + } + + bool substitution_map:: + check_ (const char* member, + const char* root_ns, + const char* root_name) const + { + const value* v = static_cast<const value*> (find (member)); + + if (v == 0) + return false; + + bool r; + + if (root_ns == 0) + r = strcmp (v->root_, root_name) == 0; + else + { + size_t n = strlen (root_name); + + r = strncmp (v->root_, root_name, n) == 0 && v->root_[n] == ' ' && + strcmp (v->root_ + n + 1, root_ns) == 0; + } + + return r ? true : check_ (v->root_, root_ns, root_name); + } + + const substitution_map::value* substitution_map:: + find_ (const ro_string& ns, const ro_string& name) const + { + bool q = !ns.empty (); + size_t h = hash (name.data (), name.size ()); + + if (q) + { + h = hash (h, " ", 1); + h = hash (h, ns.data (), ns.size ()); + } + + const bucket* p = find (h); + + if (p == 0) + return 0; + + // Search for the entry in the bucket. + // + const size_t el_size = sizeof (element) + sizeof (value); + const char* b = reinterpret_cast<const char*> (p) + sizeof (bucket); + const char* e = b + p->size_ * el_size; + + for (; b < e; b += el_size) + { + const element* e = reinterpret_cast<const element*> (b); + + if (e->hash_ == h) + { + if (!q) + { + if (strlen (e->key_) == name.size () && + strncmp (e->key_, name.data (), name.size ()) == 0) + break; + } + else + { + size_t n = name.size (); + + if (strncmp (e->key_, name.data (), n) == 0 && + e->key_[n] == ' ' && + strlen (e->key_ + n + 1) == ns.size () && + strncmp (e->key_ + n + 1, ns.data (), ns.size ()) == 0) + break; + } + } + } + + if (b == e) + return 0; + + return reinterpret_cast<const value*> (b + sizeof (element)); + } + + // substitution_map_init + // + substitution_map_init:: + substitution_map_init () + { + if (count == 0) + { + map = new substitution_map (XSDE_PARSER_SMAP_BUCKETS); + +#ifndef XSDE_EXCEPTIONS + if (map == 0 || map->_error () != substitution_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + ++count; + } + + substitution_map_init:: + ~substitution_map_init () + { + if (--count == 0) + delete map; + } + + // substitution_map_entry + // + substitution_map_entry:: + substitution_map_entry (const char* member, + const char* root, + const char* type) + { + substitution_map& m = substitution_map_instance (); + m.insert (member, root, type); + +#ifndef XSDE_EXCEPTIONS + if (m._error () != substitution_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + // + // + size_t + parser_smap_elements () + { + return substitution_map_instance ().size (); + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/substitution-map.hxx b/libxsde/xsde/cxx/parser/substitution-map.hxx new file mode 100644 index 0000000..14586c1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map.hxx @@ -0,0 +1,115 @@ +// file : xsde/cxx/parser/substitution-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_SUBSTITUTION_MAP_HXX +#define XSDE_CXX_PARSER_SUBSTITUTION_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> +#include <xsde/cxx/hashmap.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + struct substitution_map: hashmap + { + substitution_map (size_t buckets); + + void + insert (const char* member, + const char* root, + const char* type); + + // Check and have the type set if found. + // + bool + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root, + const char*& type) const; + + bool + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root_ns, // 0 if no namespace + const char* root_name, + const char*& type) const; + + // Check but don't care about the type. + // + bool + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root) const; + + private: + struct value + { + const char* root_; + const char* type_; + }; + + private: + bool + check_ (const ro_string& member_ns, + const ro_string& member_name, + const char* root, + const char** type) const; + + bool + check_ (const ro_string& member_ns, + const ro_string& member_name, + const char* root_ns, + const char* root_name, + const char** type) const; + + bool + check_ (const char* member, const char* root) const; + + bool + check_ (const char* member, + const char* root_ns, + const char* root_name) const; + + const value* + find_ (const ro_string& member_ns, + const ro_string& member_name) const; + }; + + + // Translation unit initializer. + // + struct substitution_map_init + { + static substitution_map* map; + static size_t count; + + substitution_map_init (); + ~substitution_map_init (); + }; + + substitution_map& + substitution_map_instance (); + + // Map entry initializer. + // + struct substitution_map_entry + { + substitution_map_entry (const char* member, + const char* root, + const char* type); + }; + } + } +} + +#include <xsde/cxx/parser/substitution-map.ixx> + +#endif // XSDE_CXX_PARSER_SUBSTITUTION_MAP_HXX diff --git a/libxsde/xsde/cxx/parser/substitution-map.ixx b/libxsde/xsde/cxx/parser/substitution-map.ixx new file mode 100644 index 0000000..a45b5d4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map.ixx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/substitution-map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + inline substitution_map:: + substitution_map (size_t buckets) + : hashmap (buckets, sizeof (value)) + { + } + + inline void substitution_map:: + insert (const char* member, + const char* root, + const char* type) + { + value v; + v.root_ = root; + v.type_ = type; + hashmap::insert (member, &v); + } + + inline bool substitution_map:: + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root, + const char*& type) const + { + + return empty () + ? false + : check_ (member_ns, member_name, root, &type); + } + + inline bool substitution_map:: + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root_ns, + const char* root_name, + const char*& type) const + { + return empty () + ? false + : check_ (member_ns, member_name, root_ns, root_name, &type); + } + + inline bool substitution_map:: + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root) const + { + + return empty () + ? false + : check_ (member_ns, member_name, root, 0); + } + + inline substitution_map& + substitution_map_instance () + { + return *substitution_map_init::map; + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/any-type.hxx b/libxsde/xsde/cxx/parser/validating/any-type.hxx new file mode 100644 index 0000000..6f183d4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/any-type.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/parser/validating/any-type.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_ANY_TYPE_HXX +#define XSDE_CXX_PARSER_VALIDATING_ANY_TYPE_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_type_pimpl: virtual any_type_pskel +#else + struct any_type_pimpl: any_type_pskel +#endif + { + }; + + // any_simple_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_simple_type_pimpl: virtual any_simple_type_pskel +#else + struct any_simple_type_pimpl: any_simple_type_pskel +#endif + { + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_ANY_TYPE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/base64-binary.cxx b/libxsde/xsde/cxx/parser/validating/base64-binary.cxx new file mode 100644 index 0000000..994c14b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/base64-binary.cxx @@ -0,0 +1,281 @@ +// file : xsde/cxx/parser/validating/base64-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/base64-binary.hxx> + +static unsigned char +base64_decode (char c) +{ + unsigned char r = 0xFF; + + if (c >= 'A' && c <= 'Z') + r = static_cast<unsigned char> (c - 'A'); + else if (c >= 'a' && c <= 'z') + r = static_cast<unsigned char> (c - 'a' + 26); + else if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0' + 52); + else if (c == '+') + r = 62; + else if (c == '/') + r = 63; + + return r; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + base64_binary_pimpl:: + ~base64_binary_pimpl () + { + if (!base_) + delete buf_; + } + + void base64_binary_pimpl:: + _reset () + { + base64_binary_pskel::_reset (); + + if (!base_) + { + delete buf_; + buf_ = 0; + } + } + + base64_binary_pimpl:: + base64_binary_pimpl (bool base) + : base_ (base), buf_ (0) + { + } + + void base64_binary_pimpl:: + pre_impl (buffer* b) + { + buf_ = b; + } + + void base64_binary_pimpl:: + _pre () + { + if (buf_ == 0) + { + buf_ = new buffer (); + +#ifndef XSDE_EXCEPTIONS + if (buf_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void base64_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void base64_binary_pimpl:: + _post () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + const char* src = str_.data (); + + // Remove all whitespaces. + // + { + size_type j = 0; + bool subs = false; + + for (size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + subs = false; + + str_[j++] = c; + } + } + + size = j; + str_.truncate (size); + } + + // Our length should be a multiple of four. + // + if (size == 0 || size % 4 != 0) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + size_type quad_count = size / 4; + size_type capacity = quad_count * 3 + 1; + +#ifdef XSDE_EXCEPTIONS + buf_->size (capacity); +#else + if (buf_->size (capacity)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + char* dst = buf_->data (); + + // Source and destination indexes. + // + size_type si = 0; + size_type di = 0; + + // Process all quads except the last one. + // + unsigned char b1, b2, b3, b4; + + for (size_type q = 0; q < quad_count - 1; ++q) + { + b1 = base64_decode (src[si++]); + b2 = base64_decode (src[si++]); + b3 = base64_decode (src[si++]); + b4 = base64_decode (src[si++]); + + if (b1 == 0xFF || b2 == 0xFF || b3 == 0xFF || b4 == 0xFF) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Process the last quad. The first two octets are always there. + // + b1 = base64_decode (src[si++]); + b2 = base64_decode (src[si++]); + + if (b1 == 0xFF || b2 == 0xFF) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + char e3 = src[si++]; + char e4 = src[si++]; + + if (e4 == '=') + { + if (e3 == '=') + { + // Two pads. Last 4 bits in b2 should be zero. + // + if ((b2 & 0x0F) != 0) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + dst[di++] = (b1 << 2) | (b2 >> 4); + } + else + { + // One pad. Last 2 bits in b3 should be zero. + // + b3 = base64_decode (e3); + + if (b3 == 0xFF || (b3 & 0x03) != 0) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + } + } + else + { + // No pads. + // + b3 = base64_decode (e3); + b4 = base64_decode (e4); + + if (b3 == 0xFF || b4 == 0xFF) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Set the real size. + // + buf_->size (di); + } + + buffer* base64_binary_pimpl:: + post_base64_binary () + { + buffer* r = buf_; + buf_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/base64-binary.hxx b/libxsde/xsde/cxx/parser/validating/base64-binary.hxx new file mode 100644 index 0000000..656bf9b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/base64-binary.hxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/parser/validating/base64-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_BASE64_BINARY_HXX +#define XSDE_CXX_PARSER_VALIDATING_BASE64_BINARY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct base64_binary_pimpl: virtual base64_binary_pskel +#else + struct base64_binary_pimpl: base64_binary_pskel +#endif + { + ~base64_binary_pimpl (); + base64_binary_pimpl (bool base = false); + + void + pre_impl (buffer*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual buffer* + post_base64_binary (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + buffer* buf_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_BASE64_BINARY_HXX diff --git a/libxsde/xsde/cxx/parser/validating/boolean.cxx b/libxsde/xsde/cxx/parser/validating/boolean.cxx new file mode 100644 index 0000000..80d88f8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/boolean.cxx @@ -0,0 +1,93 @@ +// file : xsde/cxx/parser/validating/boolean.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/boolean.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void boolean_pimpl:: + _pre () + { + size_ = 0; + state_ = leading_ws; + } + + void boolean_pimpl:: + _characters (const ro_string& s) + { + ro_string tmp (s.data (), s.size ()); + + size_t size = tmp.size (); + + switch (state_) + { + case leading_ws: + { + size = trim_left (tmp); + + if (size != 0) + state_ = literal; + else + break; + // Fall through. + } + case literal: + { + // If this chunk is too long then it has to be the last so trim + // trailing ws. + // + if ((5 - size_) < size) + { + size = trim_right (tmp); + state_ = trailing_ws; // It either had ws or is too large. + } + + if ((5 - size_) >= size) + { + memcpy (str_ + size_, tmp.data (), size); + size_ += size; + } + else + _schema_error (schema_error::invalid_boolean_value); + + break; + } + case trailing_ws: + { + if (trim_left (tmp) != 0) + _schema_error (schema_error::invalid_boolean_value); + } + } + } + + void boolean_pimpl:: + _post () + { + ro_string tmp (str_, size_); + trim_right (tmp); + + if (tmp == "1" || tmp == "true") + value_ = true; + else if (tmp == "0" || tmp == "false") + value_ = false; + else + _schema_error (schema_error::invalid_boolean_value); + } + + bool boolean_pimpl:: + post_boolean () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/boolean.hxx b/libxsde/xsde/cxx/parser/validating/boolean.hxx new file mode 100644 index 0000000..81c1e29 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/boolean.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/validating/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_BOOLEAN_HXX +#define XSDE_CXX_PARSER_VALIDATING_BOOLEAN_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct boolean_pimpl: virtual boolean_pskel +#else + struct boolean_pimpl: boolean_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual bool + post_boolean (); + + protected: + // We only need strlen("false") + 1 characters to hold all valid + // and trimmed string representations of boolean. + // + char str_[6]; + size_t size_; + enum { leading_ws, literal, trailing_ws } state_; + + bool value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_BOOLEAN_HXX diff --git a/libxsde/xsde/cxx/parser/validating/byte.cxx b/libxsde/xsde/cxx/parser/validating/byte.cxx new file mode 100644 index 0000000..a18c26a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/byte.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/validating/byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/validating/byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void byte_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void byte_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 4)) + _schema_error (schema_error::invalid_byte_value); + } + + void byte_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + // No need to check errno since our string representation + // can never overflow an unsigned long. + // + char* p; + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || (neg && ul > 128) || (!neg && ul > 127)) + _schema_error (schema_error::invalid_byte_value); + + value_ = neg + ? static_cast<signed char> (-static_cast<short> (ul)) + : static_cast<signed char> (ul); + } + else + _schema_error (schema_error::invalid_byte_value); + } + + signed char byte_pimpl:: + post_byte () + { + return value_; + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/validating/byte.hxx b/libxsde/xsde/cxx/parser/validating/byte.hxx new file mode 100644 index 0000000..6a3abce --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/byte.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_BYTE_HXX +#define XSDE_CXX_PARSER_VALIDATING_BYTE_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 8-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct byte_pimpl: virtual byte_pskel, number +#else + struct byte_pimpl: byte_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual signed char + post_byte (); + + protected: + // We only need strlen("0128") + 1 characters to hold all valid + // and trimmed string representations of signed byte. + // + char str_[5]; + signed char value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_BYTE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/date-time.cxx b/libxsde/xsde/cxx/parser/validating/date-time.cxx new file mode 100644 index 0000000..32f33a7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/date-time.cxx @@ -0,0 +1,259 @@ +// file : xsde/cxx/parser/validating/date-time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul, strtod + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/date-time.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void date_time_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void date_time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void date_time_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (n < 19 || (s[0] == '-' && n < 20)) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // Find the end of the year token. + // + ro_string::size_type yp = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (yp == ro_string::npos || (n - yp - 1) < 14 + || s[yp + 3] != '-' || s[yp + 6] != 'T' + || s[yp + 9] != ':' || s[yp + 12] != ':') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // Find the end of the seconds fragment. + // + ro_string::size_type sp = yp + 15; + for (; sp < n; ++sp) + { + char c = s[sp]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // At least one digit should follow the fraction point. + // + if ((sp - yp - 13) == 3) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // Parse it backwards so that we can truncate and reuse + // the string. + // + + // zone + // + if (sp < n) + { + if (!bits::parse_time_zone (s + sp, n - sp, zh_, zm_)) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // seconds + // + str_.truncate (sp); + + char* p; + set_errno (0); + seconds_ = strtod (s + yp + 13, &p); + + if (*p != '\0' || get_errno () != 0 || seconds_ >= 60.0) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // minutes + // + char d1 = s[yp + 10]; + char d2 = s[yp + 11]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // hours + // + d1 = s[yp + 7]; + d2 = s[yp + 8]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // day + // + d1 = s[yp + 4]; + d2 = s[yp + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // month + // + d1 = s[yp + 1]; + d2 = s[yp + 2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // year + // + str_.truncate (yp); + + set_errno (0); + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL) || + ul == 0) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + year_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + date_time date_time_pimpl:: + post_date_time () + { + return z_ + ? date_time (year_, month_, day_, hours_, + minutes_, seconds_, zh_, zm_) + : date_time (year_, month_, day_, hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/date-time.hxx b/libxsde/xsde/cxx/parser/validating/date-time.hxx new file mode 100644 index 0000000..dcbbaa9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/date-time.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/date-time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DATE_TIME_HXX +#define XSDE_CXX_PARSER_VALIDATING_DATE_TIME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_time_pimpl: virtual date_time_pskel +#else + struct date_time_pimpl: date_time_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual date_time + post_date_time (); + + protected: + string str_; + int year_; + unsigned short month_, day_; + unsigned short hours_, minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DATE_TIME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/date.cxx b/libxsde/xsde/cxx/parser/validating/date.cxx new file mode 100644 index 0000000..9efc52f --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/date.cxx @@ -0,0 +1,182 @@ +// file : xsde/cxx/parser/validating/date.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/date.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void date_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void date_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void date_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] + // + + if (n < 10 || (s[0] == '-' && n < 11)) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + // Find the end of the year token. + // + ro_string::size_type pos = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (pos == ro_string::npos || + (n - pos - 1) < 5 || + s[pos + 3] != '-') + { + _schema_error (schema_error::invalid_date_value); + return; + } + + // Parse the month, day values and time zone first so that we + // can truncate and reuse the string. + // + + // month + // + char d1 = s[pos + 1]; + char d2 = s[pos + 2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + // day + // + d1 = s[pos + 4]; + d2 = s[pos + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_value); + return; + } + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + // zone + // + if ((pos + 6) < n) + { + if (!bits::parse_time_zone (s + pos + 6, n - pos - 6, zh_, zm_)) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // year + // + str_.truncate (pos); + + char* p; + set_errno (0); + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL) || + ul == 0) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + year_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + date date_pimpl:: + post_date () + { + return z_ + ? date (year_, month_, day_, zh_, zm_) + : date (year_, month_, day_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/date.hxx b/libxsde/xsde/cxx/parser/validating/date.hxx new file mode 100644 index 0000000..feb4738 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/date.hxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/parser/validating/date.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DATE_HXX +#define XSDE_CXX_PARSER_VALIDATING_DATE_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_pimpl: virtual date_pskel +#else + struct date_pimpl: date_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual date + post_date (); + + protected: + string str_; + int year_; + unsigned short month_, day_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DATE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/decimal.cxx b/libxsde/xsde/cxx/parser/validating/decimal.cxx new file mode 100644 index 0000000..15aa4e9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/decimal.cxx @@ -0,0 +1,74 @@ +// file : xsde/cxx/parser/validating/decimal.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/decimal.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void decimal_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void decimal_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 127)) + _schema_error (schema_error::invalid_decimal_value); + } + + void decimal_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + if (tmp == "INF" || tmp == "NaN" || tmp == "NAN") + { + _schema_error (schema_error::invalid_decimal_value); + } + else + { + char* p; + set_errno (0); + value_ = strtod (str_, &p); + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_decimal_value); + + if (sign_ == minus) + value_ = -value_; + } + } + else + _schema_error (schema_error::invalid_decimal_value); + } + + double decimal_pimpl:: + post_decimal () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/decimal.hxx b/libxsde/xsde/cxx/parser/validating/decimal.hxx new file mode 100644 index 0000000..0669ce6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/decimal.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/decimal.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DECIMAL_HXX +#define XSDE_CXX_PARSER_VALIDATING_DECIMAL_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct decimal_pimpl: virtual decimal_pskel, number +#else + struct decimal_pimpl: decimal_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual double + post_decimal (); + + protected: + // Assume decimal values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + double value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DECIMAL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/double.cxx b/libxsde/xsde/cxx/parser/validating/double.cxx new file mode 100644 index 0000000..947f983 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/double.cxx @@ -0,0 +1,99 @@ +// file : xsde/cxx/parser/validating/double.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/double.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void double_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void double_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 127)) + _schema_error (schema_error::invalid_double_value); + } + + void double_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + if (tmp == "INF") + { + switch (sign_) + { + case none: + { + value_ = strtod ("INF", 0); + break; + } + case plus: + { + _schema_error (schema_error::invalid_double_value); + break; + } + case minus: + { + value_ = strtod ("-INF", 0); + break; + } + } + } + else if (tmp == "NaN") + { + if (sign_ == none) + value_ = strtod ("NAN", 0); + else + _schema_error (schema_error::invalid_double_value); + + } + else + { + char* p; + set_errno (0); + value_ = strtod (str_, &p); + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_double_value); + + if (sign_ == minus) + value_ = -value_; + } + } + else + _schema_error (schema_error::invalid_double_value); + } + + double double_pimpl:: + post_double () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/double.hxx b/libxsde/xsde/cxx/parser/validating/double.hxx new file mode 100644 index 0000000..afae038 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/double.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/double.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DOUBLE_HXX +#define XSDE_CXX_PARSER_VALIDATING_DOUBLE_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct double_pimpl: virtual double_pskel, number +#else + struct double_pimpl: double_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual double + post_double (); + + protected: + // Assume double values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + double value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DOUBLE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/duration.cxx b/libxsde/xsde/cxx/parser/validating/duration.cxx new file mode 100644 index 0000000..9d72609 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/duration.cxx @@ -0,0 +1,265 @@ +// file : xsde/cxx/parser/validating/duration.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul, strtod + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/duration.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void duration_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void duration_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + static ro_string::size_type + rfind_delim (const char* s, ro_string::size_type pos) + { + const char* p = s + pos; + for (; p >= s; --p) + { + if (*p == 'Y' || *p == 'D' || *p == 'M' || + *p == 'H' || *p == 'M' || *p == 'S' || + *p == 'T' || *p == 'P') + break; + } + + return p >= s ? p - s : ro_string::npos; + } + + + void duration_pimpl:: + _post () + { + typedef ro_string::size_type size_type; + + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + size_type n = trim_right (tmp); + + negative_ = false; + years_ = 0; + months_ = 0; + days_ = 0; + hours_ = 0; + minutes_ = 0; + seconds_ = 0.0; + + // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] + // + + if (n < 3 || (s[0] == '-' && n < 4)) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + if (s[0] == '-') + negative_ = true; + + if (s[negative_ ? 1 : 0] != 'P') + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + // Parse it backwards so that we can truncate and reuse + // the string. + // + + bool need_t = false; + size_type pos = n - 1; + size_type t_pos = tmp.find ('T'); + + char* p; + unsigned long ul; + + if (s[pos] == 'S') + { + need_t = true; + + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + seconds_ = strtod (s + pos + 1, &p); + + if (*p != '\0' || get_errno () != 0 || seconds_ < 0.0) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + } + + if (s[pos] == 'M' && t_pos != ro_string::npos && t_pos < pos) + { + need_t = true; + + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + minutes_ = static_cast<unsigned int> (ul); + } + + if (s[pos] == 'H') + { + need_t = true; + + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + hours_ = static_cast<unsigned int> (ul); + } + + if (need_t) + { + if (s[pos] == 'T') + pos = rfind_delim (s, pos - 1); + else + { + _schema_error (schema_error::invalid_duration_value); + return; + } + } + else + { + if (s[pos] == 'T') + { + _schema_error (schema_error::invalid_duration_value); + return; + } + } + + if (s[pos] == 'D') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + days_ = static_cast<unsigned int> (ul); + } + + if (s[pos] == 'M') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + months_ = static_cast<unsigned int> (ul); + } + + if (s[pos] == 'Y') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + years_ = static_cast<unsigned int> (ul); + } + + // Something did not match or appeared in the wrong order. + // + if (pos != static_cast<size_type> (negative_ ? 1 : 0)) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + } + + duration duration_pimpl:: + post_duration () + { + return duration ( + negative_, years_, months_, days_, hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/duration.hxx b/libxsde/xsde/cxx/parser/validating/duration.hxx new file mode 100644 index 0000000..3ee53db --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/duration.hxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/parser/validating/duration.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DURATION_HXX +#define XSDE_CXX_PARSER_VALIDATING_DURATION_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct duration_pimpl: virtual duration_pskel +#else + struct duration_pimpl: duration_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual duration + post_duration (); + + protected: + string str_; + bool negative_; + unsigned int years_, months_, days_; + unsigned int hours_, minutes_; + double seconds_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DURATION_HXX diff --git a/libxsde/xsde/cxx/parser/validating/float.cxx b/libxsde/xsde/cxx/parser/validating/float.cxx new file mode 100644 index 0000000..7bbbcca --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/float.cxx @@ -0,0 +1,118 @@ +// file : xsde/cxx/parser/validating/float.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtof, strtod + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/float.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void float_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void float_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 127)) + _schema_error (schema_error::invalid_float_value); + } + + void float_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + if (tmp == "INF") + { + switch (sign_) + { + case none: + { +#ifdef XSDE_STRTOF + value_ = strtof ("INF", 0); +#else + value_ = static_cast<float> (strtod ("INF", 0)); +#endif + break; + } + case plus: + { + _schema_error (schema_error::invalid_float_value); + break; + } + case minus: + { +#ifdef XSDE_STRTOF + value_ = strtof ("-INF", 0); +#else + value_ = static_cast<float> (strtod ("-INF", 0)); +#endif + break; + } + } + } + else if (tmp == "NaN") + { + if (sign_ == none) + { +#ifdef XSDE_STRTOF + value_ = strtof ("NAN", 0); +#else + value_ = static_cast<float> (strtod ("NAN", 0)); +#endif + } + else + _schema_error (schema_error::invalid_float_value); + + } + else + { + char* p; + set_errno (0); +#ifdef XSDE_STRTOF + value_ = strtof (str_, &p); +#else + value_ = static_cast<float> (strtod (str_, &p)); +#endif + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_float_value); + + if (sign_ == minus) + value_ = -value_; + } + } + else + _schema_error (schema_error::invalid_float_value); + } + + float float_pimpl:: + post_float () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/float.hxx b/libxsde/xsde/cxx/parser/validating/float.hxx new file mode 100644 index 0000000..2bb6e7d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/float.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/float.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_FLOAT_HXX +#define XSDE_CXX_PARSER_VALIDATING_FLOAT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct float_pimpl: virtual float_pskel, number +#else + struct float_pimpl: float_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual float + post_float (); + + protected: + // Assume float values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + float value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_FLOAT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gday.cxx b/libxsde/xsde/cxx/parser/validating/gday.cxx new file mode 100644 index 0000000..a743eee --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gday.cxx @@ -0,0 +1,112 @@ +// file : xsde/cxx/parser/validating/gday.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/gday.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gday_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gday_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gday_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gday := ---DD[Z|(+|-)HH:MM] + // + if (n < 5 || s[0] != '-' || s[1] != '-' || s[2] != '-') + { + _schema_error (schema_error::invalid_gday_value); + return; + } + + char d1 = s[3]; + char d2 = s[4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gday_value); + return; + } + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + { + _schema_error (schema_error::invalid_gday_value); + return; + } + + if (n > 5) + { + if (!bits::parse_time_zone (s + 5, n - 5, zh_, zm_)) + { + _schema_error (schema_error::invalid_gday_value); + return; + } + + z_ = true; + } + else + z_ = false; + } + + gday gday_pimpl:: + post_gday () + { + return z_ ? gday (day_, zh_, zm_) : gday (day_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gday.hxx b/libxsde/xsde/cxx/parser/validating/gday.hxx new file mode 100644 index 0000000..21f8fcd --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gday.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/gday.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GDAY_HXX +#define XSDE_CXX_PARSER_VALIDATING_GDAY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gday_pimpl: virtual gday_pskel +#else + struct gday_pimpl: gday_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gday + post_gday (); + + protected: + string str_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GDAY_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gmonth-day.cxx b/libxsde/xsde/cxx/parser/validating/gmonth-day.cxx new file mode 100644 index 0000000..3b4b4ea --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gmonth-day.cxx @@ -0,0 +1,137 @@ +// file : xsde/cxx/parser/validating/gmonth-day.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/gmonth-day.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gmonth_day_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gmonth_day_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gmonth_day_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gmonth_day := --MM-DD[Z|(+|-)HH:MM] + // + if (n < 7 || s[0] != '-' || s[1] != '-' || s[4] != '-') + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + // month + // + char d1 = s[2]; + char d2 = s[3]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + // day + // + d1 = s[5]; + d2 = s[6]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + // zone + // + if (n > 7) + { + if (!bits::parse_time_zone (s + 7, n - 7, zh_, zm_)) + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + z_ = true; + } + else + z_ = false; + } + + gmonth_day gmonth_day_pimpl:: + post_gmonth_day () + { + return z_ + ? gmonth_day (month_, day_, zh_, zm_) + : gmonth_day (month_, day_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gmonth-day.hxx b/libxsde/xsde/cxx/parser/validating/gmonth-day.hxx new file mode 100644 index 0000000..7ec4d59 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gmonth-day.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/gmonth-day.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GMONTH_DAY_HXX +#define XSDE_CXX_PARSER_VALIDATING_GMONTH_DAY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_day_pimpl: virtual gmonth_day_pskel +#else + struct gmonth_day_pimpl: gmonth_day_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gmonth_day + post_gmonth_day (); + + protected: + string str_; + unsigned short month_, day_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GMONTH_DAY_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gmonth.cxx b/libxsde/xsde/cxx/parser/validating/gmonth.cxx new file mode 100644 index 0000000..a6f5fc1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gmonth.cxx @@ -0,0 +1,112 @@ +// file : xsde/cxx/parser/validating/gmonth.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/gmonth.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gmonth_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gmonth_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gmonth_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gmonth := --MM[Z|(+|-)HH:MM] + // + if (n < 4 || s[0] != '-' || s[1] != '-') + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + + char d1 = s[2]; + char d2 = s[3]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + + if (n > 4) + { + if (!bits::parse_time_zone (s + 4, n - 4, zh_, zm_)) + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + + z_ = true; + } + else + z_ = false; + } + + gmonth gmonth_pimpl:: + post_gmonth () + { + return z_ ? gmonth (month_, zh_, zm_) : gmonth (month_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gmonth.hxx b/libxsde/xsde/cxx/parser/validating/gmonth.hxx new file mode 100644 index 0000000..cfd0e92 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gmonth.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/gmonth.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GMONTH_HXX +#define XSDE_CXX_PARSER_VALIDATING_GMONTH_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_pimpl: virtual gmonth_pskel +#else + struct gmonth_pimpl: gmonth_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gmonth + post_gmonth (); + + protected: + string str_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GMONTH_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gyear-month.cxx b/libxsde/xsde/cxx/parser/validating/gyear-month.cxx new file mode 100644 index 0000000..023b06c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gyear-month.cxx @@ -0,0 +1,161 @@ +// file : xsde/cxx/parser/validating/gyear-month.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/gyear-month.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gyear_month_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gyear_month_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gyear_month_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] + // + + if (n < 7 || (s[0] == '-' && n < 8)) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + // Find the end of the year token. + // + ro_string::size_type pos = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (pos == ro_string::npos || (n - pos - 1) < 2) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + // Parse the month value and time zone first so that we can + // truncate and reuse the string. + // + + // month + // + char d1 = s[pos + 1]; + char d2 = s[pos + 2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + // zone + // + if ((pos + 3) < n) + { + if (!bits::parse_time_zone (s + pos + 3, n - pos - 3, zh_, zm_)) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // year + // + str_.truncate (pos); + + char* p; + set_errno (0); + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL) || + ul == 0) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + year_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + gyear_month gyear_month_pimpl:: + post_gyear_month () + { + return z_ + ? gyear_month (year_, month_, zh_, zm_) + : gyear_month (year_, month_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gyear-month.hxx b/libxsde/xsde/cxx/parser/validating/gyear-month.hxx new file mode 100644 index 0000000..4e7933c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gyear-month.hxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/parser/validating/gyear-month.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GYEAR_MONTH_HXX +#define XSDE_CXX_PARSER_VALIDATING_GYEAR_MONTH_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_month_pimpl: virtual gyear_month_pskel +#else + struct gyear_month_pimpl: gyear_month_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gyear_month + post_gyear_month (); + + protected: + string str_; + int year_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GYEAR_MONTH_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gyear.cxx b/libxsde/xsde/cxx/parser/validating/gyear.cxx new file mode 100644 index 0000000..cbe87e1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gyear.cxx @@ -0,0 +1,138 @@ +// file : xsde/cxx/parser/validating/gyear.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/gyear.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gyear_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gyear_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gyear_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] + // + + if (n < 4 || (s[0] == '-' && n < 5)) + { + _schema_error (schema_error::invalid_gyear_value); + return; + } + + // Find the end of the year token. + // + ro_string::size_type pos = (s[0] == '-' ? 5 : 4); + for (; pos < n; ++pos) + { + char c = s[pos]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // Parse the time zone first so that we can truncate and + // reuse the string. + // + if (pos < n) + { + if (!bits::parse_time_zone (s + pos, n - pos, zh_, zm_)) + { + _schema_error (schema_error::invalid_gyear_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // Parse the year value. + // + str_.truncate (pos); + + char* p; + set_errno (0); + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL) || + ul == 0) + { + _schema_error (schema_error::invalid_gyear_value); + return; + } + + year_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + gyear gyear_pimpl:: + post_gyear () + { + return z_ ? gyear (year_, zh_, zm_) : gyear (year_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gyear.hxx b/libxsde/xsde/cxx/parser/validating/gyear.hxx new file mode 100644 index 0000000..557a6e4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gyear.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/gyear.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GYEAR_HXX +#define XSDE_CXX_PARSER_VALIDATING_GYEAR_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_pimpl: virtual gyear_pskel +#else + struct gyear_pimpl: gyear_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gyear + post_gyear (); + + protected: + string str_; + int year_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GYEAR_HXX diff --git a/libxsde/xsde/cxx/parser/validating/hex-binary.cxx b/libxsde/xsde/cxx/parser/validating/hex-binary.cxx new file mode 100644 index 0000000..5f5a02c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/hex-binary.cxx @@ -0,0 +1,172 @@ +// file : xsde/cxx/parser/validating/hex-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/hex-binary.hxx> + +static unsigned char +hex_decode (char c) +{ + unsigned char r = 0xFF; + + if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0'); + else if (c >= 'A' && c <= 'F') + r = static_cast<unsigned char> (10 + (c - 'A')); + else if (c >= 'a' && c <= 'f') + r = static_cast<unsigned char> (10 + (c - 'a')); + + return r; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + hex_binary_pimpl:: + ~hex_binary_pimpl () + { + if (!base_) + delete buf_; + } + + void hex_binary_pimpl:: + _reset () + { + hex_binary_pskel::_reset (); + + if (!base_) + { + delete buf_; + buf_ = 0; + } + } + + hex_binary_pimpl:: + hex_binary_pimpl (bool base) + : base_ (base), buf_ (0) + { + } + + void hex_binary_pimpl:: + pre_impl (buffer* b) + { + buf_ = b; + } + + void hex_binary_pimpl:: + _pre () + { + if (buf_ == 0) + { + buf_ = new buffer (); + +#ifndef XSDE_EXCEPTIONS + if (buf_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void hex_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void hex_binary_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + if (size % 2 != 0) + { + _schema_error (schema_error::invalid_hex_binary_value); + return; + } + + size_t n = size / 2; + +#ifdef XSDE_EXCEPTIONS + buf_->size (n); +#else + if (buf_->size (n)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + + if (n != 0) + { + const char* src = tmp.data (); + char* dst = buf_->data (); + size_t i = 0; + + for (; i < n; ++i) + { + unsigned char h = hex_decode (src[2 * i]); + unsigned char l = hex_decode (src[2 * i + 1]); + + if (h == 0xFF || l == 0xFF) + break; + + dst[i] = (h << 4) | l; + } + + if (i != n) + _schema_error (schema_error::invalid_hex_binary_value); + } + } + + buffer* hex_binary_pimpl:: + post_hex_binary () + { + buffer* r = buf_; + buf_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/hex-binary.hxx b/libxsde/xsde/cxx/parser/validating/hex-binary.hxx new file mode 100644 index 0000000..4ba0e96 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/hex-binary.hxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/parser/validating/hex-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_HEX_BINARY_HXX +#define XSDE_CXX_PARSER_VALIDATING_HEX_BINARY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct hex_binary_pimpl: virtual hex_binary_pskel +#else + struct hex_binary_pimpl: hex_binary_pskel +#endif + { + ~hex_binary_pimpl (); + hex_binary_pimpl (bool base = false); + + void + pre_impl (buffer*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual buffer* + post_hex_binary (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + buffer* buf_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_HEX_BINARY_HXX diff --git a/libxsde/xsde/cxx/parser/validating/id-stl.cxx b/libxsde/xsde/cxx/parser/validating/id-stl.cxx new file mode 100644 index 0000000..84d487c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/id-stl.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/validating/id-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/id-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void id_pimpl:: + _pre () + { + str_.erase (); + } + + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void id_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.resize (size); + else + _schema_error (schema_error::invalid_id_value); + } + + std::string id_pimpl:: + post_id () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/id-stl.hxx b/libxsde/xsde/cxx/parser/validating/id-stl.hxx new file mode 100644 index 0000000..8ded862 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/id-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/id-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_ID_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_ID_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_pimpl: virtual id_pskel +#else + struct id_pimpl: id_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_id (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_ID_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/id.cxx b/libxsde/xsde/cxx/parser/validating/id.cxx new file mode 100644 index 0000000..f5b1daf --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/id.cxx @@ -0,0 +1,80 @@ +// file : xsde/cxx/parser/validating/id.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/id.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void id_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void id_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.truncate (size); + else + _schema_error (schema_error::invalid_id_value); + } + + char* id_pimpl:: + post_id () + { + return str_.detach (); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/validating/id.hxx b/libxsde/xsde/cxx/parser/validating/id.hxx new file mode 100644 index 0000000..2b02290 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/id.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/id.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_ID_HXX +#define XSDE_CXX_PARSER_VALIDATING_ID_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_pimpl: virtual id_pskel +#else + struct id_pimpl: id_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_id (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_ID_HXX diff --git a/libxsde/xsde/cxx/parser/validating/idref-stl.cxx b/libxsde/xsde/cxx/parser/validating/idref-stl.cxx new file mode 100644 index 0000000..a7a4f10 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idref-stl.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/validating/idref-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void idref_pimpl:: + _pre () + { + str_.erase (); + } + + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void idref_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.resize (size); + else + _schema_error (schema_error::invalid_idref_value); + } + + std::string idref_pimpl:: + post_idref () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/idref-stl.hxx b/libxsde/xsde/cxx/parser/validating/idref-stl.hxx new file mode 100644 index 0000000..0382400 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idref-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/idref-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_IDREF_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_IDREF_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_pimpl: virtual idref_pskel +#else + struct idref_pimpl: idref_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_idref (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_IDREF_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/idref.cxx b/libxsde/xsde/cxx/parser/validating/idref.cxx new file mode 100644 index 0000000..1e0b320 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idref.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/idref.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void idref_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void idref_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.truncate (size); + else + _schema_error (schema_error::invalid_idref_value); + } + + char* idref_pimpl:: + post_idref () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/idref.hxx b/libxsde/xsde/cxx/parser/validating/idref.hxx new file mode 100644 index 0000000..bfbacb9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idref.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/idref.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_IDREF_HXX +#define XSDE_CXX_PARSER_VALIDATING_IDREF_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_pimpl: virtual idref_pskel +#else + struct idref_pimpl: idref_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_idref (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_IDREF_HXX diff --git a/libxsde/xsde/cxx/parser/validating/idrefs-stl.cxx b/libxsde/xsde/cxx/parser/validating/idrefs-stl.cxx new file mode 100644 index 0000000..0451a43 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idrefs-stl.cxx @@ -0,0 +1,133 @@ +// file : xsde/cxx/parser/validating/idrefs-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/pre.hxx> + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/idrefs-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + idrefs_pimpl:: + ~idrefs_pimpl () + { + if (!base_) + delete seq_; + } + + void idrefs_pimpl:: + _reset () + { + idrefs_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + idrefs_pimpl:: + idrefs_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void idrefs_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void idrefs_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + idrefs_pskel::_pre (); + } + + void idrefs_pimpl:: + _post () + { + idrefs_pskel::_post (); + + // Should have at least one element. + // + if (!_context ().error_type () && seq_->size () < 1) + _schema_error (schema_error::invalid_idrefs_value); + } + + string_sequence* idrefs_pimpl:: + post_idrefs () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + idref_pskel& p = parser_; + + p.pre (); + +#ifndef XSDE_EXCEPTIONS + if (!p._error_type ()) + p._pre_impl (ctx); + else + p._copy_error (ctx); +#else + p._pre_impl (ctx); +#endif + if (!ctx.error_type ()) + p._characters (s); + + if (!ctx.error_type ()) + p._post_impl (); + + if (!ctx.error_type ()) + { + const std::string& x = p.post_idref (); + +#ifndef XSDE_EXCEPTIONS + if (!p._error_type ()) + seq_->push_back (x); + else + p._copy_error (ctx); +#else + seq_->push_back (x); +#endif + } + } + } + } + } +} + +#include <xsde/cxx/post.hxx> diff --git a/libxsde/xsde/cxx/parser/validating/idrefs-stl.hxx b/libxsde/xsde/cxx/parser/validating/idrefs-stl.hxx new file mode 100644 index 0000000..44dfea8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idrefs-stl.hxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/parser/validating/idrefs-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_IDREFS_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_IDREFS_STL_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_pimpl: virtual idrefs_pskel +#else + struct idrefs_pimpl: idrefs_pskel +#endif + { + ~idrefs_pimpl (); + idrefs_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence* + post_idrefs (); + + virtual void + _reset (); + + protected: + bool base_; + idref_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_IDREFS_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/idrefs.cxx b/libxsde/xsde/cxx/parser/validating/idrefs.cxx new file mode 100644 index 0000000..f6072a5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idrefs.cxx @@ -0,0 +1,136 @@ +// file : xsde/cxx/parser/validating/idrefs.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/pre.hxx> + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/idrefs.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + idrefs_pimpl:: + ~idrefs_pimpl () + { + if (!base_) + delete seq_; + } + + void idrefs_pimpl:: + _reset () + { + idrefs_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + idrefs_pimpl:: + idrefs_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void idrefs_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void idrefs_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + idrefs_pskel::_pre (); + } + + void idrefs_pimpl:: + _post () + { + idrefs_pskel::_post (); + + // Should have at least one element. + // + if (!_context ().error_type () && seq_->size () < 1) + _schema_error (schema_error::invalid_idrefs_value); + } + + string_sequence* idrefs_pimpl:: + post_idrefs () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); +#else + parser_._pre_impl (ctx); +#endif + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + char* x = parser_.post_idref (); + + // push_back() frees the string if it fails. + // +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + { + if (seq_->push_back (x)) + _sys_error (sys_error::no_memory); + } + else + parser_._copy_error (ctx); +#else + seq_->push_back (x); +#endif + } + } + } + } + } +} + +#include <xsde/cxx/post.hxx> diff --git a/libxsde/xsde/cxx/parser/validating/idrefs.hxx b/libxsde/xsde/cxx/parser/validating/idrefs.hxx new file mode 100644 index 0000000..f2415ff --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idrefs.hxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/parser/validating/idrefs.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_IDREFS_HXX +#define XSDE_CXX_PARSER_VALIDATING_IDREFS_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_pimpl: virtual idrefs_pskel +#else + struct idrefs_pimpl: idrefs_pskel +#endif + { + ~idrefs_pimpl (); + idrefs_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence* + post_idrefs (); + + virtual void + _reset (); + + protected: + bool base_; + idref_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_IDREFS_HXX diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map-load.hxx b/libxsde/xsde/cxx/parser/validating/inheritance-map-load.hxx new file mode 100644 index 0000000..ad04019 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map-load.hxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/parser/validating/inheritance-map-load.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_LOAD_HXX +#define XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_LOAD_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + size_t + parser_imap_elements (); + + inline size_t + parser_imap_buckets () + { + return XSDE_PARSER_IMAP_BUCKETS; + } + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_LOAD_HXX + diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx b/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx new file mode 100644 index 0000000..491ec8d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx @@ -0,0 +1,111 @@ +// file : xsde/cxx/parser/validating/inheritance-map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <string.h> // strcmp + +#ifndef XSDE_EXCEPTIONS +# include <assert.h> // assert +# include <stdlib.h> // exit +#endif + +#include <xsde/cxx/parser/validating/inheritance-map.hxx> +#include <xsde/cxx/parser/validating/inheritance-map-load.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + inheritance_map* inheritance_map_init::map = 0; + size_t inheritance_map_init::count = 0; + + bool inheritance_map:: + check (const char* derived, const char* base) const + { + if (strcmp (derived, base) == 0) + return true; + + const void* p = find (derived); + + if (p) + { + const char* b = *static_cast<const char* const*> (p); + return strcmp (base, b) == 0 ? true : check (b, base); + } + + return false; + } + + // inheritance_map_init + // + inheritance_map_init:: + inheritance_map_init () + { + if (count == 0) + { + map = new inheritance_map (XSDE_PARSER_IMAP_BUCKETS); + +#ifndef XSDE_EXCEPTIONS + if (map == 0 || map->_error () != inheritance_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + ++count; + } + + inheritance_map_init:: + ~inheritance_map_init () + { + if (--count == 0) + delete map; + } + + // inheritance_map_entry + // + inheritance_map_entry:: + inheritance_map_entry (const char* derived, const char* base) + { + inheritance_map& m = inheritance_map_instance (); + m.insert (derived, base); + +#ifndef XSDE_EXCEPTIONS + if (m._error () != inheritance_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + // + // + size_t + parser_imap_elements () + { + return inheritance_map_instance ().size (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx b/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx new file mode 100644 index 0000000..6329545 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx @@ -0,0 +1,63 @@ +// file : xsde/cxx/parser/validating/inheritance-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX +#define XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> +#include <xsde/cxx/hashmap.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + struct inheritance_map: hashmap + { + inheritance_map (size_t buckets); + + void + insert (const char* derived, const char* base); + + bool + check (const char* derived, const char* base) const; + }; + + + // Translation unit initializer. + // + struct inheritance_map_init + { + static inheritance_map* map; + static size_t count; + + inheritance_map_init (); + ~inheritance_map_init (); + }; + + inline inheritance_map& + inheritance_map_instance (); + + // Map entry initializer. + // + struct inheritance_map_entry + { + inheritance_map_entry (const char* derived, const char* base); + }; + } + } + } +} + +#include <xsde/cxx/parser/validating/inheritance-map.ixx> + +#endif // XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX + diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.ixx b/libxsde/xsde/cxx/parser/validating/inheritance-map.ixx new file mode 100644 index 0000000..4f76685 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.ixx @@ -0,0 +1,34 @@ +// file : xsde/cxx/parser/validating/inheritance-map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + inline inheritance_map:: + inheritance_map (size_t buckets) + : hashmap (buckets, sizeof (const char*)) + { + } + + inline void inheritance_map:: + insert (const char* derived, const char* base) + { + hashmap::insert (derived, &base); + } + + inline inheritance_map& + inheritance_map_instance () + { + return *inheritance_map_init::map; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/int.cxx b/libxsde/xsde/cxx/parser/validating/int.cxx new file mode 100644 index 0000000..bfbac40 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/int.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/parser/validating/int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void int_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void int_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 11)) + _schema_error (schema_error::invalid_int_value); + } + + void int_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL)) + _schema_error (schema_error::invalid_int_value); + + value_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + else + _schema_error (schema_error::invalid_int_value); + } + + int int_pimpl:: + post_int () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/int.hxx b/libxsde/xsde/cxx/parser/validating/int.hxx new file mode 100644 index 0000000..7172af7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/int.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_INT_HXX +#define XSDE_CXX_PARSER_VALIDATING_INT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 32-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct int_pimpl: virtual int_pskel, number +#else + struct int_pimpl: int_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual int + post_int (); + + protected: + // We only need strlen("02147483648") + 1 characters to hold all + // valid and trimmed string representations of int. + // + char str_[12]; + int value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_INT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/integer.cxx b/libxsde/xsde/cxx/parser/validating/integer.cxx new file mode 100644 index 0000000..e3255e3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/integer.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/parser/validating/integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN, LONG_MAX + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_integer_value); + } + + void integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > static_cast<unsigned long> (LONG_MIN)) || + (!neg && ul > LONG_MAX)) + _schema_error (schema_error::invalid_integer_value); + + value_ = neg + ? (ul == static_cast<unsigned long> (LONG_MIN) + ? LONG_MIN: -static_cast<long> (ul)) + : static_cast<long> (ul); + } + else + _schema_error (schema_error::invalid_integer_value); + } + + long integer_pimpl:: + post_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/integer.hxx b/libxsde/xsde/cxx/parser/validating/integer.hxx new file mode 100644 index 0000000..ec7c863 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/integer.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct integer_pimpl: virtual integer_pskel, number +#else + struct integer_pimpl: integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long + post_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/language-stl.cxx b/libxsde/xsde/cxx/parser/validating/language-stl.cxx new file mode 100644 index 0000000..53e0e75 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/language-stl.cxx @@ -0,0 +1,95 @@ +// file : xsde/cxx/parser/validating/language-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/language-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void language_pimpl:: + _pre () + { + str_.erase (); + } + + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void language_pimpl:: + _post () + { + typedef ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size = trim_right (tmp); + + // language := ALPHA{1,8} *(-(ALPHA | DIGIT){1,8}) + // + bool ok = true; + size_type i = 0; + + for (size_type tag = 0; ; ++tag) + { + size_type n = 0; + + for (; i < size && n < 8; ++n, ++i) + { + char c = tmp[i]; + + if (!((c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (tag != 0 && c >= '0' && c <= '9'))) + break; + } + + if (n == 0) + { + ok = false; + break; + } + + if (i == size) + break; + + if (tmp[i++] != '-') + { + ok = false; + break; + } + } + + if (ok) + str_.resize (size); + else + _schema_error (schema_error::invalid_language_value); + } + + std::string language_pimpl:: + post_language () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/language-stl.hxx b/libxsde/xsde/cxx/parser/validating/language-stl.hxx new file mode 100644 index 0000000..8c0dfca --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/language-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/language-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_LANGUAGE_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_LANGUAGE_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_pimpl: virtual language_pskel +#else + struct language_pimpl: language_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_language (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_LANGUAGE_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/language.cxx b/libxsde/xsde/cxx/parser/validating/language.cxx new file mode 100644 index 0000000..177be73 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/language.cxx @@ -0,0 +1,114 @@ +// file : xsde/cxx/parser/validating/language.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/language.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void language_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void language_pimpl:: + _post () + { + typedef ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size = trim_right (tmp); + + // language := ALPHA{1,8} *(-(ALPHA | DIGIT){1,8}) + // + bool ok = true; + size_type i = 0; + + for (size_type tag = 0; ; ++tag) + { + size_type n = 0; + + for (; i < size && n < 8; ++n, ++i) + { + char c = tmp[i]; + + if (!((c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (tag != 0 && c >= '0' && c <= '9'))) + break; + } + + if (n == 0) + { + ok = false; + break; + } + + if (i == size) + break; + + if (tmp[i++] != '-') + { + ok = false; + break; + } + } + + if (ok) + str_.truncate (size); + else + _schema_error (schema_error::invalid_language_value); + } + + char* language_pimpl:: + post_language () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/language.hxx b/libxsde/xsde/cxx/parser/validating/language.hxx new file mode 100644 index 0000000..4321b00 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/language.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/language.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_LANGUAGE_HXX +#define XSDE_CXX_PARSER_VALIDATING_LANGUAGE_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_pimpl: virtual language_pskel +#else + struct language_pimpl: language_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_language (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_LANGUAGE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/long-long.cxx b/libxsde/xsde/cxx/parser/validating/long-long.cxx new file mode 100644 index 0000000..66fec5b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/long-long.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/parser/validating/long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoull + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void long_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_long_value); + } + + void long_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long long ull = strtoull (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ull > 9223372036854775808ULL) || + (!neg && ull > 9223372036854775807ULL)) + _schema_error (schema_error::invalid_long_value); + + value_ = neg + ? (ull == 9223372036854775808ULL + ? (-9223372036854775807LL - 1) + : -static_cast<long long> (ull)) + : static_cast<long long> (ull); + } + else + _schema_error (schema_error::invalid_long_value); + } + + long long long_pimpl:: + post_long () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/long-long.hxx b/libxsde/xsde/cxx/parser/validating/long-long.hxx new file mode 100644 index 0000000..b7e830b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/long-long.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_LONG_LONG_HXX +#define XSDE_CXX_PARSER_VALIDATING_LONG_LONG_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 64-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_pimpl: virtual long_pskel, number +#else + struct long_pimpl: long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_long (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long long. + // + char str_[21]; + long long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/validating/long.cxx b/libxsde/xsde/cxx/parser/validating/long.cxx new file mode 100644 index 0000000..d1f24b4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/long.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/parser/validating/long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void long_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_long_value); + } + + void long_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL)) + _schema_error (schema_error::invalid_long_value); + + value_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<long> (ul)) + : static_cast<long> (ul); + } + else + _schema_error (schema_error::invalid_long_value); + } + + long long_pimpl:: + post_long () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/long.hxx b/libxsde/xsde/cxx/parser/validating/long.hxx new file mode 100644 index 0000000..f87c6c6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/long.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_LONG_HXX +#define XSDE_CXX_PARSER_VALIDATING_LONG_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_pimpl: virtual long_pskel, number +#else + struct long_pimpl: long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long + post_long (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long long. + // + char str_[21]; + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/validating/name-stl.cxx b/libxsde/xsde/cxx/parser/validating/name-stl.cxx new file mode 100644 index 0000000..a691f94 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/name-stl.cxx @@ -0,0 +1,86 @@ +// file : xsde/cxx/parser/validating/name-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/parser/validating/name-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void name_pimpl:: + _pre () + { + str_.erase (); + } + + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void name_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + unsigned char c = static_cast<unsigned char> (str_[0]); + + ok = c >= 0x80 || (xml::char_table[c] & xml::name_first_char_mask); + + if (ok) + { + for (ro_string::size_type i = 1; i < size; ++i) + { + c = static_cast<unsigned char> (str_[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + { + ok = false; + break; + } + } + } + } + + str_.resize (size); + + if (!ok) + _schema_error (schema_error::invalid_name_value); + } + + std::string name_pimpl:: + post_name () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/name-stl.hxx b/libxsde/xsde/cxx/parser/validating/name-stl.hxx new file mode 100644 index 0000000..d3d7e02 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/name-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/name-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NAME_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_pimpl: virtual name_pskel +#else + struct name_pimpl: name_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_name (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/name.cxx b/libxsde/xsde/cxx/parser/validating/name.cxx new file mode 100644 index 0000000..167aa47 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/name.cxx @@ -0,0 +1,105 @@ +// file : xsde/cxx/parser/validating/name.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/parser/validating/name.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void name_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void name_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + unsigned char c = static_cast<unsigned char> (str_[0]); + + ok = c >= 0x80 || (xml::char_table[c] & xml::name_first_char_mask); + + if (ok) + { + for (ro_string::size_type i = 1; i < size; ++i) + { + c = static_cast<unsigned char> (str_[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + { + ok = false; + break; + } + } + } + } + + str_.truncate (size); + + if (!ok) + _schema_error (schema_error::invalid_name_value); + } + + char* name_pimpl:: + post_name () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/name.hxx b/libxsde/xsde/cxx/parser/validating/name.hxx new file mode 100644 index 0000000..9f9046f --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/name.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/name.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NAME_HXX +#define XSDE_CXX_PARSER_VALIDATING_NAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_pimpl: virtual name_pskel +#else + struct name_pimpl: name_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_name (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NAME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/ncname-stl.cxx b/libxsde/xsde/cxx/parser/validating/ncname-stl.cxx new file mode 100644 index 0000000..50bea6f --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/ncname-stl.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/validating/ncname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/ncname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void ncname_pimpl:: + _pre () + { + str_.erase (); + } + + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void ncname_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.resize (size); + else + _schema_error (schema_error::invalid_ncname_value); + } + + std::string ncname_pimpl:: + post_ncname () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/ncname-stl.hxx b/libxsde/xsde/cxx/parser/validating/ncname-stl.hxx new file mode 100644 index 0000000..6329c18 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/ncname-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/ncname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NCNAME_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NCNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_pimpl: virtual ncname_pskel +#else + struct ncname_pimpl: ncname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_ncname (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NCNAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/ncname.cxx b/libxsde/xsde/cxx/parser/validating/ncname.cxx new file mode 100644 index 0000000..c664014 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/ncname.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/ncname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/ncname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void ncname_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void ncname_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.truncate (size); + else + _schema_error (schema_error::invalid_ncname_value); + } + + char* ncname_pimpl:: + post_ncname () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/ncname.hxx b/libxsde/xsde/cxx/parser/validating/ncname.hxx new file mode 100644 index 0000000..89a5521 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/ncname.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/ncname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NCNAME_HXX +#define XSDE_CXX_PARSER_VALIDATING_NCNAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_pimpl: virtual ncname_pskel +#else + struct ncname_pimpl: ncname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_ncname (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NCNAME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/negative-integer.cxx b/libxsde/xsde/cxx/parser/validating/negative-integer.cxx new file mode 100644 index 0000000..e5c78a8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/negative-integer.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/validating/negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void negative_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void negative_integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_negative_integer_value); + } + + void negative_integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (sign_ == minus && size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + ul == 0 || + ul > static_cast<unsigned long> (LONG_MIN)) + _schema_error (schema_error::invalid_negative_integer_value); + + value_ = ul == static_cast<unsigned long> (LONG_MIN) + ? LONG_MIN : -static_cast<long> (ul); + } + else + _schema_error (schema_error::invalid_negative_integer_value); + } + + long negative_integer_pimpl:: + post_negative_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/negative-integer.hxx b/libxsde/xsde/cxx/parser/validating/negative-integer.hxx new file mode 100644 index 0000000..0839b03 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/negative-integer.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length negative integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct negative_integer_pimpl: virtual negative_integer_pskel, number +#else + struct negative_integer_pimpl: negative_integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long + post_negative_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/nmtoken-stl.cxx b/libxsde/xsde/cxx/parser/validating/nmtoken-stl.cxx new file mode 100644 index 0000000..0f7e987 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtoken-stl.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/nmtoken-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/parser/validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void nmtoken_pimpl:: + _pre () + { + str_.erase (); + } + + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void nmtoken_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + for (ro_string::size_type i = 0; i < size; ++i) + { + unsigned char c = static_cast<unsigned char> (str_[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + { + ok = false; + break; + } + } + } + + str_.resize (size); + + if (!ok) + _schema_error (schema_error::invalid_nmtoken_value); + } + + std::string nmtoken_pimpl:: + post_nmtoken () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/nmtoken-stl.hxx b/libxsde/xsde/cxx/parser/validating/nmtoken-stl.hxx new file mode 100644 index 0000000..5166018 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtoken-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/nmtoken-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NMTOKEN_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NMTOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_pimpl: virtual nmtoken_pskel +#else + struct nmtoken_pimpl: nmtoken_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_nmtoken (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NMTOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/nmtoken.cxx b/libxsde/xsde/cxx/parser/validating/nmtoken.cxx new file mode 100644 index 0000000..875b8e3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtoken.cxx @@ -0,0 +1,98 @@ +// file : xsde/cxx/parser/validating/nmtoken.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/parser/validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void nmtoken_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void nmtoken_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + for (ro_string::size_type i = 0; i < size; ++i) + { + unsigned char c = static_cast<unsigned char> (str_[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + { + ok = false; + break; + } + } + } + + str_.truncate (size); + + if (!ok) + _schema_error (schema_error::invalid_nmtoken_value); + } + + char* nmtoken_pimpl:: + post_nmtoken () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/nmtoken.hxx b/libxsde/xsde/cxx/parser/validating/nmtoken.hxx new file mode 100644 index 0000000..f4d322e --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtoken.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/nmtoken.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NMTOKEN_HXX +#define XSDE_CXX_PARSER_VALIDATING_NMTOKEN_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_pimpl: virtual nmtoken_pskel +#else + struct nmtoken_pimpl: nmtoken_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_nmtoken (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NMTOKEN_HXX diff --git a/libxsde/xsde/cxx/parser/validating/nmtokens-stl.cxx b/libxsde/xsde/cxx/parser/validating/nmtokens-stl.cxx new file mode 100644 index 0000000..1c88132 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtokens-stl.cxx @@ -0,0 +1,127 @@ +// file : xsde/cxx/parser/validating/nmtokens-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/nmtokens-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + nmtokens_pimpl:: + ~nmtokens_pimpl () + { + if (!base_) + delete seq_; + } + + void nmtokens_pimpl:: + _reset () + { + nmtokens_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + nmtokens_pimpl:: + nmtokens_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void nmtokens_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void nmtokens_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + nmtokens_pskel::_pre (); + } + + void nmtokens_pimpl:: + _post () + { + nmtokens_pskel::_post (); + + // Should have at least one element. + // + if (!_context ().error_type () && seq_->size () < 1) + _schema_error (schema_error::invalid_nmtokens_value); + } + + string_sequence* nmtokens_pimpl:: + post_nmtokens () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); +#else + parser_._pre_impl (ctx); +#endif + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + const std::string& x = parser_.post_nmtoken (); + +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + seq_->push_back (x); + else + parser_._copy_error (ctx); +#else + seq_->push_back (x); +#endif + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/nmtokens-stl.hxx b/libxsde/xsde/cxx/parser/validating/nmtokens-stl.hxx new file mode 100644 index 0000000..6cbc464 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtokens-stl.hxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/parser/validating/nmtokens-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NMTOKENS_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NMTOKENS_STL_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_pimpl: virtual nmtokens_pskel +#else + struct nmtokens_pimpl: nmtokens_pskel +#endif + { + ~nmtokens_pimpl (); + nmtokens_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence* + post_nmtokens (); + + virtual void + _reset (); + + protected: + bool base_; + nmtoken_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NMTOKENS_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/nmtokens.cxx b/libxsde/xsde/cxx/parser/validating/nmtokens.cxx new file mode 100644 index 0000000..074294d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtokens.cxx @@ -0,0 +1,132 @@ +// file : xsde/cxx/parser/validating/nmtokens.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/nmtokens.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + nmtokens_pimpl:: + ~nmtokens_pimpl () + { + if (!base_) + delete seq_; + } + + void nmtokens_pimpl:: + _reset () + { + nmtokens_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + nmtokens_pimpl:: + nmtokens_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void nmtokens_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void nmtokens_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + nmtokens_pskel::_pre (); + } + + void nmtokens_pimpl:: + _post () + { + nmtokens_pskel::_post (); + + // Should have at least one element. + // + if (!_context ().error_type () && seq_->size () < 1) + _schema_error (schema_error::invalid_nmtokens_value); + } + + string_sequence* nmtokens_pimpl:: + post_nmtokens () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); +#else + parser_._pre_impl (ctx); +#endif + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + char* x = parser_.post_nmtoken (); + + // push_back() frees the string if it fails. + // +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + { + if (seq_->push_back (x)) + _sys_error (sys_error::no_memory); + } + else + parser_._copy_error (ctx); +#else + seq_->push_back (x); +#endif + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/nmtokens.hxx b/libxsde/xsde/cxx/parser/validating/nmtokens.hxx new file mode 100644 index 0000000..f24161a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtokens.hxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/parser/validating/nmtokens.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NMTOKENS_HXX +#define XSDE_CXX_PARSER_VALIDATING_NMTOKENS_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_pimpl: virtual nmtokens_pskel +#else + struct nmtokens_pimpl: nmtokens_pskel +#endif + { + ~nmtokens_pimpl (); + nmtokens_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence* + post_nmtokens (); + + virtual void + _reset (); + + protected: + bool base_; + nmtoken_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NMTOKENS_HXX diff --git a/libxsde/xsde/cxx/parser/validating/non-negative-integer.cxx b/libxsde/xsde/cxx/parser/validating/non-negative-integer.cxx new file mode 100644 index 0000000..7333abf --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/non-negative-integer.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/validating/non-negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/non-negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void non_negative_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void non_negative_integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 21)) + _schema_error (schema_error::invalid_non_negative_integer_value); + } + + void non_negative_integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + value_ = strtoul (str_, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (sign_ == minus && value_ != 0)) + _schema_error (schema_error::invalid_non_negative_integer_value); + } + else + _schema_error (schema_error::invalid_non_negative_integer_value); + } + + unsigned long non_negative_integer_pimpl:: + post_non_negative_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/non-negative-integer.hxx b/libxsde/xsde/cxx/parser/validating/non-negative-integer.hxx new file mode 100644 index 0000000..36dabf7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/non-negative-integer.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/validating/non-negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NON_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_NON_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length non-negative integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_negative_integer_pimpl: virtual non_negative_integer_pskel, +#else + struct non_negative_integer_pimpl: non_negative_integer_pskel, +#endif + number + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long + post_non_negative_integer (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long, assuming we are on a 64 bit machine. + // + char str_[22]; + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NON_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/non-positive-integer.cxx b/libxsde/xsde/cxx/parser/validating/non-positive-integer.cxx new file mode 100644 index 0000000..0560a34 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/non-positive-integer.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/validating/non-positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/non-positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void non_positive_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void non_positive_integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_non_positive_integer_value); + } + + void non_positive_integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (sign_ != minus && ul != 0) || + ul > static_cast<unsigned long> (LONG_MIN)) + _schema_error (schema_error::invalid_non_positive_integer_value); + + value_ = ul == static_cast<unsigned long> (LONG_MIN) + ? LONG_MIN : -static_cast<long> (ul); + } + else + _schema_error (schema_error::invalid_non_positive_integer_value); + } + + long non_positive_integer_pimpl:: + post_non_positive_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/non-positive-integer.hxx b/libxsde/xsde/cxx/parser/validating/non-positive-integer.hxx new file mode 100644 index 0000000..f592289 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/non-positive-integer.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/validating/non-positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NON_POSITIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_NON_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length non-positive integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_positive_integer_pimpl: virtual non_positive_integer_pskel, +#else + struct non_positive_integer_pimpl: non_positive_integer_pskel, +#endif + number + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long + post_non_positive_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NON_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/normalized-string-stl.cxx b/libxsde/xsde/cxx/parser/validating/normalized-string-stl.cxx new file mode 100644 index 0000000..131b4a1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/normalized-string-stl.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/validating/normalized-string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/normalized-string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void normalized_string_pimpl:: + _pre () + { + str_.erase (); + } + + void normalized_string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + std::string normalized_string_pimpl:: + post_normalized_string () + { + std::string::size_type size = str_.size (); + + for (std::string::size_type i = 0; i < size; ++i) + { + char& c = str_[i]; + + if (c == 0x0A || c == 0x0D || c == 0x09) + c = 0x20; + } + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/normalized-string-stl.hxx b/libxsde/xsde/cxx/parser/validating/normalized-string-stl.hxx new file mode 100644 index 0000000..02247d2 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/normalized-string-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/normalized-string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_pimpl: virtual normalized_string_pskel +#else + struct normalized_string_pimpl: normalized_string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_normalized_string (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/normalized-string.cxx b/libxsde/xsde/cxx/parser/validating/normalized-string.cxx new file mode 100644 index 0000000..634cf2e --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/normalized-string.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/validating/normalized-string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/normalized-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void normalized_string_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void normalized_string_pimpl:: + _characters (const ro_string& s) + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + + char* normalized_string_pimpl:: + post_normalized_string () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + + for (size_type i = 0; i < size; ++i) + { + char& c = str_[i]; + + if (c == 0x0A || c == 0x0D || c == 0x09) + c = 0x20; + } + + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/normalized-string.hxx b/libxsde/xsde/cxx/parser/validating/normalized-string.hxx new file mode 100644 index 0000000..5446ceb --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/normalized-string.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/normalized-string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_HXX +#define XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_pimpl: virtual normalized_string_pskel +#else + struct normalized_string_pimpl: normalized_string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_normalized_string (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_HXX diff --git a/libxsde/xsde/cxx/parser/validating/number.cxx b/libxsde/xsde/cxx/parser/validating/number.cxx new file mode 100644 index 0000000..62b7d53 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/number.cxx @@ -0,0 +1,133 @@ +// file : xsde/cxx/parser/validating/number.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy + +#include <xsde/cxx/parser/validating/number.hxx> + +using xsde::cxx::ro_string; + +static bool +trim_leading_zeros (ro_string& s) +{ + ro_string::size_type size = s.size (); + + if (size != 0) + { + const char* f = s.data (); + const char* l = f + size; + const char* of = f; + + while (f < l && *f == '0') + ++f; + + if (f != of) + { + s.assign ((f <= l ? f : 0), (f <= l ? l - f : 0)); + return true; + } + } + + return false; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + bool number:: + parse (const ro_string& s, char* str, size_t max) + { + bool r = true; + + ro_string tmp (s.data (), s.size ()); + size_t size = tmp.size (); + + switch (state_) + { + case leading_ws: + { + size = trim_left (tmp); + + if (size != 0) + state_ = sign; + else + break; + // Fall through. + } + case sign: + { + if (tmp[0] == '-') + sign_ = minus; + else if (tmp[0] == '+') + sign_ = plus; + + if (sign_ != none) + tmp.assign (tmp.data () + 1, --size); + + if (size != 0) + state_ = leading_zeros; + else + break; + + // Fall through. + } + case leading_zeros: + { + if (trim_leading_zeros (tmp)) + { + if (size_ == 0) + { + str[0] = '0'; + size_ = 1; + } + + size = tmp.size (); + } + + if (size != 0) + state_ = literal; + else + break; + // Fall through. + } + case literal: + { + // If this chunk is too long then it has to be the last so trim + // trailing ws. + // + if ((max - size_) < size) + { + size = trim_right (tmp); + state_ = trailing_ws; // It either had ws or is too large. + } + + if ((max - size_) >= size) + { + memcpy (str + size_, tmp.data (), size); + size_ += size; + } + else + r = false; + + break; + } + case trailing_ws: + { + if (trim_left (tmp) != 0) + r = false; + } + } + + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/number.hxx b/libxsde/xsde/cxx/parser/validating/number.hxx new file mode 100644 index 0000000..2cd9b62 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/number.hxx @@ -0,0 +1,37 @@ +// file : xsde/cxx/parser/validating/number.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NUMBER_HXX +#define XSDE_CXX_PARSER_VALIDATING_NUMBER_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/ro-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + class number + { + protected: + bool + parse (const ro_string&, char* str, size_t max); + + protected: + size_t size_; + enum {leading_ws, sign, leading_zeros, literal, trailing_ws} state_; + enum {none, plus, minus} sign_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NUMBER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/parser.cxx b/libxsde/xsde/cxx/parser/validating/parser.cxx new file mode 100644 index 0000000..119bf79 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/parser.cxx @@ -0,0 +1,633 @@ +// file : xsde/cxx/parser/validating/parser.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <assert.h> + +#include <xsde/cxx/parser/validating/parser.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // empty_content + // + +#ifdef XSDE_POLYMORPHIC + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&, + const char*) + { + return false; + } +#else + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&) + { + return false; + } +#endif + + bool empty_content:: + _end_element_impl (const ro_string&, + const ro_string&) + { + return false; + } + + bool empty_content:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool empty_content:: + _characters_impl (const ro_string&) + { + return false; + } + + // + // +#ifdef XSDE_POLYMORPHIC + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (!_start_element_impl (ns, name, type)) + _schema_error (schema_error::unexpected_element); + } +#else + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name) + { + if (!_start_element_impl (ns, name)) + _schema_error (schema_error::unexpected_element); + } +#endif + + void empty_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _schema_error (schema_error::unexpected_element); + } + + static const char + xmlns_namespace_[] = "http://www.w3.org/2000/xmlns/"; + + static const char + xsi_namespace_[] = "http://www.w3.org/2001/XMLSchema-instance"; + + static const char + type_[] = "type"; + + static const char + nil_[] = "nil"; + + static const char + schema_location_[] = "schemaLocation"; + + static const char + no_namespace_schema_location_[] = "noNamespaceSchemaLocation"; + + void empty_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _schema_error (schema_error::unexpected_attribute); + } + + void empty_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + _schema_error (schema_error::unexpected_characters); + } + + + // simple_content + // + + void simple_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _schema_error (schema_error::unexpected_attribute); + } + + void simple_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + { + // Mixed content is implemented in the generated code + // by overriding _characters_impl and forwarding to + // _any_characters. + // + + // Scan the string for any non-whitespace characters + // (Structures, section 3.4.4, clause 1.3). + // + ro_string::size_type end = s.size (); + for (ro_string::size_type i = 0; i < end; ++i) + { + char c = s[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + continue; + + _schema_error (schema_error::unexpected_characters); + break; + } + } + } + + void simple_content:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + context_ = &c; + + previous_ = c.current_; + + c.current_.parser_ = this; + c.current_.depth_ = 0; + c.current_.any_ = false; + + _pre (); + + if (!c.error_type ()) + _pre_a_validate (); + } + + void simple_content:: + _post_impl () + { + if (!context_->error_type ()) + _post_a_validate (); + + if (!context_->error_type ()) + _post (); + + context_->current_ = previous_; + context_ = 0; + } + + void simple_content:: + _pre_a_validate () + { + } + + void simple_content:: + _post_a_validate () + { + } + + bool simple_content:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Returns true on error. + // + if (_attribute_impl_phase_one (ns, name, value)) + return true; + + return _attribute_impl_phase_two (ns, name, value); + } + + bool simple_content:: + _attribute_impl_phase_one (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool simple_content:: + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + + // complex_content + // + +#ifdef XSDE_POLYMORPHIC + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (!_start_element_impl (ns, name, type)) + _schema_error (schema_error::unexpected_element); + } +#else + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name) + { + if (!_start_element_impl (ns, name)) + _schema_error (schema_error::unexpected_element); + } +#endif + + void complex_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _schema_error (schema_error::unexpected_element); + } + + void complex_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _schema_error (schema_error::unexpected_attribute); + } + + void complex_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + { + // Mixed content is implemented in the generated code + // by overriding _characters_impl and forwarding to + // _any_characters. + // + + // Scan the string for any non-whitespace characters + // (Structures, section 3.4.4, clause 1.3). + // + ro_string::size_type end = s.size (); + for (ro_string::size_type i = 0; i < end; ++i) + { + char c = s[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + continue; + + _schema_error (schema_error::unexpected_characters); + break; + } + } + } + + void complex_content:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + if (depth_++ == 0) + context_ = &c; + +#ifdef XSDE_EXCEPTIONS + parser_stack_.push (c.current_); +#else + if (parser_stack_.push (c.current_)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + c.current_.parser_ = this; + c.current_.depth_ = 0; + c.current_.any_ = false; + + _pre (); + + if (!c.error_type ()) + _pre_a_validate (); + + if (!c.error_type ()) + _pre_e_validate (); + } + + void complex_content:: + _post_impl () + { + if (!context_->error_type ()) + _post_e_validate (); + + if (!context_->error_type ()) + _post_a_validate (); + + if (!context_->error_type ()) + _post (); + + context_->current_ = parser_stack_.top (); + parser_stack_.pop (); + + if (--depth_ == 0) + context_ = 0; + } + + void complex_content:: + _pre_e_validate () + { + } + + void complex_content:: + _post_e_validate () + { + } + + void complex_content:: + _pre_a_validate () + { + } + + void complex_content:: + _post_a_validate () + { + } + + bool complex_content:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Returns true on error. + // + if (_attribute_impl_phase_one (ns, name, value)) + return true; + + return _attribute_impl_phase_two (ns, name, value); + } + + bool complex_content:: + _attribute_impl_phase_one (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool complex_content:: + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + void complex_content:: + _reset () + { + empty_content::_reset (); + + depth_ = 0; + parser_stack_.clear (); + } + + // list_base + // + + // Find first non-space character. + // + static ro_string::size_type + find_ns (const char* s, + ro_string::size_type size, + ro_string::size_type pos) + { + while (pos < size && + (s[pos] == 0x20 || s[pos] == 0x0A || + s[pos] == 0x0D || s[pos] == 0x09)) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Find first space character. + // + static ro_string::size_type + find_s (const char* s, + ro_string::size_type size, + ro_string::size_type pos) + { + while (pos < size && + s[pos] != 0x20 && s[pos] != 0x0A && + s[pos] != 0x0D && s[pos] != 0x09) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Relevant XML Schema Part 2: Datatypes sections: 4.2.1.2, 4.3.6. + // + + void list_base:: + _pre_impl (context& c) + { + simple_content::_pre_impl (c); + + if (!c.error_type ()) + { +#ifdef XSDE_EXCEPTIONS + buf_.assign ("", 0); +#else + if (buf_.assign ("", 0)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + } + + void list_base:: + _characters (const ro_string& s) + { + typedef ro_string::size_type size_type; + + const char* data = s.data (); + size_type size = s.size (); + + // Handle the previous chunk if we start with a ws. + // + if (!buf_.empty () && + (data[0] == 0x20 || data[0] == 0x0A || + data[0] == 0x0D || data[0] == 0x09)) + { + ro_string tmp (buf_); // Private copy ctor. + _xsde_parse_item (tmp); + buf_.assign ("", 0); // Can't fail. + } + + context& ctx = _context (); + + // Traverse the data while logically collapsing spaces. + // + for (size_type i = find_ns (data, size, 0); i != ro_string::npos;) + { + size_type j = find_s (data, size, i); + + if (j != ro_string::npos) + { + if (buf_.empty ()) + { + ro_string tmp (data + i, j - i); // Private copy ctor. + _xsde_parse_item (tmp); + } + else + { + // Assemble the first item in str from buf_ and s. + // + string str; + str.swap (buf_); + +#ifdef XSDE_EXCEPTIONS + str.append (data + i, j - i); +#else + if (str.append (data + i, j - i)) + { + _sys_error (sys_error::no_memory); + break; + } +#endif + ro_string tmp (str); // Private copy ctor. + _xsde_parse_item (tmp); + } + + if (ctx.error_type ()) + break; + + i = find_ns (data, size, j); + } + else + { + // Last fragment, append it to buf_. + // +#ifdef XSDE_EXCEPTIONS + buf_.append (data + i, size - i); +#else + if (buf_.append (data + i, size - i)) + _sys_error (sys_error::no_memory); +#endif + break; + } + } + } + + void list_base:: + _xsde_parse_item (const ro_string&) + { + } + + void list_base:: + _post_impl () + { + // Handle the last item. + // + if (!buf_.empty ()) + { + ro_string tmp (buf_); // Private copy ctor. + _xsde_parse_item (tmp); + } + + simple_content::_post_impl (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/parser.hxx b/libxsde/xsde/cxx/parser/validating/parser.hxx new file mode 100644 index 0000000..246b7c9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/parser.hxx @@ -0,0 +1,304 @@ +// file : xsde/cxx/parser/validating/parser.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_PARSER_HXX +#define XSDE_CXX_PARSER_VALIDATING_PARSER_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/cxx/string.hxx> +#include <xsde/cxx/ro-string.hxx> + +#include <xsde/cxx/parser/elements.hxx> +#include <xsde/cxx/parser/state.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // + // + struct empty_content: parser_base + { + +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, + const ro_string&); +#endif + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + + // + // +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string&, + const ro_string&, + const char*); +#else + virtual void + _start_element (const ro_string&, + const ro_string&); +#endif + + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + empty_content (); + empty_content (empty_content* impl, void*); +#endif + }; + + + // + // + struct simple_content: empty_content + { + // + // + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + // + // + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + // + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + + + // Implementation callbacks. + // + virtual void + _pre_a_validate (); + + virtual void + _post_a_validate (); + + + // Attribute validation: during phase one we are searching for + // matching attributes (Structures, section 3.4.4, clause 2.1). + // During phase two we are searching for attribute wildcards + // (section 3.4.4, clause 2.2). Both phases run across + // inheritance hierarchy from derived to base for extension + // only. Both functions return true if the match was found and + // validation has been performed. + // + virtual bool + _attribute_impl_phase_one (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual bool + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + simple_content (); + simple_content (simple_content* impl, void*); +#endif + }; + + + // + // + struct complex_content: empty_content + { +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string&, + const ro_string&, + const char*); +#else + virtual void + _start_element (const ro_string&, + const ro_string&); +#endif + + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + // + // + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + // + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + + + // Implementation callbacks. + // + virtual void + _pre_e_validate (); + + virtual void + _post_e_validate (); + + virtual void + _pre_a_validate (); + + virtual void + _post_a_validate (); + + + // Attribute validation: during phase one we are searching for + // matching attributes (Structures, section 3.4.4, clause 2.1). + // During phase two we are searching for attribute wildcards + // (section 3.4.4, clause 2.2). Both phases run across + // inheritance hierarchy from derived to base for extension + // only. Both functions return true if the match was found and + // validation has been performed. + // + virtual bool + _attribute_impl_phase_one (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual bool + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + // + // + virtual void + _reset (); + + // + // + complex_content (); + +#ifdef XSDE_REUSE_STYLE_TIEIN + complex_content (complex_content* impl, void*); +#endif + protected: + size_t depth_; + parser_stack parser_stack_; + }; + + // Validation state stack for the 'all' particle. + // + struct all_stack + { + all_stack (size_t n, unsigned char* first); + + stack::error + push (); + + void + pop (); + + unsigned char* + top (); + + void + clear (); + + private: + stack stack_; + }; + + // Base for xsd:list. + // + struct list_base: simple_content + { + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _pre_impl (context&); + + virtual void + _characters (const ro_string&); + + virtual void + _post_impl (); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + list_base (); + list_base (list_base* impl, void*); +#endif + protected: + string buf_; + }; + } + } + } +} + +#include <xsde/cxx/parser/validating/parser.ixx> + +#endif // XSDE_CXX_PARSER_VALIDATING_PARSER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/parser.ixx b/libxsde/xsde/cxx/parser/validating/parser.ixx new file mode 100644 index 0000000..4a0e176 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/parser.ixx @@ -0,0 +1,121 @@ +// file : xsde/cxx/parser/validating/parser.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + + // empty_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline empty_content:: + empty_content () + { + } + + inline empty_content:: + empty_content (empty_content* impl, void*) + : parser_base (impl, 0) + { + } +#endif + + // simple_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline simple_content:: + simple_content () + { + } + + inline simple_content:: + simple_content (simple_content* impl, void*) + : empty_content (impl, 0) + { + } +#endif + + // complex_content + // + inline complex_content:: + complex_content () + : depth_ (0), parser_stack_ (previous_) + { + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline complex_content:: + complex_content (complex_content* impl, void*) + : empty_content (impl, 0), depth_ (0), parser_stack_ (previous_) + { + } +#endif + + // all_stack + // + + inline all_stack:: + all_stack (size_t n, unsigned char* first) + : stack_ (n, first) + { + } + + inline stack::error all_stack:: + push () + { + if (stack::error e = stack_.push ()) + return e; + + unsigned char* p = static_cast<unsigned char*> (stack_.top ()); + + for (size_t i = 0; i < stack_.element_size (); ++i) + p[i] = 0; + + return stack::error_none; + } + + inline void all_stack:: + pop () + { + stack_.pop (); + } + + inline unsigned char* all_stack:: + top () + { + return static_cast<unsigned char*> (stack_.top ()); + } + + inline void all_stack:: + clear () + { + stack_.clear (); + } + + + // list_base + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline list_base:: + list_base () + { + } + + inline list_base:: + list_base (list_base* impl, void*) + : simple_content (impl, 0) + { + } +#endif + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/validating/positive-integer.cxx b/libxsde/xsde/cxx/parser/validating/positive-integer.cxx new file mode 100644 index 0000000..2a6595a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/positive-integer.cxx @@ -0,0 +1,64 @@ +// file : xsde/cxx/parser/validating/positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void positive_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void positive_integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 21)) + _schema_error (schema_error::invalid_positive_integer_value); + } + + void positive_integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + value_ = strtoul (str_, &p, 10); + + if (*p != '\0' || get_errno () != 0 || value_ == 0) + _schema_error (schema_error::invalid_positive_integer_value); + } + else + _schema_error (schema_error::invalid_positive_integer_value); + } + + unsigned long positive_integer_pimpl:: + post_positive_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/positive-integer.hxx b/libxsde/xsde/cxx/parser/validating/positive-integer.hxx new file mode 100644 index 0000000..59b6b27 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/positive-integer.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_POSITIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length positive integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct positive_integer_pimpl: virtual positive_integer_pskel, number +#else + struct positive_integer_pimpl: positive_integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long + post_positive_integer (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long, assuming we are on a 64 bit machine. + // + char str_[22]; + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/qname-stl.cxx b/libxsde/xsde/cxx/parser/validating/qname-stl.cxx new file mode 100644 index 0000000..a65e367 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/qname-stl.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/qname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/qname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void qname_pimpl:: + _pre () + { + str_.erase (); + } + + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void qname_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + ro_string::size_type pos = tmp.find (':'); + + const char* s = tmp.data (); + + if (pos != ro_string::npos) + { + if (xml::valid_ncname (s, pos) && + xml::valid_ncname (s + pos + 1, size - pos - 1)) + { + prefix_.assign (s, pos); + name_.assign (s + pos + 1, size - pos - 1); + } + else + _schema_error (schema_error::invalid_qname_value); + } + else + { + if (xml::valid_ncname (s, size)) + { + prefix_.erase (); + str_.resize (size); + name_.swap (str_); + } + else + _schema_error (schema_error::invalid_qname_value); + } + } + + qname qname_pimpl:: + post_qname () + { + return qname (prefix_, name_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/qname-stl.hxx b/libxsde/xsde/cxx/parser/validating/qname-stl.hxx new file mode 100644 index 0000000..c766c55 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/qname-stl.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/validating/qname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_QNAME_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_QNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_pimpl: virtual qname_pskel +#else + struct qname_pimpl: qname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual qname + post_qname (); + + protected: + std::string str_; + std::string name_; + std::string prefix_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_QNAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/qname.cxx b/libxsde/xsde/cxx/parser/validating/qname.cxx new file mode 100644 index 0000000..265179c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/qname.cxx @@ -0,0 +1,180 @@ +// file : xsde/cxx/parser/validating/qname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/qname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + qname_pimpl:: + ~qname_pimpl () + { + if (!base_) + delete qn_; + } + + void qname_pimpl:: + _reset () + { + qname_pskel::_reset (); + + if (!base_) + { + delete qn_; + qn_ = 0; + } + } + + qname_pimpl:: + qname_pimpl (bool base) + : base_ (base), qn_ (0) + { + } + + void qname_pimpl:: + pre_impl (qname* qn) + { + qn_ = qn; + } + + void qname_pimpl:: + _pre () + { + if (qn_ == 0) + { + qn_ = new qname (); + +#ifndef XSDE_EXCEPTIONS + if (qn_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void qname_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + ro_string::size_type pos = tmp.find (':'); + + string name; + string prefix; + + const char* s = tmp.data (); + + if (pos != ro_string::npos) + { + if (xml::valid_ncname (s, pos) && + xml::valid_ncname (s + pos + 1, size - pos - 1)) + { +#ifdef XSDE_EXCEPTIONS + prefix.assign (s, pos); + name.assign (s + pos + 1, size - pos - 1); +#else + if (prefix.assign (s, pos) || + name.assign (s + pos + 1, size - pos - 1)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + else + { + _schema_error (schema_error::invalid_qname_value); + return; + } + } + else + { + if (xml::valid_ncname (s, size)) + { +#ifdef XSDE_EXCEPTIONS + prefix.assign ("", 0); + str_.truncate (size); + name.swap (str_); +#else + if (prefix.assign ("", 0)) + { + _sys_error (sys_error::no_memory); + return; + } + else + { + str_.truncate (size); + name.swap (str_); + } +#endif + } + else + { + _schema_error (schema_error::invalid_qname_value); + return; + } + } + + qn_->prefix (prefix.detach ()); + qn_->name (name.detach ()); + } + + qname* qname_pimpl:: + post_qname () + { + qname* r = qn_; + qn_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/qname.hxx b/libxsde/xsde/cxx/parser/validating/qname.hxx new file mode 100644 index 0000000..2201699 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/qname.hxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/parser/validating/qname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_QNAME_HXX +#define XSDE_CXX_PARSER_VALIDATING_QNAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_pimpl: virtual qname_pskel +#else + struct qname_pimpl: qname_pskel +#endif + { + ~qname_pimpl (); + qname_pimpl (bool base = false); + + void + pre_impl (qname*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual qname* + post_qname (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + qname* qn_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_QNAME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/short.cxx b/libxsde/xsde/cxx/parser/validating/short.cxx new file mode 100644 index 0000000..199465b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/short.cxx @@ -0,0 +1,70 @@ +// file : xsde/cxx/parser/validating/short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/validating/short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void short_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void short_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 6)) + _schema_error (schema_error::invalid_short_value); + } + + void short_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + // No need to check errno since our string representation + // can never overflow an unsigned long. + // + char* p; + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || (neg && ul > 32768) || (!neg && ul > 32767)) + _schema_error (schema_error::invalid_short_value); + + value_ = neg + ? static_cast<short> (-static_cast<int> (ul)) + : static_cast<short> (ul); + } + else + _schema_error (schema_error::invalid_short_value); + } + + short short_pimpl:: + post_short () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/short.hxx b/libxsde/xsde/cxx/parser/validating/short.hxx new file mode 100644 index 0000000..1bbe7bd --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/short.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_SHORT_HXX +#define XSDE_CXX_PARSER_VALIDATING_SHORT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 16-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct short_pimpl: virtual short_pskel, number +#else + struct short_pimpl: short_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual short + post_short (); + + protected: + // We only need strlen("032768") + 1 characters to hold all valid + // and trimmed string representations of short. + // + char str_[7]; + short value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_SHORT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/string-stl.cxx b/libxsde/xsde/cxx/parser/validating/string-stl.cxx new file mode 100644 index 0000000..a0394db --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/string-stl.cxx @@ -0,0 +1,38 @@ +// file : xsde/cxx/parser/validating/string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void string_pimpl:: + _pre () + { + str_.erase (); + } + + void string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + std::string string_pimpl:: + post_string () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/string-stl.hxx b/libxsde/xsde/cxx/parser/validating/string-stl.hxx new file mode 100644 index 0000000..a6220d1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/string-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_STRING_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_pimpl: virtual string_pskel +#else + struct string_pimpl: string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_string (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/string.cxx b/libxsde/xsde/cxx/parser/validating/string.cxx new file mode 100644 index 0000000..a4319fb --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/string.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/validating/string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void string_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void string_pimpl:: + _characters (const ro_string& s) + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + + char* string_pimpl:: + post_string () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/string.hxx b/libxsde/xsde/cxx/parser/validating/string.hxx new file mode 100644 index 0000000..2e2bcd5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/string.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_STRING_HXX +#define XSDE_CXX_PARSER_VALIDATING_STRING_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_pimpl: virtual string_pskel +#else + struct string_pimpl: string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_string (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_STRING_HXX diff --git a/libxsde/xsde/cxx/parser/validating/time-zone.cxx b/libxsde/xsde/cxx/parser/validating/time-zone.cxx new file mode 100644 index 0000000..fb25f56 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/time-zone.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/time-zone.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + namespace bits + { + bool + parse_time_zone (const char* s, size_t n, short& h, short& m) + { + // time_zone := Z|(+|-)HH:MM + // + if (n == 0) + { + return false; + } + else if (s[0] == 'Z') + { + if (n != 1) + return false; + + h = 0; + m = 0; + } + else + { + if (n != 6 || (s[0] != '-' && s[0] != '+') || s[3] != ':') + return false; + + // Parse hours. + // + char d1 = s[1]; + char d2 = s[2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + return false; + + h = 10 * (d1 - '0') + (d2 - '0'); + + if (h > 14) + return false; + + // Parse minutes. + // + d1 = s[4]; + d2 = s[5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + return false; + + m = 10 * (d1 - '0') + (d2 - '0'); + + if (m > 59 || (h == 14 && m != 0)) + return false; + + if (s[0] == '-') + { + h = -h; + m = -m; + } + } + + return true; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/time-zone.hxx b/libxsde/xsde/cxx/parser/validating/time-zone.hxx new file mode 100644 index 0000000..93a8205 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/time-zone.hxx @@ -0,0 +1,32 @@ +// file : xsde/cxx/parser/validating/time-zone.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_TIME_ZONE_HXX +#define XSDE_CXX_PARSER_VALIDATING_TIME_ZONE_HXX + +#include <stddef.h> // size_t + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + namespace bits + { + bool + parse_time_zone (const char* s, + size_t size, + short& hours, + short& minutes); + } + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_TIME_ZONE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/time.cxx b/libxsde/xsde/cxx/parser/validating/time.cxx new file mode 100644 index 0000000..eaddc58 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/time.cxx @@ -0,0 +1,181 @@ +// file : xsde/cxx/parser/validating/time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/time.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void time_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void time_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (n < 8 || s[2] != ':' || s[5] != ':') + { + _schema_error (schema_error::invalid_time_value); + return; + } + + // hours + // + char d1 = s[0]; + char d2 = s[1]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_time_value); + return; + } + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + // minutes + // + d1 = s[3]; + d2 = s[4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_time_value); + return; + } + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + // Find the end of the seconds fragment. + // + ro_string::size_type pos = 8; + for (; pos < n; ++pos) + { + char c = s[pos]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // At least one digit should follow the fraction point. + // + if ((pos - 6) == 3) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + // Parse the time zone first so that we can truncate and + // reuse the string. + // + if (pos < n) + { + if (!bits::parse_time_zone (s + pos, n - pos, zh_, zm_)) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // seconds + // + str_.truncate (pos); + + char* p; + set_errno (0); + seconds_ = strtod (s + 6, &p); + + if (*p != '\0' || get_errno () != 0 || seconds_ >= 60.0) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + { + _schema_error (schema_error::invalid_time_value); + return; + } + } + + time time_pimpl:: + post_time () + { + return z_ + ? time (hours_, minutes_, seconds_, zh_, zm_) + : time (hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/time.hxx b/libxsde/xsde/cxx/parser/validating/time.hxx new file mode 100644 index 0000000..3f68b4c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/time.hxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/parser/validating/time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_TIME_HXX +#define XSDE_CXX_PARSER_VALIDATING_TIME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct time_pimpl: virtual time_pskel +#else + struct time_pimpl: time_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual time + post_time (); + + protected: + string str_; + unsigned short hours_, minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_TIME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/token-stl.cxx b/libxsde/xsde/cxx/parser/validating/token-stl.cxx new file mode 100644 index 0000000..e6ac6ea --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/token-stl.cxx @@ -0,0 +1,73 @@ +// file : xsde/cxx/parser/validating/token-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/token-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void token_pimpl:: + _pre () + { + str_.erase (); + } + + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string token_pimpl:: + post_token () + { + std::string::size_type size = str_.size (); + std::string::size_type j = 0; + + bool subs = false; + + for (std::string::size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = 0x20; + } + + str_[j++] = c; + } + } + + str_.resize (j); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/token-stl.hxx b/libxsde/xsde/cxx/parser/validating/token-stl.hxx new file mode 100644 index 0000000..29e4f9a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/token-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/token-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_TOKEN_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_TOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_pimpl: virtual token_pskel +#else + struct token_pimpl: token_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_token (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_TOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/token.cxx b/libxsde/xsde/cxx/parser/validating/token.cxx new file mode 100644 index 0000000..5e12a60 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/token.cxx @@ -0,0 +1,94 @@ +// file : xsde/cxx/parser/validating/token.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/token.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void token_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* token_pimpl:: + post_token () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + size_type j = 0; + + bool subs = false; + + for (size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = 0x20; + } + + str_[j++] = c; + } + } + + str_.truncate (j); + + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/token.hxx b/libxsde/xsde/cxx/parser/validating/token.hxx new file mode 100644 index 0000000..230466b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/token.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/token.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_TOKEN_HXX +#define XSDE_CXX_PARSER_VALIDATING_TOKEN_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_pimpl: virtual token_pskel +#else + struct token_pimpl: token_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_token (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_TOKEN_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-byte.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-byte.cxx new file mode 100644 index 0000000..ace72f8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-byte.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/validating/unsigned-byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/validating/unsigned-byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_byte_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_byte_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 4)) + _schema_error (schema_error::invalid_unsigned_byte_value); + } + + void unsigned_byte_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + // No need to check errno since our string representation + // can never overflow an unsigned long. + // + char* p; + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || ul > 255) + _schema_error (schema_error::invalid_unsigned_byte_value); + + value_ = static_cast<unsigned char> (ul); + } + else + _schema_error (schema_error::invalid_unsigned_byte_value); + } + + unsigned char unsigned_byte_pimpl:: + post_unsigned_byte () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-byte.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-byte.hxx new file mode 100644 index 0000000..bec1e6d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-byte.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/unsigned-byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_BYTE_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_BYTE_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 8-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_byte_pimpl: virtual unsigned_byte_pskel, number +#else + struct unsigned_byte_pimpl: unsigned_byte_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned char + post_unsigned_byte (); + + protected: + // We only need strlen("0256") + 1 characters to hold all valid + // and trimmed string representations of unsigned byte. + // + char str_[5]; + unsigned char value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_BYTE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-int.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-int.cxx new file mode 100644 index 0000000..fbb18aa --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-int.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/validating/unsigned-int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/unsigned-int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_int_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_int_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 11)) + _schema_error (schema_error::invalid_unsigned_int_value); + } + + void unsigned_int_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + _schema_error (schema_error::invalid_unsigned_int_value); + + value_ = static_cast<unsigned int> (ul); + } + else + _schema_error (schema_error::invalid_unsigned_int_value); + } + + unsigned int unsigned_int_pimpl:: + post_unsigned_int () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-int.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-int.hxx new file mode 100644 index 0000000..2811557 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-int.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/unsigned-int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_INT_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_INT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 32-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_int_pimpl: virtual unsigned_int_pskel, number +#else + struct unsigned_int_pimpl: unsigned_int_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned int + post_unsigned_int (); + + protected: + // We only need strlen("04294967295") + 1 characters to hold all + // valid and trimmed string representations of unsigned int. + // + char str_[12]; + unsigned int value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_INT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-long-long.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-long-long.cxx new file mode 100644 index 0000000..5464028 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-long-long.cxx @@ -0,0 +1,64 @@ +// file : xsde/cxx/parser/validating/unsigned-long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoull + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/unsigned-long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 21)) + _schema_error (schema_error::invalid_unsigned_long_value); + } + + void unsigned_long_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + value_ = strtoull (str_, &p, 10); + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_unsigned_long_value); + } + else + _schema_error (schema_error::invalid_unsigned_long_value); + } + + unsigned long long unsigned_long_pimpl:: + post_unsigned_long () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-long-long.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-long-long.hxx new file mode 100644 index 0000000..b0aa4cb --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-long-long.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/unsigned-long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_LONG_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_LONG_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 64-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_pimpl: virtual unsigned_long_pskel, number +#else + struct unsigned_long_pimpl: unsigned_long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long long + post_unsigned_long (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long long. + // + char str_[22]; + unsigned long long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-long.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-long.cxx new file mode 100644 index 0000000..eababbf --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-long.cxx @@ -0,0 +1,64 @@ +// file : xsde/cxx/parser/validating/unsigned-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/unsigned-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 21)) + _schema_error (schema_error::invalid_unsigned_long_value); + } + + void unsigned_long_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + value_ = strtoul (str_, &p, 10); + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_unsigned_long_value); + } + else + _schema_error (schema_error::invalid_unsigned_long_value); + } + + unsigned long unsigned_long_pimpl:: + post_unsigned_long () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-long.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-long.hxx new file mode 100644 index 0000000..6b2ac19 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-long.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/unsigned-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_pimpl: virtual unsigned_long_pskel, number +#else + struct unsigned_long_pimpl: unsigned_long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long + post_unsigned_long (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long long. + // + char str_[22]; + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-short.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-short.cxx new file mode 100644 index 0000000..b40b51c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-short.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/validating/unsigned-short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/validating/unsigned-short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_short_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_short_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 6)) + _schema_error (schema_error::invalid_unsigned_short_value); + } + + void unsigned_short_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + // No need to check errno since our string representation + // can never overflow an unsigned long. + // + char* p; + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || ul > 65535) + _schema_error (schema_error::invalid_unsigned_short_value); + + value_ = static_cast<unsigned short> (ul); + } + else + _schema_error (schema_error::invalid_unsigned_short_value); + } + + unsigned short unsigned_short_pimpl:: + post_unsigned_short () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-short.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-short.hxx new file mode 100644 index 0000000..be7228a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-short.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/unsigned-short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_SHORT_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_SHORT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 16-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_short_pimpl: virtual unsigned_short_pskel, number +#else + struct unsigned_short_pimpl: unsigned_short_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned short + post_unsigned_short (); + + protected: + // We only need strlen("065535") + 1 characters to hold all valid + // and trimmed string representations of unsigned short. + // + char str_[7]; + unsigned short value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_SHORT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/uri-stl.cxx b/libxsde/xsde/cxx/parser/validating/uri-stl.cxx new file mode 100644 index 0000000..c2947dd --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/uri-stl.cxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/uri-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/uri-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void uri_pimpl:: + _pre () + { + str_.erase (); + } + + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string uri_pimpl:: + post_uri () + { + // According to Datatypes 3.2.17 and RFC2396 pretty much anything + // can be a URI and conforming processors do not need to figure + // out and verify particular URI schemes. + // + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/uri-stl.hxx b/libxsde/xsde/cxx/parser/validating/uri-stl.hxx new file mode 100644 index 0000000..b964aff --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/uri-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/uri-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_URI_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_URI_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_pimpl: virtual uri_pskel +#else + struct uri_pimpl: uri_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_uri (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_URI_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/uri.cxx b/libxsde/xsde/cxx/parser/validating/uri.cxx new file mode 100644 index 0000000..37acfea --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/uri.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/validating/uri.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/uri.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void uri_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* uri_pimpl:: + post_uri () + { + // According to Datatypes 3.2.17 and RFC2396 pretty much anything + // can be a URI and conforming processors do not need to figure + // out and verify particular URI schemes. + // + ro_string tmp (str_); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/uri.hxx b/libxsde/xsde/cxx/parser/validating/uri.hxx new file mode 100644 index 0000000..2e19aef --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/uri.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/uri.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_URI_HXX +#define XSDE_CXX_PARSER_VALIDATING_URI_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_pimpl: virtual uri_pskel +#else + struct uri_pimpl: uri_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_uri (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_URI_HXX diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pimpl.hxx b/libxsde/xsde/cxx/parser/validating/xml-schema-pimpl.hxx new file mode 100644 index 0000000..7552521 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pimpl.hxx @@ -0,0 +1,82 @@ +// file : xsde/cxx/parser/validating/xml-schema-pimpl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX +#define XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +#include <xsde/cxx/parser/validating/any-type.hxx> +#include <xsde/cxx/parser/validating/boolean.hxx> +#include <xsde/cxx/parser/validating/byte.hxx> +#include <xsde/cxx/parser/validating/unsigned-byte.hxx> +#include <xsde/cxx/parser/validating/byte.hxx> +#include <xsde/cxx/parser/validating/unsigned-byte.hxx> +#include <xsde/cxx/parser/validating/short.hxx> +#include <xsde/cxx/parser/validating/unsigned-short.hxx> +#include <xsde/cxx/parser/validating/int.hxx> +#include <xsde/cxx/parser/validating/unsigned-int.hxx> + +#ifdef XSDE_LONGLONG +# include <xsde/cxx/parser/validating/long-long.hxx> +# include <xsde/cxx/parser/validating/unsigned-long-long.hxx> +#else +# include <xsde/cxx/parser/validating/long.hxx> +# include <xsde/cxx/parser/validating/unsigned-long.hxx> +#endif + +#include <xsde/cxx/parser/validating/integer.hxx> +#include <xsde/cxx/parser/validating/negative-integer.hxx> +#include <xsde/cxx/parser/validating/non-positive-integer.hxx> +#include <xsde/cxx/parser/validating/positive-integer.hxx> +#include <xsde/cxx/parser/validating/non-negative-integer.hxx> +#include <xsde/cxx/parser/validating/float.hxx> +#include <xsde/cxx/parser/validating/double.hxx> +#include <xsde/cxx/parser/validating/decimal.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/parser/validating/string-stl.hxx> +# include <xsde/cxx/parser/validating/normalized-string-stl.hxx> +# include <xsde/cxx/parser/validating/token-stl.hxx> +# include <xsde/cxx/parser/validating/name-stl.hxx> +# include <xsde/cxx/parser/validating/nmtoken-stl.hxx> +# include <xsde/cxx/parser/validating/nmtokens-stl.hxx> +# include <xsde/cxx/parser/validating/ncname-stl.hxx> +# include <xsde/cxx/parser/validating/id-stl.hxx> +# include <xsde/cxx/parser/validating/idref-stl.hxx> +# include <xsde/cxx/parser/validating/idrefs-stl.hxx> +# include <xsde/cxx/parser/validating/language-stl.hxx> +# include <xsde/cxx/parser/validating/uri-stl.hxx> +# include <xsde/cxx/parser/validating/qname-stl.hxx> +#else +# include <xsde/cxx/parser/validating/string.hxx> +# include <xsde/cxx/parser/validating/normalized-string.hxx> +# include <xsde/cxx/parser/validating/token.hxx> +# include <xsde/cxx/parser/validating/name.hxx> +# include <xsde/cxx/parser/validating/nmtoken.hxx> +# include <xsde/cxx/parser/validating/nmtokens.hxx> +# include <xsde/cxx/parser/validating/ncname.hxx> +# include <xsde/cxx/parser/validating/id.hxx> +# include <xsde/cxx/parser/validating/idref.hxx> +# include <xsde/cxx/parser/validating/idrefs.hxx> +# include <xsde/cxx/parser/validating/language.hxx> +# include <xsde/cxx/parser/validating/uri.hxx> +# include <xsde/cxx/parser/validating/qname.hxx> +#endif + +#include <xsde/cxx/parser/validating/base64-binary.hxx> +#include <xsde/cxx/parser/validating/hex-binary.hxx> + +#include <xsde/cxx/parser/validating/gday.hxx> +#include <xsde/cxx/parser/validating/gmonth.hxx> +#include <xsde/cxx/parser/validating/gyear.hxx> +#include <xsde/cxx/parser/validating/gmonth-day.hxx> +#include <xsde/cxx/parser/validating/gyear-month.hxx> +#include <xsde/cxx/parser/validating/date.hxx> +#include <xsde/cxx/parser/validating/time.hxx> +#include <xsde/cxx/parser/validating/date-time.hxx> +#include <xsde/cxx/parser/validating/duration.hxx> + +#endif // XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.cxx b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.cxx new file mode 100644 index 0000000..894f674 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.cxx @@ -0,0 +1,617 @@ +// file : xsde/cxx/parser/validating/xml-schema-pskel.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // +#ifdef XSDE_POLYMORPHIC + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, + const ro_string& name, + const char* type) + { + context& ctx = _context (); + ctx.current_.any_ = true; + ctx.current_.depth_++; + + _start_any_element (ns, name, type); + return true; + } +#else + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, const ro_string& name) + { + context& ctx = _context (); + ctx.current_.any_ = true; + ctx.current_.depth_++; + + _start_any_element (ns, name); + return true; + } +#endif + + bool any_type_pskel:: + _end_element_impl (const ro_string& ns, const ro_string& name) + { + _end_any_element (ns, name); + return true; + } + + bool any_type_pskel:: + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + _any_attribute (ns, name, value); + return true; + } + + bool any_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + + void any_type_pskel:: + post_any_type () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_type_impl_) + any_type_impl_->post_any_type (); +#endif + } + + // any_simple_type + // + bool any_simple_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + + void any_simple_type_pskel:: + post_any_simple_type () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_simple_type_impl_) + any_simple_type_impl_->post_any_simple_type (); +#endif + } + + // static/dynamic_type function implementations. + // +#ifdef XSDE_POLYMORPHIC + const char* any_type_pskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* any_simple_type_pskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* boolean_pskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + const char* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* byte_pskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + const char* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_byte_pskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* short_pskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + const char* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_short_pskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* int_pskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + const char* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_int_pskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* long_pskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + const char* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_long_pskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* integer_pskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + const char* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* negative_integer_pskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_positive_integer_pskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* positive_integer_pskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_negative_integer_pskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* float_pskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + const char* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* double_pskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + const char* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* decimal_pskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + const char* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* string_pskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + const char* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* normalized_string_pskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + const char* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* token_pskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + const char* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* name_pskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + const char* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtoken_pskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtokens_pskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* ncname_pskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + const char* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* id_pskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + const char* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idref_pskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + const char* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idrefs_pskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + const char* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* language_pskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + const char* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* uri_pskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + const char* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* qname_pskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + const char* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* base64_binary_pskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + const char* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* hex_binary_pskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + const char* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gday_pskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_pskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_pskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_day_pskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_month_pskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_pskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + const char* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* time_pskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + const char* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_time_pskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + const char* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* duration_pskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + const char* duration_pskel:: + _dynamic_type () const + { + return _static_type (); + } +#endif // XSDE_POLYMORPHIC + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx new file mode 100644 index 0000000..8f9e33a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx @@ -0,0 +1,1385 @@ +// file : xsde/cxx/parser/validating/xml-schema-pskel.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX +#define XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_STL +# include <string> +#endif + +#include <xsde/cxx/parser/xml-schema.hxx> + +#include <xsde/cxx/parser/validating/parser.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // anyType and anySimpleType. All events are routed to the + // _any_* callbacks. + // + struct any_type_pskel: complex_content + { +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, const ro_string&); +#endif + + virtual bool + _end_element_impl (const ro_string&, const ro_string&); + + virtual bool + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_type (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_type_pskel (); + any_type_pskel (any_type_pskel* impl, void*); + + protected: + any_type_pskel* any_type_impl_; +#endif + }; + + struct any_simple_type_pskel: simple_content + { + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_simple_type (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_simple_type_pskel (); + any_simple_type_pskel (any_simple_type_pskel* impl, void*); + + protected: + any_simple_type_pskel* any_simple_type_impl_; +#endif + }; + + + // Boolean. + // + struct boolean_pskel: simple_content + { + virtual bool + post_boolean () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + boolean_pskel (); + boolean_pskel (boolean_pskel* impl, void*); + + protected: + boolean_pskel* boolean_impl_; +#endif + }; + + + // 8-bit + // + + struct byte_pskel: simple_content + { + virtual signed char + post_byte () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + byte_pskel (); + byte_pskel (byte_pskel* impl, void*); + + protected: + byte_pskel* byte_impl_; +#endif + }; + + struct unsigned_byte_pskel: simple_content + { + virtual unsigned char + post_unsigned_byte () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_byte_pskel (); + unsigned_byte_pskel (unsigned_byte_pskel* impl, void*); + + protected: + unsigned_byte_pskel* unsigned_byte_impl_; +#endif + }; + + + // 16-bit + // + + struct short_pskel: simple_content + { + virtual short + post_short () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + short_pskel (); + short_pskel (short_pskel* impl, void*); + + protected: + short_pskel* short_impl_; +#endif + }; + + struct unsigned_short_pskel: simple_content + { + virtual unsigned short + post_unsigned_short () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_short_pskel (); + unsigned_short_pskel (unsigned_short_pskel* impl, void*); + + protected: + unsigned_short_pskel* unsigned_short_impl_; +#endif + }; + + + // 32-bit + // + + struct int_pskel: simple_content + { + virtual int + post_int () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + int_pskel (); + int_pskel (int_pskel* impl, void*); + + protected: + int_pskel* int_impl_; +#endif + }; + + struct unsigned_int_pskel: simple_content + { + virtual unsigned int + post_unsigned_int () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_int_pskel (); + unsigned_int_pskel (unsigned_int_pskel* impl, void*); + + protected: + unsigned_int_pskel* unsigned_int_impl_; +#endif + }; + + + // 64-bit + // +#ifdef XSDE_LONGLONG + + struct long_pskel: simple_content + { + virtual long long + post_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_pskel (); + long_pskel (long_pskel* impl, void*); + + protected: + long_pskel* long_impl_; +#endif + }; + + struct unsigned_long_pskel: simple_content + { + virtual unsigned long long + post_unsigned_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_pskel (); + unsigned_long_pskel (unsigned_long_pskel* impl, void*); + + protected: + unsigned_long_pskel* unsigned_long_impl_; +#endif + }; + +#else + + struct long_pskel: simple_content + { + virtual long + post_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_pskel (); + long_pskel (long_pskel* impl, void*); + + protected: + long_pskel* long_impl_; +#endif + }; + + struct unsigned_long_pskel: simple_content + { + virtual unsigned long + post_unsigned_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_pskel (); + unsigned_long_pskel (unsigned_long_pskel* impl, void*); + + protected: + unsigned_long_pskel* unsigned_long_impl_; +#endif + }; +#endif + + + // Arbitrary-length integers. + // + + struct integer_pskel: simple_content + { + virtual long + post_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + integer_pskel (); + integer_pskel (integer_pskel* impl, void*); + + protected: + integer_pskel* integer_impl_; +#endif + }; + + struct negative_integer_pskel: simple_content + { + virtual long + post_negative_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + negative_integer_pskel (); + negative_integer_pskel (negative_integer_pskel* impl, void*); + + protected: + negative_integer_pskel* negative_integer_impl_; +#endif + }; + + struct non_positive_integer_pskel: simple_content + { + virtual long + post_non_positive_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_positive_integer_pskel (); + non_positive_integer_pskel (non_positive_integer_pskel* impl, void*); + + protected: + non_positive_integer_pskel* non_positive_integer_impl_; +#endif + }; + + struct positive_integer_pskel: simple_content + { + virtual unsigned long + post_positive_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + positive_integer_pskel (); + positive_integer_pskel (positive_integer_pskel* impl, void*); + + protected: + positive_integer_pskel* positive_integer_impl_; +#endif + }; + + struct non_negative_integer_pskel: simple_content + { + virtual unsigned long + post_non_negative_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_negative_integer_pskel (); + non_negative_integer_pskel (non_negative_integer_pskel* impl, void*); + + protected: + non_negative_integer_pskel* non_negative_integer_impl_; +#endif + }; + + + // Floats. + // + + struct float_pskel: simple_content + { + virtual float + post_float () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + float_pskel (); + float_pskel (float_pskel* impl, void*); + + protected: + float_pskel* float_impl_; +#endif + }; + + struct double_pskel: simple_content + { + virtual double + post_double () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + double_pskel (); + double_pskel (double_pskel* impl, void*); + + protected: + double_pskel* double_impl_; +#endif + }; + + struct decimal_pskel: simple_content + { + virtual double + post_decimal () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + decimal_pskel (); + decimal_pskel (decimal_pskel* impl, void*); + + protected: + decimal_pskel* decimal_impl_; +#endif + }; + + + // String-based types. + // +#ifdef XSDE_STL + + struct string_pskel: simple_content + { + virtual std::string + post_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_pskel (); + string_pskel (string_pskel* impl, void*); + + protected: + string_pskel* string_impl_; +#endif + }; + + struct normalized_string_pskel: simple_content + { + virtual std::string + post_normalized_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_pskel (); + normalized_string_pskel (normalized_string_pskel* impl, void*); + + protected: + normalized_string_pskel* normalized_string_impl_; +#endif + }; + + struct token_pskel: simple_content + { + virtual std::string + post_token () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_pskel (); + token_pskel (token_pskel* impl, void*); + + protected: + token_pskel* token_impl_; +#endif + }; + + struct name_pskel: simple_content + { + virtual std::string + post_name () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_pskel (); + name_pskel (name_pskel* impl, void*); + + protected: + name_pskel* name_impl_; +#endif + }; + + struct nmtoken_pskel: simple_content + { + virtual std::string + post_nmtoken () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_pskel (); + nmtoken_pskel (nmtoken_pskel* impl, void*); + + protected: + nmtoken_pskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_pskel: list_base + { + virtual string_sequence* + post_nmtokens () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_pskel (); + nmtokens_pskel (nmtokens_pskel* impl, void*); + + protected: + nmtokens_pskel* nmtokens_impl_; +#endif + }; + + struct ncname_pskel: simple_content + { + virtual std::string + post_ncname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_pskel (); + ncname_pskel (ncname_pskel* impl, void*); + + protected: + ncname_pskel* ncname_impl_; +#endif + }; + + struct id_pskel: simple_content + { + virtual std::string + post_id () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_pskel (); + id_pskel (id_pskel* impl, void*); + + protected: + id_pskel* id_impl_; +#endif + }; + + struct idref_pskel: simple_content + { + virtual std::string + post_idref () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_pskel (); + idref_pskel (idref_pskel* impl, void*); + + protected: + idref_pskel* idref_impl_; +#endif + }; + + struct idrefs_pskel: list_base + { + virtual string_sequence* + post_idrefs () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_pskel (); + idrefs_pskel (idrefs_pskel* impl, void*); + + protected: + idrefs_pskel* idrefs_impl_; +#endif + }; + + struct language_pskel: simple_content + { + virtual std::string + post_language () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_pskel (); + language_pskel (language_pskel* impl, void*); + + protected: + language_pskel* language_impl_; +#endif + }; + + struct uri_pskel: simple_content + { + virtual std::string + post_uri () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_pskel (); + uri_pskel (uri_pskel* impl, void*); + + protected: + uri_pskel* uri_impl_; +#endif + }; + + struct qname_pskel: simple_content + { + virtual qname + post_qname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_pskel (); + qname_pskel (qname_pskel* impl, void*); + + protected: + qname_pskel* qname_impl_; +#endif + }; + +#else // XSDE_STL + + // Note that in this case you are getting a C string that you + // have to delete with delete[]. + // + struct string_pskel: simple_content + { + virtual char* + post_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_pskel (); + string_pskel (string_pskel* impl, void*); + + protected: + string_pskel* string_impl_; +#endif + }; + + struct normalized_string_pskel: simple_content + { + virtual char* + post_normalized_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_pskel (); + normalized_string_pskel (normalized_string_pskel* impl, void*); + + protected: + normalized_string_pskel* normalized_string_impl_; +#endif + }; + + struct token_pskel: simple_content + { + virtual char* + post_token () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_pskel (); + token_pskel (token_pskel* impl, void*); + + protected: + token_pskel* token_impl_; +#endif + }; + + struct name_pskel: simple_content + { + virtual char* + post_name () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_pskel (); + name_pskel (name_pskel* impl, void*); + + protected: + name_pskel* name_impl_; +#endif + }; + + struct nmtoken_pskel: simple_content + { + virtual char* + post_nmtoken () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_pskel (); + nmtoken_pskel (nmtoken_pskel* impl, void*); + + protected: + nmtoken_pskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_pskel: list_base + { + virtual string_sequence* + post_nmtokens () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_pskel (); + nmtokens_pskel (nmtokens_pskel* impl, void*); + + protected: + nmtokens_pskel* nmtokens_impl_; +#endif + }; + + struct ncname_pskel: simple_content + { + virtual char* + post_ncname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_pskel (); + ncname_pskel (ncname_pskel* impl, void*); + + protected: + ncname_pskel* ncname_impl_; +#endif + }; + + struct id_pskel: simple_content + { + virtual char* + post_id () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_pskel (); + id_pskel (id_pskel* impl, void*); + + protected: + id_pskel* id_impl_; +#endif + }; + + struct idref_pskel: simple_content + { + virtual char* + post_idref () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_pskel (); + idref_pskel (idref_pskel* impl, void*); + + protected: + idref_pskel* idref_impl_; +#endif + }; + + struct idrefs_pskel: list_base + { + virtual string_sequence* + post_idrefs () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_pskel (); + idrefs_pskel (idrefs_pskel* impl, void*); + + protected: + idrefs_pskel* idrefs_impl_; +#endif + }; + + struct language_pskel: simple_content + { + virtual char* + post_language () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_pskel (); + language_pskel (language_pskel* impl, void*); + + protected: + language_pskel* language_impl_; +#endif + }; + + struct uri_pskel: simple_content + { + virtual char* + post_uri () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_pskel (); + uri_pskel (uri_pskel* impl, void*); + + protected: + uri_pskel* uri_impl_; +#endif + }; + + struct qname_pskel: simple_content + { + virtual qname* + post_qname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_pskel (); + qname_pskel (qname_pskel* impl, void*); + + protected: + qname_pskel* qname_impl_; +#endif + }; +#endif // XSDE_STL + + + // base64Binary + // + struct base64_binary_pskel: simple_content + { + virtual buffer* + post_base64_binary () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + base64_binary_pskel (); + base64_binary_pskel (base64_binary_pskel* impl, void*); + + protected: + base64_binary_pskel* base64_binary_impl_; +#endif + }; + + // hexBinary + // + struct hex_binary_pskel: simple_content + { + virtual buffer* + post_hex_binary () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + hex_binary_pskel (); + hex_binary_pskel (hex_binary_pskel* impl, void*); + + protected: + hex_binary_pskel* hex_binary_impl_; +#endif + }; + + // Time and date types. + // + struct gday_pskel: simple_content + { + virtual gday + post_gday () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gday_pskel (); + gday_pskel (gday_pskel* impl, void*); + + protected: + gday_pskel* gday_impl_; +#endif + }; + + struct gmonth_pskel: simple_content + { + virtual gmonth + post_gmonth () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_pskel (); + gmonth_pskel (gmonth_pskel* impl, void*); + + protected: + gmonth_pskel* gmonth_impl_; +#endif + }; + + struct gyear_pskel: simple_content + { + virtual gyear + post_gyear () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_pskel (); + gyear_pskel (gyear_pskel* impl, void*); + + protected: + gyear_pskel* gyear_impl_; +#endif + }; + + struct gmonth_day_pskel: simple_content + { + virtual gmonth_day + post_gmonth_day () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_day_pskel (); + gmonth_day_pskel (gmonth_day_pskel* impl, void*); + + protected: + gmonth_day_pskel* gmonth_day_impl_; +#endif + }; + + struct gyear_month_pskel: simple_content + { + virtual gyear_month + post_gyear_month () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_month_pskel (); + gyear_month_pskel (gyear_month_pskel* impl, void*); + + protected: + gyear_month_pskel* gyear_month_impl_; +#endif + }; + + struct date_pskel: simple_content + { + virtual date + post_date () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_pskel (); + date_pskel (date_pskel* impl, void*); + + protected: + date_pskel* date_impl_; +#endif + }; + + struct time_pskel: simple_content + { + virtual time + post_time () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + time_pskel (); + time_pskel (time_pskel* impl, void*); + + protected: + time_pskel* time_impl_; +#endif + }; + + struct date_time_pskel: simple_content + { + virtual date_time + post_date_time () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_time_pskel (); + date_time_pskel (date_time_pskel* impl, void*); + + protected: + date_time_pskel* date_time_impl_; +#endif + }; + + struct duration_pskel: simple_content + { + virtual duration + post_duration () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + duration_pskel (); + duration_pskel (duration_pskel* impl, void*); + + protected: + duration_pskel* duration_impl_; +#endif + }; + } + } + } +} + +#include <xsde/cxx/parser/validating/xml-schema-pskel.ixx> + +#endif // XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx new file mode 100644 index 0000000..bb94f3e --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx @@ -0,0 +1,704 @@ +// file : xsde/cxx/parser/validating/xml-schema-pskel.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_type_pskel:: + any_type_pskel () + : any_type_impl_ (0) + { + } + + inline any_type_pskel:: + any_type_pskel (any_type_pskel* impl, void*) + : complex_content (impl, 0), any_type_impl_ (impl) + { + } +#endif + + // any_simple_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_simple_type_pskel:: + any_simple_type_pskel () + : any_simple_type_impl_ (0) + { + } + + inline any_simple_type_pskel:: + any_simple_type_pskel (any_simple_type_pskel* impl, void*) + : simple_content (impl, 0), any_simple_type_impl_ (impl) + { + } +#endif + + // boolean_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline boolean_pskel:: + boolean_pskel () + : boolean_impl_ (0) + { + } + + inline boolean_pskel:: + boolean_pskel (boolean_pskel* impl, void*) + : simple_content (impl, 0), boolean_impl_ (impl) + { + } +#endif + + // byte_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline byte_pskel:: + byte_pskel () + : byte_impl_ (0) + { + } + + inline byte_pskel:: + byte_pskel (byte_pskel* impl, void*) + : simple_content (impl, 0), byte_impl_ (impl) + { + } +#endif + + // unsigned_byte_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_byte_pskel:: + unsigned_byte_pskel () + : unsigned_byte_impl_ (0) + { + } + + inline unsigned_byte_pskel:: + unsigned_byte_pskel (unsigned_byte_pskel* impl, void*) + : simple_content (impl, 0), unsigned_byte_impl_ (impl) + { + } +#endif + + // short_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline short_pskel:: + short_pskel () + : short_impl_ (0) + { + } + + inline short_pskel:: + short_pskel (short_pskel* impl, void*) + : simple_content (impl, 0), short_impl_ (impl) + { + } +#endif + + // unsigned_short_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_short_pskel:: + unsigned_short_pskel () + : unsigned_short_impl_ (0) + { + } + + inline unsigned_short_pskel:: + unsigned_short_pskel (unsigned_short_pskel* impl, void*) + : simple_content (impl, 0), unsigned_short_impl_ (impl) + { + } +#endif + + // int_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline int_pskel:: + int_pskel () + : int_impl_ (0) + { + } + + inline int_pskel:: + int_pskel (int_pskel* impl, void*) + : simple_content (impl, 0), int_impl_ (impl) + { + } +#endif + + // unsigned_int_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_int_pskel:: + unsigned_int_pskel () + : unsigned_int_impl_ (0) + { + } + + inline unsigned_int_pskel:: + unsigned_int_pskel (unsigned_int_pskel* impl, void*) + : simple_content (impl, 0), unsigned_int_impl_ (impl) + { + } +#endif + + // long_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline long_pskel:: + long_pskel () + : long_impl_ (0) + { + } + + inline long_pskel:: + long_pskel (long_pskel* impl, void*) + : simple_content (impl, 0), long_impl_ (impl) + { + } +#endif + + // unsigned_long_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_long_pskel:: + unsigned_long_pskel () + : unsigned_long_impl_ (0) + { + } + + inline unsigned_long_pskel:: + unsigned_long_pskel (unsigned_long_pskel* impl, void*) + : simple_content (impl, 0), unsigned_long_impl_ (impl) + { + } +#endif + + // integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline integer_pskel:: + integer_pskel () + : integer_impl_ (0) + { + } + + inline integer_pskel:: + integer_pskel (integer_pskel* impl, void*) + : simple_content (impl, 0), integer_impl_ (impl) + { + } +#endif + + // negative_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline negative_integer_pskel:: + negative_integer_pskel () + : negative_integer_impl_ (0) + { + } + + inline negative_integer_pskel:: + negative_integer_pskel (negative_integer_pskel* impl, void*) + : simple_content (impl, 0), negative_integer_impl_ (impl) + { + } +#endif + + // non_positive_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_positive_integer_pskel:: + non_positive_integer_pskel () + : non_positive_integer_impl_ (0) + { + } + + inline non_positive_integer_pskel:: + non_positive_integer_pskel (non_positive_integer_pskel* impl, void*) + : simple_content (impl, 0), non_positive_integer_impl_ (impl) + { + } +#endif + + // positive_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline positive_integer_pskel:: + positive_integer_pskel () + : positive_integer_impl_ (0) + { + } + + inline positive_integer_pskel:: + positive_integer_pskel (positive_integer_pskel* impl, void*) + : simple_content (impl, 0), positive_integer_impl_ (impl) + { + } +#endif + + // non_negative_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_negative_integer_pskel:: + non_negative_integer_pskel () + : non_negative_integer_impl_ (0) + { + } + + inline non_negative_integer_pskel:: + non_negative_integer_pskel (non_negative_integer_pskel* impl, void*) + : simple_content (impl, 0), non_negative_integer_impl_ (impl) + { + } +#endif + + // float_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline float_pskel:: + float_pskel () + : float_impl_ (0) + { + } + + inline float_pskel:: + float_pskel (float_pskel* impl, void*) + : simple_content (impl, 0), float_impl_ (impl) + { + } +#endif + + // double_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline double_pskel:: + double_pskel () + : double_impl_ (0) + { + } + + inline double_pskel:: + double_pskel (double_pskel* impl, void*) + : simple_content (impl, 0), double_impl_ (impl) + { + } +#endif + + // decimal_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline decimal_pskel:: + decimal_pskel () + : decimal_impl_ (0) + { + } + + inline decimal_pskel:: + decimal_pskel (decimal_pskel* impl, void*) + : simple_content (impl, 0), decimal_impl_ (impl) + { + } +#endif + + // string_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline string_pskel:: + string_pskel () + : string_impl_ (0) + { + } + + inline string_pskel:: + string_pskel (string_pskel* impl, void*) + : simple_content (impl, 0), string_impl_ (impl) + { + } +#endif + + // normalized_string_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline normalized_string_pskel:: + normalized_string_pskel () + : normalized_string_impl_ (0) + { + } + + inline normalized_string_pskel:: + normalized_string_pskel (normalized_string_pskel* impl, void*) + : simple_content (impl, 0), normalized_string_impl_ (impl) + { + } +#endif + + // token_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline token_pskel:: + token_pskel () + : token_impl_ (0) + { + } + + inline token_pskel:: + token_pskel (token_pskel* impl, void*) + : simple_content (impl, 0), token_impl_ (impl) + { + } +#endif + + // name_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline name_pskel:: + name_pskel () + : name_impl_ (0) + { + } + + inline name_pskel:: + name_pskel (name_pskel* impl, void*) + : simple_content (impl, 0), name_impl_ (impl) + { + } +#endif + + // nmtoken_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtoken_pskel:: + nmtoken_pskel () + : nmtoken_impl_ (0) + { + } + + inline nmtoken_pskel:: + nmtoken_pskel (nmtoken_pskel* impl, void*) + : simple_content (impl, 0), nmtoken_impl_ (impl) + { + } +#endif + + // nmtokens_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtokens_pskel:: + nmtokens_pskel () + : nmtokens_impl_ (0) + { + } + + inline nmtokens_pskel:: + nmtokens_pskel (nmtokens_pskel* impl, void*) + : list_base (impl, 0), nmtokens_impl_ (impl) + { + } +#endif + + // ncname_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline ncname_pskel:: + ncname_pskel () + : ncname_impl_ (0) + { + } + + inline ncname_pskel:: + ncname_pskel (ncname_pskel* impl, void*) + : simple_content (impl, 0), ncname_impl_ (impl) + { + } +#endif + + // id_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline id_pskel:: + id_pskel () + : id_impl_ (0) + { + } + + inline id_pskel:: + id_pskel (id_pskel* impl, void*) + : simple_content (impl, 0), id_impl_ (impl) + { + } +#endif + + // idref_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idref_pskel:: + idref_pskel () + : idref_impl_ (0) + { + } + + inline idref_pskel:: + idref_pskel (idref_pskel* impl, void*) + : simple_content (impl, 0), idref_impl_ (impl) + { + } +#endif + + // idrefs_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idrefs_pskel:: + idrefs_pskel () + : idrefs_impl_ (0) + { + } + + inline idrefs_pskel:: + idrefs_pskel (idrefs_pskel* impl, void*) + : list_base (impl, 0), idrefs_impl_ (impl) + { + } +#endif + + // language_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline language_pskel:: + language_pskel () + : language_impl_ (0) + { + } + + inline language_pskel:: + language_pskel (language_pskel* impl, void*) + : simple_content (impl, 0), language_impl_ (impl) + { + } +#endif + + // uri_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline uri_pskel:: + uri_pskel () + : uri_impl_ (0) + { + } + + inline uri_pskel:: + uri_pskel (uri_pskel* impl, void*) + : simple_content (impl, 0), uri_impl_ (impl) + { + } +#endif + + // qname_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline qname_pskel:: + qname_pskel () + : qname_impl_ (0) + { + } + + inline qname_pskel:: + qname_pskel (qname_pskel* impl, void*) + : simple_content (impl, 0), qname_impl_ (impl) + { + } +#endif + + // base64_binary_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline base64_binary_pskel:: + base64_binary_pskel () + : base64_binary_impl_ (0) + { + } + + inline base64_binary_pskel:: + base64_binary_pskel (base64_binary_pskel* impl, void*) + : simple_content (impl, 0), base64_binary_impl_ (impl) + { + } +#endif + + // hex_binary_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline hex_binary_pskel:: + hex_binary_pskel () + : hex_binary_impl_ (0) + { + } + + inline hex_binary_pskel:: + hex_binary_pskel (hex_binary_pskel* impl, void*) + : simple_content (impl, 0), hex_binary_impl_ (impl) + { + } +#endif + + // gday_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gday_pskel:: + gday_pskel () + : gday_impl_ (0) + { + } + + inline gday_pskel:: + gday_pskel (gday_pskel* impl, void*) + : simple_content (impl, 0), gday_impl_ (impl) + { + } +#endif + + // gmonth_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_pskel:: + gmonth_pskel () + : gmonth_impl_ (0) + { + } + + inline gmonth_pskel:: + gmonth_pskel (gmonth_pskel* impl, void*) + : simple_content (impl, 0), gmonth_impl_ (impl) + { + } +#endif + + // gyear_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_pskel:: + gyear_pskel () + : gyear_impl_ (0) + { + } + + inline gyear_pskel:: + gyear_pskel (gyear_pskel* impl, void*) + : simple_content (impl, 0), gyear_impl_ (impl) + { + } +#endif + + // gmonth_day_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_day_pskel:: + gmonth_day_pskel () + : gmonth_day_impl_ (0) + { + } + + inline gmonth_day_pskel:: + gmonth_day_pskel (gmonth_day_pskel* impl, void*) + : simple_content (impl, 0), gmonth_day_impl_ (impl) + { + } +#endif + + // gyear_month_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_month_pskel:: + gyear_month_pskel () + : gyear_month_impl_ (0) + { + } + + inline gyear_month_pskel:: + gyear_month_pskel (gyear_month_pskel* impl, void*) + : simple_content (impl, 0), gyear_month_impl_ (impl) + { + } +#endif + + // date_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_pskel:: + date_pskel () + : date_impl_ (0) + { + } + + inline date_pskel:: + date_pskel (date_pskel* impl, void*) + : simple_content (impl, 0), date_impl_ (impl) + { + } +#endif + + // time_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline time_pskel:: + time_pskel () + : time_impl_ (0) + { + } + + inline time_pskel:: + time_pskel (time_pskel* impl, void*) + : simple_content (impl, 0), time_impl_ (impl) + { + } +#endif + + // date_time_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_time_pskel:: + date_time_pskel () + : date_time_impl_ (0) + { + } + + inline date_time_pskel:: + date_time_pskel (date_time_pskel* impl, void*) + : simple_content (impl, 0), date_time_impl_ (impl) + { + } +#endif + + // duration_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline duration_pskel:: + duration_pskel () + : duration_impl_ (0) + { + } + + inline duration_pskel:: + duration_pskel (duration_pskel* impl, void*) + : simple_content (impl, 0), duration_impl_ (impl) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/xml-schema.hxx b/libxsde/xsde/cxx/parser/xml-schema.hxx new file mode 100644 index 0000000..5b17568 --- /dev/null +++ b/libxsde/xsde/cxx/parser/xml-schema.hxx @@ -0,0 +1,20 @@ +// file : xsde/cxx/parser/xml-schema.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_XML_SCHEMA_HXX +#define XSDE_CXX_PARSER_XML_SCHEMA_HXX + +#include <xsde/cxx/buffer.hxx> +#include <xsde/cxx/date-time.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/qname-stl.hxx> +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/qname.hxx> +# include <xsde/cxx/string-sequence.hxx> +#endif + +#endif // XSDE_CXX_PARSER_XML_SCHEMA_HXX |