From d6313f9155195b856ee8170efb6d67e4072e64bc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 8 Sep 2010 16:24:44 +0200 Subject: Handle NULL and empty namespace value in serializer --- libxsde/xsde/cxx/serializer/genx/document.cxx | 57 +++++++++++++-------------- libxsde/xsde/cxx/serializer/genx/document.hxx | 4 ++ 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/libxsde/xsde/cxx/serializer/genx/document.cxx b/libxsde/xsde/cxx/serializer/genx/document.cxx index 5514765..4c634a4 100644 --- a/libxsde/xsde/cxx/serializer/genx/document.cxx +++ b/libxsde/xsde/cxx/serializer/genx/document.cxx @@ -86,14 +86,7 @@ namespace xsde #ifdef XSDE_POLYMORPHIC root_static_type_ = st; #endif - // Leave root_ns_ uninitialized. - // -#ifdef XSDE_EXCEPTIONS - root_name_.assign (name); -#else - if (root_name_.assign (name)) - error_ = error (sys_error::no_memory); -#endif + init_root_name (0, name); } document_simpl:: @@ -113,13 +106,7 @@ namespace xsde #ifdef XSDE_POLYMORPHIC root_static_type_ = st; #endif -#ifdef XSDE_EXCEPTIONS - root_ns_.assign (ns); - root_name_.assign (name); -#else - if (root_ns_.assign (ns) || root_name_.assign (name)) - error_ = error (sys_error::no_memory); -#endif + init_root_name (ns, name); } #ifdef XSDE_STL @@ -137,14 +124,7 @@ namespace xsde #ifdef XSDE_POLYMORPHIC root_static_type_ = st; #endif - // Leave root_ns_ uninitialized. - // -#ifdef XSDE_EXCEPTIONS - root_name_.assign (name.c_str (), name.size ()); -#else - if (root_name_.assign (name.c_str (), name.size ())) - error_ = error (sys_error::no_memory); -#endif + init_root_name (0, name.c_str ()); } document_simpl:: @@ -164,17 +144,36 @@ namespace xsde #ifdef XSDE_POLYMORPHIC root_static_type_ = st; #endif + init_root_name (ns.c_str (), name.c_str ()); + } +#endif // XSDE_STL + + + void document_simpl:: + init_root_name (const char* ns, const char* name) + { + // Leave root_ns_ uninitialized if ns is not specified. + // + if (ns != 0 && *ns != '\0') + { +#ifdef XSDE_EXCEPTIONS + root_ns_.assign (ns); +#else + if (root_ns_.assign (ns)) + { + error_ = error (sys_error::no_memory); + return; + } +#endif + } + #ifdef XSDE_EXCEPTIONS - root_ns_.assign (ns.c_str (), ns.size ()); - root_name_.assign (name.c_str (), name.size ()); + root_name_.assign (name); #else - if (root_ns_.assign (ns.c_str (), ns.size ()) || - root_name_.assign (name.c_str (), name.size ())) + if (root_name_.assign (name)) error_ = error (sys_error::no_memory); #endif } -#endif // XSDE_STL - void document_simpl:: add_prefix (const char* p, const char* ns) diff --git a/libxsde/xsde/cxx/serializer/genx/document.hxx b/libxsde/xsde/cxx/serializer/genx/document.hxx index 2d7dd5c..10d82db 100644 --- a/libxsde/xsde/cxx/serializer/genx/document.hxx +++ b/libxsde/xsde/cxx/serializer/genx/document.hxx @@ -283,6 +283,10 @@ namespace xsde #ifndef XSDE_EXCEPTIONS error error_; #endif + + private: + void + init_root_name (const char* ns, const char* name); }; } } -- cgit v1.1