summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-12-07 18:13:31 +0100
committerLuboš Luňák <l.lunak@suse.cz>2012-12-07 19:48:16 +0100
commit49a9d370e6598284c0a337d0f4f7ec329187de53 (patch)
tree4bc861c85a942bb41f62838744c4218da9288992
parent1aad4689babec28f47b99666b303ab8bfffc3106 (diff)
add rtl::OUStringBuffer::append(bool)
The same as 563fa900ba22bf83dfa58e67807ed0337f810576 , but this time with extra care to not break anything with pointer->bool conversions. Change-Id: Ifcea840e96da0fbfcf92b54141fb8ef9c5eb94ff
-rw-r--r--config/config_global.h.in1
-rw-r--r--configure.ac28
-rw-r--r--sal/inc/rtl/stringutils.hxx23
-rw-r--r--sal/inc/rtl/ustrbuf.hxx40
4 files changed, 91 insertions, 1 deletions
diff --git a/config/config_global.h.in b/config/config_global.h.in
index a9eb54f68c34..77980d48fde5 100644
--- a/config/config_global.h.in
+++ b/config/config_global.h.in
@@ -9,6 +9,7 @@ Any change in this header will cause a rebuild of almost everything.
*/
+#undef HAVE_CXX11_DELETE
#undef HAVE_GCC_BUILTIN_ATOMIC
#undef HAVE_SFINAE_ANONYMOUS_BROKEN
#undef HAVE_THREADSAFE_STATICS
diff --git a/configure.ac b/configure.ac
index 9a0d449c26c4..5cc0d71394e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5705,6 +5705,34 @@ AC_SUBST(HAVE_GCC_NO_LONG_DOUBLE)
AC_SUBST(HAVE_GCC_AVX)
AC_SUBST(HAVE_GCC_BUILTIN_ATOMIC)
+dnl ==================================
+dnl Check for C++11 "= delete" support
+dnl ==================================
+
+AC_MSG_CHECKING([whether $CXX supports C++11 = delete syntax])
+if test "$HAVE_CXX0X" = "TRUE"; then
+ save_CXXFLAGS=$CXXFLAGS
+ CXXFLAGS="$CXXFLAGS -std=gnu++0x"
+ AC_LANG_PUSH([C++])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+struct A
+ {
+ void test() = delete;
+ };
+]])],[HAVE_CXX11_DELETE=TRUE],[])
+
+ AC_LANG_POP([C++])
+ CXXFLAGS=$save_CXXFLAGS
+ if test "$HAVE_CXX11_DELETE" = "TRUE"; then
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_CXX11_DELETE])
+ else
+ AC_MSG_RESULT([no])
+ fi
+else
+ AC_MSG_RESULT([no (C++11 disabled)])
+fi
+
dnl ===================================================================
dnl system stl sanity tests
dnl ===================================================================
diff --git a/sal/inc/rtl/stringutils.hxx b/sal/inc/rtl/stringutils.hxx
index e8909327ac2c..c972d83ba3f5 100644
--- a/sal/inc/rtl/stringutils.hxx
+++ b/sal/inc/rtl/stringutils.hxx
@@ -88,19 +88,22 @@ So char[] and const char[] should always be used with their contents specified (
turns them into char[N] or const char[N]), or char* and const char* should be used.
*/
struct Dummy {};
-template< typename T1, typename T2 >
+template< typename T1, typename T2 = void >
struct CharPtrDetector
{
+ static const bool ok = false;
};
template< typename T >
struct CharPtrDetector< const char*, T >
{
typedef T Type;
+ static const bool ok = true;
};
template< typename T >
struct CharPtrDetector< char*, T >
{
typedef T Type;
+ static const bool ok = true;
};
template< typename T1, typename T2 >
@@ -167,6 +170,24 @@ struct ExceptCharArrayDetector< const char[ N ] >
{
};
+template< typename T1, typename T2 = void >
+struct SalUnicodePtrDetector
+{
+ static const bool ok = false;
+};
+template< typename T >
+struct SalUnicodePtrDetector< const sal_Unicode*, T >
+{
+ typedef T Type;
+ static const bool ok = true;
+};
+template< typename T >
+struct SalUnicodePtrDetector< sal_Unicode*, T >
+{
+ typedef T Type;
+ static const bool ok = true;
+};
+
// SFINAE helper class
template< typename T, bool >
struct Enable
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx
index 1397a182457d..3814a6f5b96c 100644
--- a/sal/inc/rtl/ustrbuf.hxx
+++ b/sal/inc/rtl/ustrbuf.hxx
@@ -557,6 +557,46 @@ public:
}
/**
+ Appends the string representation of the <code>bool</code>
+ argument to the string buffer.
+
+ The argument is converted to a string as if by the method
+ <code>String.valueOf</code>, and the characters of that
+ string are then appended to this string buffer.
+
+ @param b a <code>bool</code>.
+ @return this string buffer.
+
+ @since LibreOffice 4.1
+ */
+ OUStringBuffer & append(bool b)
+ {
+ sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
+ return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
+ }
+#ifdef HAVE_CXX11_DELETE
+#ifndef HAVE_SFINAE_ANONYMOUS_BROKEN
+ // Pointer can be automatically converted to bool, which is unwanted here.
+ // Explicitly delete all pointer append() overloads to prevent this
+ // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
+ template< typename T >
+ typename internal::Enable< void,
+ !internal::CharPtrDetector< T* >::ok && !internal::SalUnicodePtrDetector< T* >::ok >::Type
+ append( T* ) = delete;
+#endif
+#endif
+
+ // This overload is needed because OUString has a ctor from rtl_uString*, but
+ // the bool overload above would be prefered to the conversion.
+ /**
+ @internal
+ */
+ OUStringBuffer & append(rtl_uString* str)
+ {
+ return append( OUString( str ));
+ }
+
+ /**
Appends the string representation of the <code>sal_Bool</code>
argument to the string buffer.