diff options
author | Martin Corino <mcorino@remedy.nl> | 2018-08-03 14:15:38 +0200 |
---|---|---|
committer | Martin Corino <mcorino@remedy.nl> | 2018-08-04 13:56:37 +0200 |
commit | 4a09b0b10cbea1fdcb16161583ee22f7d151784b (patch) | |
tree | 3a69f80021bf06e96197cd5bae164d8ebff657f3 /TAO/tao/Codeset/UTF8_Latin1_Translator.cpp | |
parent | 81d3d81c4cf0904cd8d5b4c0872cd1821b5d874e (diff) | |
download | ATCD-4a09b0b10cbea1fdcb16161583ee22f7d151784b.tar.gz |
add full support for streaming std::(w)string
(optimized for C++11 and onwards)
added tests for optimized std::(w)string support
extend character translators with std::(w)string support also
Diffstat (limited to 'TAO/tao/Codeset/UTF8_Latin1_Translator.cpp')
-rw-r--r-- | TAO/tao/Codeset/UTF8_Latin1_Translator.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
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) |