summaryrefslogtreecommitdiff
path: root/sal
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 /sal
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
Diffstat (limited to 'sal')
-rw-r--r--sal/inc/rtl/stringutils.hxx23
-rw-r--r--sal/inc/rtl/ustrbuf.hxx40
2 files changed, 62 insertions, 1 deletions
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.