Kaydet (Commit) 96b45756 authored tarafından Luboš Luňák's avatar Luboš Luňák

move ostream OUString operator<< directly to ustring.hxx

It apparently works that way, so there's no need to have
an #include loop.

Change-Id: I58d4f0461c14637872a139f0fbfb78f2a99fe28a
üst c3c0ae7f
......@@ -27,47 +27,9 @@
#ifndef INCLUDED_RTL_OUSTRINGOSTREAMINSERTER_HXX
#define INCLUDED_RTL_OUSTRINGOSTREAMINSERTER_HXX
#include "sal/config.h"
#include <ostream>
#include "rtl/textenc.h"
#include "rtl/ustring.hxx"
// 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
// sure the compiler generates a different (if generating also non-inline)
// copy of the function and does not merge them together. The class
// is "brought" into the proper rtl namespace by a typedef below.
#ifdef RTL_STRING_UNITTEST
#define rtl rtlunittest
#endif
namespace rtl {
#ifdef RTL_STRING_UNITTEST
#undef rtl
#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 >
inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, rtl::OUString const & string)
{
return stream <<
rtl::OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr();
// best effort; potentially loses data due to conversion failures
// (stray surrogate halves) and embedded null characters
}
}
// File kept only for backwards compatibility, the inserter is now defined
// together with OUString.
#include <rtl/ustring.hxx>
#endif
......
......@@ -32,12 +32,14 @@
#include "sal/config.h"
#include <cassert>
#include <ostream>
#include "osl/diagnose.h"
#include <rtl/ustring.h>
#include <rtl/string.hxx>
#include <rtl/stringutils.hxx>
#include <rtl/memory.h>
#include <rtl/textenc.h>
#include "sal/log.hxx"
#if defined EXCEPTIONS_OFF
......@@ -2141,6 +2143,35 @@ inline OString OUStringToOString( const OUString & rUnicode,
} /* Namespace */
#ifdef RTL_STRING_UNITTEST
#define rtl rtlunittest
#endif
namespace rtl
{
#ifdef RTL_STRING_UNITTEST
#undef rtl
#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 >
inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, OUString const & string)
{
return stream <<
rtl::OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr();
// best effort; potentially loses data due to conversion failures
// (stray surrogate halves) and embedded null characters
}
} // namespace
// RTL_USING is defined by gbuild for all modules except those with stable public API
// (as listed in ure/source/README). It allows to use classes like OUString without
// having to explicitly refer to the rtl namespace, which is kind of superfluous
......@@ -2154,9 +2185,4 @@ using ::rtl::OUStringToOString;
#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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment