diff options
Diffstat (limited to 'TAO')
-rw-r--r-- | TAO/tao/CDR.h | 27 | ||||
-rw-r--r-- | TAO/tao/CDR.inl | 72 | ||||
-rw-r--r-- | TAO/tao/Codeset/UTF16_BOM_Translator.cpp | 68 | ||||
-rw-r--r-- | TAO/tao/Codeset/UTF16_BOM_Translator.h | 4 | ||||
-rw-r--r-- | TAO/tao/Codeset/UTF8_Latin1_Translator.cpp | 49 | ||||
-rw-r--r-- | TAO/tao/Codeset/UTF8_Latin1_Translator.h | 2 |
6 files changed, 171 insertions, 51 deletions
diff --git a/TAO/tao/CDR.h b/TAO/tao/CDR.h index 65d120186f0..3360714ffe4 100644 --- a/TAO/tao/CDR.h +++ b/TAO/tao/CDR.h @@ -442,25 +442,6 @@ public: /// Called after demarshalling. void reset_vt_indirect_maps (); - /// Helper classes for extracting bounded strings into std::string/wstring. - struct TAO_Export to_std_string - { - to_std_string (std::string &s, - ACE_CDR::ULong b); - std::string &val_; - ACE_CDR::ULong bound_; - }; - -#if !defined(ACE_LACKS_STD_WSTRING) - struct TAO_Export to_std_wstring - { - to_std_wstring (std::wstring &ws, - ACE_CDR::ULong b); - std::wstring &val_; - ACE_CDR::ULong bound_; - }; -#endif /* ACE_LACKS_STD_WSTRING */ - private: /// The ORB_Core, required to extract object references. TAO_ORB_Core* orb_core_; @@ -509,9 +490,13 @@ TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os, ACE_OutputCDR::from_wstring x); TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os, const std::string &x); +TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os, + ACE_OutputCDR::from_std_string x); #if !defined(ACE_LACKS_STD_WSTRING) TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os, const std::wstring &x); +TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os, + ACE_OutputCDR::from_std_wstring x); #endif /* ACE_LACKS_STD_WSTRING */ // CDR input operators for CORBA types @@ -545,12 +530,12 @@ TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &os, TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &os, std::string &x); TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &os, - TAO_InputCDR::to_std_string x); + ACE_InputCDR::to_std_string x); #if !defined(ACE_LACKS_STD_WSTRING) TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &os, std::wstring &x); TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &os, - TAO_InputCDR::to_std_wstring x); + ACE_InputCDR::to_std_wstring x); #endif /* ACE_LACKS_STD_WSTRING */ TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/tao/CDR.inl b/TAO/tao/CDR.inl index fcf3d9d5b13..c4fb156fcc5 100644 --- a/TAO/tao/CDR.inl +++ b/TAO/tao/CDR.inl @@ -326,24 +326,6 @@ TAO_InputCDR::reset_vt_indirect_maps () } } -ACE_INLINE -TAO_InputCDR::to_std_string::to_std_string (std::string &s, - ACE_CDR::ULong b) - : val_ (s), - bound_ (b) -{ -} - -#if !defined(ACE_LACKS_STD_WSTRING) -ACE_INLINE -TAO_InputCDR::to_std_wstring::to_std_wstring (std::wstring &s, - ACE_CDR::ULong b) - : val_ (s), - bound_ (b) -{ -} -#endif /* ACE_LACKS_STD_WSTRING */ - // **************************************************************** ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os, @@ -472,14 +454,52 @@ ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os, ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os, const std::string &x) { +#if defined (ACE_HAS_CPP11) + return + os.fragment_stream (ACE_CDR::OCTET_ALIGN, + sizeof (char)) + && static_cast<ACE_OutputCDR &> (os) << x; +#else return os << x.c_str (); +#endif +} + +ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os, + ACE_OutputCDR::from_std_string x) +{ + if (x.bound_ != 0 && + static_cast<ACE_CDR::ULong> (x.val_.size ()) > x.bound_) + { + throw CORBA::BAD_PARAM (); + } + return os << x.val_; } #if !defined(ACE_LACKS_STD_WSTRING) ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os, const std::wstring &x) { +#if defined (ACE_HAS_CPP11) + return + os.fragment_stream ((sizeof (CORBA::WChar) == 2 + ? ACE_CDR::SHORT_ALIGN + : ACE_CDR::LONG_ALIGN), + sizeof (CORBA::WChar)) + && static_cast<ACE_OutputCDR &> (os) << x; +#else return os << x.c_str (); +#endif +} + +ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os, + ACE_OutputCDR::from_std_wstring x) +{ + if (x.bound_ != 0 && + static_cast<ACE_CDR::ULong> (x.val_.size ()) > x.bound_) + { + throw CORBA::BAD_PARAM (); + } + return os << x.val_; } #endif /* ACE_LACKS_STD_WSTRING */ @@ -580,15 +600,11 @@ ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is, ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is, std::string &x) { - char *buf = 0; - CORBA::Boolean const marshal_flag = is >> buf; - x.assign (buf); - ACE::strdelete (buf); - return marshal_flag; + return static_cast<ACE_InputCDR &> (is) >> x; } ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is, - TAO_InputCDR::to_std_string x) + ACE_InputCDR::to_std_string x) { CORBA::Boolean const marshal_flag = is >> x.val_; if (marshal_flag && x.bound_ != 0 && x.val_.size () > x.bound_) @@ -602,15 +618,11 @@ ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is, ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is, std::wstring &x) { - CORBA::WChar *buf = 0; - CORBA::Boolean const marshal_flag = is >> buf; - x.assign (buf); - ACE::strdelete (buf); - return marshal_flag; + return static_cast<ACE_InputCDR &> (is) >> x; } ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is, - TAO_InputCDR::to_std_wstring x) + ACE_InputCDR::to_std_wstring x) { CORBA::Boolean const marshal_flag = is >> x.val_; if (marshal_flag && x.bound_ != 0 && x.val_.size () > x.bound_) diff --git a/TAO/tao/Codeset/UTF16_BOM_Translator.cpp b/TAO/tao/Codeset/UTF16_BOM_Translator.cpp index ad66904c07a..0d0169cdd11 100644 --- a/TAO/tao/Codeset/UTF16_BOM_Translator.cpp +++ b/TAO/tao/Codeset/UTF16_BOM_Translator.cpp @@ -165,6 +165,74 @@ TAO_UTF16_BOM_Translator::read_wstring (ACE_InputCDR &cdr, return 0; } +#if !defined(ACE_LACKS_STD_WSTRING) +ACE_CDR::Boolean +TAO_UTF16_BOM_Translator::read_wstring (ACE_InputCDR &cdr, + std::wstring &x) +{ +#if defined (ACE_HAS_CPP11) + ACE_CDR::ULong len; + if (!this->read_4 (cdr, &len)) + return false; + + // A check for the length being too great is done later in the + // call to read_char_array but we want to have it done before + // the memory is allocated. + if (len > 0 && len <= cdr.length ()) + { + if (static_cast<ACE_CDR::Short> (this->major_version (cdr)) == 1 + && static_cast<ACE_CDR::Short> (this->minor_version (cdr)) > 1) + { + len /= ACE_UTF16_CODEPOINT_SIZE; + + try + { + x.resize (len); + } + catch (const std::bad_alloc&) + { + return false; + } + + if (this->read_wchar_array_i (cdr, &x[0], len, 1)) + { + // Since reading the array may have adjusted the length, + // shrink to fit + x.resize (len); + return true; + } + } + else + { + try + { + x.resize (len); + } + catch (const std::bad_alloc&) + { + return false; + } + + if (this->read_wchar_array (cdr, &x[0], len)) + { + x.resize (len-1); // drop terminating zero wchar read from stream + return true; + } + } + } + else if (len == 0) + { + x.clear (); + return true; + } + x.clear (); + return false; +#else + return this->ACE_WChar_Codeset_Translator::read_wstring (cdr, x); +#endif +} +#endif + ACE_CDR::Boolean TAO_UTF16_BOM_Translator::read_wchar_array_i (ACE_InputCDR & cdr, ACE_CDR::WChar *x, diff --git a/TAO/tao/Codeset/UTF16_BOM_Translator.h b/TAO/tao/Codeset/UTF16_BOM_Translator.h index 20d9ac2ad1e..19c3b8eb159 100644 --- a/TAO/tao/Codeset/UTF16_BOM_Translator.h +++ b/TAO/tao/Codeset/UTF16_BOM_Translator.h @@ -52,6 +52,10 @@ public: ACE_CDR::WChar &); virtual ACE_CDR::Boolean read_wstring (ACE_InputCDR &, ACE_CDR::WChar *&); +#if !defined(ACE_LACKS_STD_WSTRING) + virtual ACE_CDR::Boolean read_wstring (ACE_InputCDR&, + std::wstring &); +#endif virtual ACE_CDR::Boolean read_wchar_array (ACE_InputCDR &, ACE_CDR::WChar *, ACE_CDR::ULong); diff --git a/TAO/tao/Codeset/UTF8_Latin1_Translator.cpp b/TAO/tao/Codeset/UTF8_Latin1_Translator.cpp index 5dfb557ff0b..6da6df8f67a 100644 --- a/TAO/tao/Codeset/UTF8_Latin1_Translator.cpp +++ b/TAO/tao/Codeset/UTF8_Latin1_Translator.cpp @@ -118,6 +118,55 @@ TAO_UTF8_Latin1_Translator::read_string (ACE_InputCDR &cdr, } ACE_CDR::Boolean +TAO_UTF8_Latin1_Translator::read_string (ACE_InputCDR &cdr, + std::string &x) +{ +#if defined (ACE_HAS_CPP11) + ACE_CDR::ULong len; + if (!cdr.read_ulong (len)) + return false; + + // A check for the length being too great is done later in the + // call to read_char_array but we want to have it done before + // the memory is allocated. + if (len > 0 && len <= cdr.length()) + { + // detract terminating '\0' from length + len--; + try + { + x.resize (len); + } + catch (const std::bad_alloc&) + { + return false; + } + + // pos keeps track of the character position, it will never be + // greater than len + size_t pos = 0; + ACE_CDR::ULong incr = 1; + for (ACE_CDR::ULong i = 0; incr > 0 && i < len; i += incr) + { + incr = this->read_char_i(cdr,x[pos++]); + } + if (incr > 0) + { + // read terminating '\0' from stream + ACE_CDR::Char c; + incr = this->read_char_i(cdr, c); + return (incr > 0); + } + } + + x.clear (); + return false; +#else + return this->ACE_Char_Codeset_Translator::read_string (cdr, x); +#endif +} + +ACE_CDR::Boolean TAO_UTF8_Latin1_Translator::read_char_array (ACE_InputCDR & cdr, ACE_CDR::Char *x, ACE_CDR::ULong length) diff --git a/TAO/tao/Codeset/UTF8_Latin1_Translator.h b/TAO/tao/Codeset/UTF8_Latin1_Translator.h index 2fac7ed1f80..6bccd0bee8c 100644 --- a/TAO/tao/Codeset/UTF8_Latin1_Translator.h +++ b/TAO/tao/Codeset/UTF8_Latin1_Translator.h @@ -56,6 +56,8 @@ public: ACE_CDR::Char &); virtual ACE_CDR::Boolean read_string (ACE_InputCDR &, ACE_CDR::Char *&); + virtual ACE_CDR::Boolean read_string (ACE_InputCDR &, + std::string &); virtual ACE_CDR::Boolean read_char_array (ACE_InputCDR &, ACE_CDR::Char *, ACE_CDR::ULong); |