aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/parser
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-10-11 12:43:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-10-11 12:43:48 +0200
commit9553149aa6b6561c49981adf2848607a43765054 (patch)
treeff941ad89aa2c87ec5ddbd7a7bdd189fc33f87ba /libxsde/xsde/cxx/parser
parent0dd6d623af5dfe3590d0c269f76a2fa322e75e58 (diff)
Support for validation of the pattern facet
New test: hybrid/pattern.
Diffstat (limited to 'libxsde/xsde/cxx/parser')
-rw-r--r--libxsde/xsde/cxx/parser/validating/string-common.cxx43
-rw-r--r--libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx24
-rw-r--r--libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx27
3 files changed, 94 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/parser/validating/string-common.cxx b/libxsde/xsde/cxx/parser/validating/string-common.cxx
index 9558e30..1e3d8ba 100644
--- a/libxsde/xsde/cxx/parser/validating/string-common.cxx
+++ b/libxsde/xsde/cxx/parser/validating/string-common.cxx
@@ -3,6 +3,14 @@
// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+#include <xsde/cxx/config.hxx>
+
+#ifdef XSDE_REGEXP
+#ifdef XSDE_EXCEPTIONS
+# include <new> // std::bad_alloc
+#endif
+#endif
+
#include <xsde/cxx/string-search.hxx>
#include <xsde/cxx/parser/validating/string-common.hxx>
@@ -116,6 +124,41 @@ namespace xsde
}
}
+#ifdef XSDE_REGEXP
+ if (f.pattern_set_ != 0)
+ {
+ if (f.pattern_set_ == 1)
+ {
+ xmlRegexpPtr r = xmlRegexpCompile (
+ reinterpret_cast<const xmlChar*> (f.pattern_.str));
+
+ if (r == 0)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw std::bad_alloc ();
+#else
+ ctx.sys_error (sys_error::no_memory);
+ return false;
+#endif
+
+ }
+
+ string_facets::facets& t =
+ const_cast<string_facets::facets&> (f);
+
+ t.pattern_.regexp = r;
+ t.pattern_set_ = 2;
+ }
+
+ if (xmlRegexpExec (
+ f.pattern_.regexp,
+ reinterpret_cast<const xmlChar*> (s)) != 1)
+ {
+ ctx.schema_error (schema_error::value_pattern_mismatch);
+ return false;
+ }
+ }
+#endif
return true;
}
}
diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx
index 1ef1005..8823846 100644
--- a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx
+++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx
@@ -12,6 +12,10 @@
# include <string>
#endif
+#ifdef XSDE_REGEXP
+# include <xsde/c/regexp/xmlregexp.h>
+#endif
+
#include <xsde/cxx/parser/xml-schema.hxx>
#include <xsde/cxx/parser/validating/parser.hxx>
@@ -662,6 +666,9 @@ namespace xsde
struct string_facets
{
string_facets ();
+#ifdef XSDE_REGEXP
+ ~string_facets ();
+#endif
void
_length_facet (size_t);
@@ -678,6 +685,9 @@ namespace xsde
void
_enumeration_facet (const char* const*, size_t count);
+ void
+ _pattern_facet (const char*);
+
public:
struct facets
{
@@ -688,10 +698,24 @@ namespace xsde
const char* const* enum_;
size_t enum_count_;
+#ifdef XSDE_REGEXP
+ union
+ {
+ const char* str;
+ xmlRegexpPtr regexp;
+ } pattern_;
+#endif
unsigned int length_set_ : 1;
unsigned int min_length_set_ : 1;
unsigned int max_length_set_ : 1;
+#ifdef XSDE_REGEXP
+ // 0 - not set
+ // 1 - string
+ // 2 - compiled
+ //
+ unsigned int pattern_set_: 2;
+#endif
// 0 - preserve
// 1 - replace
// 2 - collapse
diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx
index 0a8f99a..a9d01f1 100644
--- a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx
+++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx
@@ -458,7 +458,20 @@ namespace xsde
facets_.enum_ = 0;
facets_.enum_count_ = 0;
+
+#ifdef XSDE_REGEXP
+ facets_.pattern_set_ = 0;
+#endif
+ }
+
+#ifdef XSDE_REGEXP
+ inline string_facets::
+ ~string_facets ()
+ {
+ if (facets_.pattern_set_ == 2)
+ xmlRegFreeRegexp (facets_.pattern_.regexp);
}
+#endif
inline void string_facets::
_length_facet (size_t v)
@@ -494,6 +507,20 @@ namespace xsde
facets_.enum_count_ = count;
}
+#ifndef XSDE_REGEXP
+ inline void string_facets::
+ _pattern_facet (const char*)
+ {
+ }
+#else
+ inline void string_facets::
+ _pattern_facet (const char* s)
+ {
+ facets_.pattern_.str = s;
+ facets_.pattern_set_ = 1;
+ }
+#endif
+
// string_pskel
//
#ifdef XSDE_REUSE_STYLE_TIEIN