diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-06-24 15:40:44 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-06-24 15:48:21 +0200 |
commit | 4d4f3512db0cf0bf47c2ba1b39c3813842903ef7 (patch) | |
tree | d684cbc20bcff5071c0de27ec523b81f991e1823 /include/rtl/ustrbuf.hxx | |
parent | 892455e72a57d890918f37bd2b32d6c5000ba6ff (diff) |
Generalize OUStringLiteral1
...by making all places that accept a string literal via ConstCharArrayDetector
also accept an OUStringLiteral1 via ConstCharArrayDetector (which required some
tweaking of the ConstCharArrayDetector internals). That removes the need for
special-purpose OUStringLiteral1 overloads, and will allow OUStringLiteral1 to
be used in more places.
Change-Id: I370de8480e02f8423cde5677dd38479b81bccdb2
Diffstat (limited to 'include/rtl/ustrbuf.hxx')
-rw-r--r-- | include/rtl/ustrbuf.hxx | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx index 04ac8a6c00f4..fe64ebe48280 100644 --- a/include/rtl/ustrbuf.hxx +++ b/include/rtl/ustrbuf.hxx @@ -132,10 +132,14 @@ public: template< typename T > OUStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() ) : pData(NULL) - , nCapacity( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 + 16 ) - { - assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 ); - rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 16 ); + , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 ) + { + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + rtl_uString_newFromLiteral( + &pData, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), + libreoffice_internal::ConstCharArrayDetector<T>::length, 16); #ifdef RTL_STRING_UNITTEST rtl_string_unittest_const_literal = true; #endif @@ -470,9 +474,12 @@ public: template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type append( T& literal ) { - assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 ); - rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), literal, - libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ); + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + rtl_uStringbuffer_insert_ascii( + &pData, &nCapacity, getLength(), + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), + libreoffice_internal::ConstCharArrayDetector<T>::length); return *this; } @@ -813,9 +820,12 @@ public: template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type insert( sal_Int32 offset, T& literal ) { - assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 ); - rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, offset, literal, - libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ); + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + rtl_uStringbuffer_insert_ascii( + &pData, &nCapacity, offset, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), + libreoffice_internal::ConstCharArrayDetector<T>::length); return *this; } @@ -1199,11 +1209,13 @@ public: template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const { - assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 ); - sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength( - pData->buffer + fromIndex, pData->length - fromIndex, literal, - libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1); - return ret < 0 ? ret : ret + fromIndex; + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + sal_Int32 n = rtl_ustr_indexOfAscii_WithLength( + pData->buffer + fromIndex, pData->length - fromIndex, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), + libreoffice_internal::ConstCharArrayDetector<T>::length); + return n < 0 ? n : n + fromIndex; } /** @@ -1263,9 +1275,12 @@ public: template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const { - assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 ); + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rtl_ustr_lastIndexOfAscii_WithLength( - pData->buffer, pData->length, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1); + pData->buffer, pData->length, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), + libreoffice_internal::ConstCharArrayDetector<T>::length); } /** |