try including the ostream<<OUString operator directly with OUString

The theory is that

- the operator is suboptimal, because it always uses utf-8 as the encoding,
  which might possibly lead to some encoding problem somewhere

but

- the SAL_LOG macros need it anyway, or they are otherwise cumbersome
  with OUString
- as people learn to use the macros more, rtl/oustringostreaminserter.hxx
  will be included in more and more places, eventually possibly triggering
  the above problem anyway
- people probably should not just blindly do ostream << oustring if they
  have special encoding requirements

So let's try to simply always have the operator available and see how
it works out.
This commit is contained in:
Luboš Luňák 2012-04-03 17:29:08 +02:00
parent 7d540bd08e
commit 2ac5b08361
3 changed files with 15 additions and 14 deletions

View file

@ -34,14 +34,6 @@
#include "rtl/textenc.h" #include "rtl/textenc.h"
#include "rtl/ustring.hxx" #include "rtl/ustring.hxx"
/** Include this header to support rtl::OUString in std::ostream (and thus in
CPPUNIT_ASSERT macros, for example).
The rtl::OUString is converted to UTF-8.
@since LibreOffice 3.5.
*/
// The unittest uses slightly different code to help check that the proper // The unittest uses slightly different code to help check that the proper
// calls are made. The class is put into a different namespace to make // calls are made. The class is put into a different namespace to make
// sure the compiler generates a different (if generating also non-inline) // sure the compiler generates a different (if generating also non-inline)
@ -57,6 +49,14 @@ namespace rtl {
#undef rtl #undef rtl
#endif #endif
/**
Support for rtl::OUString in std::ostream (and thus in
CPPUNIT_ASSERT or SAL_INFO macros, for example).
The rtl::OUString is converted to UTF-8.
@since LibreOffice 3.5.
*/
template< typename charT, typename traits > std::basic_ostream<charT, traits> & template< typename charT, typename traits > std::basic_ostream<charT, traits> &
operator <<( operator <<(
std::basic_ostream<charT, traits> & stream, rtl::OUString const & string) std::basic_ostream<charT, traits> & stream, rtl::OUString const & string)

View file

@ -2085,4 +2085,9 @@ inline OString OUStringToOString( const OUString & rUnicode,
#endif /* _RTL_USTRING_HXX */ #endif /* _RTL_USTRING_HXX */
// Include the ostream << operator directly here, so that it's always available
// for SAL_INFO etc. Make sure it's outside of #ifdef _RTL_USTRING_HXX, because
// includes ustring.hxx back.
#include <rtl/oustringostreaminserter.hxx>
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -197,13 +197,9 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
SAL_INFO("foo", "string " << s << " of length " << n) SAL_INFO("foo", "string " << s << " of length " << n)
would be an example of such a call; if the given s is of type rtl::OUString, would be an example of such a call.
\#include "rtl/oustringostreaminserter.hxx" In the composed message should be in UTF-8 and it should
would make sure that an appropriate operator << is available.
In either case, the composed message should be in UTF-8 and it should
contain no vertical formatting characters and no null characters contain no vertical formatting characters and no null characters
For the _IF variants, log output is only generated if the given condition is For the _IF variants, log output is only generated if the given condition is