From 90e0d12d8fcda9cce08a4037493acada078e72ce Mon Sep 17 00:00:00 2001 From: kgv Date: Wed, 18 Nov 2020 14:56:59 +0300 Subject: [PATCH] 0031940: Foundation Classes - TCollection_ExtendedString::Print() corrupts UNICODE strings and does not compile with C++20 TCollection_ExtendedString::Print() now converts string into UTF-8 instead of printing character indexes. --- dox/upgrade/upgrade.md | 7 +++++++ src/TCollection/TCollection_ExtendedString.cxx | 16 ++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dox/upgrade/upgrade.md b/dox/upgrade/upgrade.md index 34958e3bd6..f8221fc810 100644 --- a/dox/upgrade/upgrade.md +++ b/dox/upgrade/upgrade.md @@ -2159,6 +2159,13 @@ Existing message files containing 8-bit characters (previously interpreted as ch @section upgrade_occt760 Upgrade to OCCT 7.6.0 +@subsection upgrade_760_extendedstring_cout Output of TCollection_ExtendedString to stream + +Behavior of the method TCollection_ExtendedString::Print(Standard_OStream&) and corresponding operator << has changed. +Previously it printed all Latin-1 symbols (those in range 0x80-0xff) as '\0' (effectively loosing them); symbols above 0xff were converted to hex representation (formatted like XML Numeric Character Reference). +Now all symbols are sent to stream as UTF-8 byte sequences. +Existing code relying on old behavior, if any, shall be rewritten. + @subsection upgrade_760_trimming_surface Trimming surface Geom_RectangularTrimmedSurface sequentially trimming in U and V directions already no longer loses the first trim. diff --git a/src/TCollection/TCollection_ExtendedString.cxx b/src/TCollection/TCollection_ExtendedString.cxx index 00c60225ad..30597cb0ce 100644 --- a/src/TCollection/TCollection_ExtendedString.cxx +++ b/src/TCollection/TCollection_ExtendedString.cxx @@ -611,16 +611,12 @@ Standard_Integer TCollection_ExtendedString::Length() const // ---------------------------------------------------------------------------- // Print // ---------------------------------------------------------------------------- -void TCollection_ExtendedString::Print(Standard_OStream& astream) const -{ - // ASCII symbols (including extended Ascii) are printed as is; - // other Unicode characters are encoded as SGML numeric character references - for (Standard_Integer i = 0 ; i < mylength ; i++) { - Standard_ExtCharacter c = mystring[i]; - if ( IsAnAscii(c) ) - astream << ToCharacter(c); - else - astream << "&#" << c << ";"; +void TCollection_ExtendedString::Print (Standard_OStream& theStream) const +{ + if (mylength > 0) + { + const TCollection_AsciiString aUtf8 (mystring); + theStream << aUtf8; } }