aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-12-03 17:02:56 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-12-03 17:02:56 +0200
commitd71611d5fb575078bdf573c35257bb86bb7054e0 (patch)
tree9702bfd0a370ececb7a6b57dcee0913938080f7a
parent5212455789c8600ac830afbd3e8c55c76b2104ed (diff)
Implement automatic mapping for urn-style XML namespaces
-rw-r--r--NEWS3
-rw-r--r--xsd/cxx/elements.cxx27
-rw-r--r--xsd/cxx/elements.hxx4
3 files changed, 29 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 9b73e6e..9472972 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@ Version 3.3.0
enabled then you will also need to build it with Xerces-C++ 3.1.0 or
later to take advantage of this feature.
+ * Automatic mapping for the urn-style XML namespaces. The last component
+ in the urn name is used to derive the C++ namespace name.
+
* Warning id's have changed to start with a letter identifying the
component issuing the warning. F - compiler frontend, D - compiler
driver, P - C++/Parser mapping, T - C++/Tree mapping.
diff --git a/xsd/cxx/elements.cxx b/xsd/cxx/elements.cxx
index 3cd5e9e..fd23fc0 100644
--- a/xsd/cxx/elements.cxx
+++ b/xsd/cxx/elements.cxx
@@ -144,6 +144,8 @@ namespace CXX
cxx_id_expr_ (L"^(::)?([a-zA-Z_]\\w*)(::[a-zA-Z_]\\w*)*$"),
cxx_id_expr (cxx_id_expr_),
trace_namespace_regex (trace_namespace_regex_),
+ urn_mapping_ (L"#^urn.*:([a-zA-Z_].*)$#$1#"),
+ urn_mapping (urn_mapping_),
nsr_mapping (nsr_mapping_),
nsm_mapping (nsm_mapping_),
include_mapping (include_mapping_),
@@ -352,22 +354,37 @@ namespace CXX
if (!found)
{
+ String const& n (ns.name ());
+
// Check if the name is valid by itself.
//
- if (ns.name ().empty ())
+ if (n.empty ())
{
// Empty name denotes a no-namespace case.
//
- tmp = ns.name ();
+ tmp = n;
}
else
{
- tmp = colon.merge (ns.name ()); // replace `/' with `::'
+ tmp = colon.merge (n); // replace `/' with `::'
if (!cxx_id_expr.match (tmp))
{
- throw NoNamespaceMapping (
- ns.file (), ns.line (), ns.column (), ns.name ());
+ // See if this is a urn-style namespace.
+ //
+ if (urn_mapping.match (n))
+ {
+ Regex filter (L"#[.:-]#_#");
+ tmp = urn_mapping.merge (n);
+ tmp = filter.merge (tmp);
+
+ if (!cxx_id_expr.match (tmp))
+ throw NoNamespaceMapping (
+ ns.file (), ns.line (), ns.column (), ns.name ());
+ }
+ else
+ throw NoNamespaceMapping (
+ ns.file (), ns.line (), ns.column (), ns.name ());
}
}
}
diff --git a/xsd/cxx/elements.hxx b/xsd/cxx/elements.hxx
index e478234..39eee77 100644
--- a/xsd/cxx/elements.hxx
+++ b/xsd/cxx/elements.hxx
@@ -152,6 +152,7 @@ namespace CXX
xs_ns_ (c.xs_ns_),
cxx_id_expr (c.cxx_id_expr),
trace_namespace_regex (c.trace_namespace_regex),
+ urn_mapping (c.urn_mapping),
nsr_mapping (c.nsr_mapping),
nsm_mapping (c.nsm_mapping),
include_mapping (c.include_mapping),
@@ -176,6 +177,7 @@ namespace CXX
xs_ns_ (c.xs_ns_),
cxx_id_expr (c.cxx_id_expr),
trace_namespace_regex (c.trace_namespace_regex),
+ urn_mapping (c.urn_mapping),
nsr_mapping (c.nsr_mapping),
nsm_mapping (c.nsm_mapping),
include_mapping (c.include_mapping),
@@ -338,8 +340,10 @@ namespace CXX
RegexPat const cxx_id_expr_;
RegexPat const& cxx_id_expr;
Boolean trace_namespace_regex;
+ Regex urn_mapping_;
RegexMapping nsr_mapping_;
MapMapping nsm_mapping_;
+ Regex const& urn_mapping;
RegexMapping const& nsr_mapping;
MapMapping const& nsm_mapping;
MappingCache ns_mapping_cache_;