Kaydet (Commit) 5cba714b authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Revert "Generalize OUStringLiteral1"

This reverts commit 4d4f3512, at least "gcc
version 4.8.3 20140627 [gcc-4_8-branch revision 212064] (SUSE Linux)" fails with
"include/rtl/stringutils.hxx:175:49: internal compiler error: Segmentation
fault."
üst 4d4f3512
...@@ -170,14 +170,10 @@ public: ...@@ -170,14 +170,10 @@ public:
template< typename T > template< typename T >
OStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy()) OStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
: pData(NULL) : pData(NULL)
, nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 ) , nCapacity( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 + 16 )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); rtl_string_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 16 );
rtl_string_newFromLiteral(
&pData,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length, 16);
#ifdef RTL_STRING_UNITTEST #ifdef RTL_STRING_UNITTEST
rtl_string_unittest_const_literal = true; rtl_string_unittest_const_literal = true;
#endif #endif
...@@ -457,12 +453,8 @@ public: ...@@ -457,12 +453,8 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type append( T& literal ) typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type append( T& literal )
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
rtl_stringbuffer_insert(
&pData, &nCapacity, getLength(),
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
return *this; return *this;
} }
...@@ -716,12 +708,8 @@ public: ...@@ -716,12 +708,8 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& literal ) typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); rtl_stringbuffer_insert( &pData, &nCapacity, offset, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
rtl_stringbuffer_insert(
&pData, &nCapacity, offset,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
return *this; return *this;
} }
......
...@@ -181,18 +181,12 @@ public: ...@@ -181,18 +181,12 @@ public:
template< typename T > template< typename T >
OString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() ) OString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
pData = 0; pData = 0;
if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) { if( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
rtl_string_new(&pData); rtl_string_new( &pData );
} else { else
rtl_string_newFromLiteral( rtl_string_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
&pData,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
}
#ifdef RTL_STRING_UNITTEST #ifdef RTL_STRING_UNITTEST
rtl_string_unittest_const_literal = true; rtl_string_unittest_const_literal = true;
#endif #endif
...@@ -284,17 +278,11 @@ public: ...@@ -284,17 +278,11 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, OString& >::Type operator=( T& literal ) typename libreoffice_internal::ConstCharArrayDetector< T, OString& >::Type operator=( T& literal )
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); if( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) { rtl_string_new( &pData );
rtl_string_new(&pData); else
} else { rtl_string_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
rtl_string_newFromLiteral(
&pData,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
}
return *this; return *this;
} }
...@@ -555,17 +543,11 @@ public: ...@@ -555,17 +543,11 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); if ( pData->length != libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 )
return return false;
(pData->length return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
== libreoffice_internal::ConstCharArrayDetector<T>::length) literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
&& (rtl_str_compareIgnoreAsciiCase_WithLength(
pData->buffer, pData->length,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0);
} }
/** /**
...@@ -626,16 +608,10 @@ public: ...@@ -626,16 +608,10 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rtl_str_shortenedCompare_WithLength(
return
rtl_str_shortenedCompare_WithLength(
pData->buffer + fromIndex, pData->length - fromIndex, pData->buffer + fromIndex, pData->length - fromIndex,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1) == 0;
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length,
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0;
} }
/** /**
...@@ -705,16 +681,9 @@ public: ...@@ -705,16 +681,9 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
return literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
pData->buffer+fromIndex, pData->length-fromIndex,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length,
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0;
} }
/** /**
...@@ -751,8 +720,7 @@ public: ...@@ -751,8 +720,7 @@ public:
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
bool b = match(literal, 0); bool b = match(literal, 0);
if (b && rest != 0) { if (b && rest != 0) {
*rest = copy( *rest = copy(libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
return b; return b;
} }
...@@ -790,21 +758,14 @@ public: ...@@ -790,21 +758,14 @@ public:
T & literal, OString * rest = 0) const T & literal, OString * rest = 0) const
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= getLength()
bool b && match(literal, getLength() - ( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ));
= (libreoffice_internal::ConstCharArrayDetector<T>::length
<= sal_uInt32(getLength()))
&& match(
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
(getLength()
- libreoffice_internal::ConstCharArrayDetector<T>::length));
if (b && rest != 0) { if (b && rest != 0) {
*rest = copy( *rest = copy(
0, 0,
(getLength() (getLength()
- libreoffice_internal::ConstCharArrayDetector<T>::length)); - (libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)));
} }
return b; return b;
} }
...@@ -873,17 +834,10 @@ public: ...@@ -873,17 +834,10 @@ public:
friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( const OString& rStr, T& literal ) friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( const OString& rStr, T& literal )
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rStr.getLength() == libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1
return && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal,
(rStr.getLength() libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
== libreoffice_internal::ConstCharArrayDetector<T>::length)
&& (rtl_str_compare_WithLength(
rStr.pData->buffer, rStr.pData->length,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0);
} }
/** /**
...@@ -895,17 +849,10 @@ public: ...@@ -895,17 +849,10 @@ public:
friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OString& rStr ) friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OString& rStr )
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rStr.getLength() == libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1
return && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal,
(rStr.getLength() libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
== libreoffice_internal::ConstCharArrayDetector<T>::length)
&& (rtl_str_compare_WithLength(
rStr.pData->buffer, rStr.pData->length,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0);
} }
template< typename T > template< typename T >
...@@ -1047,12 +994,9 @@ public: ...@@ -1047,12 +994,9 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
sal_Int32 n = rtl_str_indexOfStr_WithLength( sal_Int32 n = rtl_str_indexOfStr_WithLength(
pData->buffer + fromIndex, pData->length - fromIndex, pData->buffer + fromIndex, pData->length - fromIndex, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
return n < 0 ? n : n + fromIndex; return n < 0 ? n : n + fromIndex;
} }
......
...@@ -141,19 +141,6 @@ struct ToStringHelper< const char[ N ] > ...@@ -141,19 +141,6 @@ struct ToStringHelper< const char[ N ] >
static const bool allowOUStringConcat = true; static const bool allowOUStringConcat = true;
}; };
#if defined LIBO_INTERNAL_ONLY
template<char C> struct ToStringHelper<OUStringLiteral1_<C>> {
static int length(OUStringLiteral1_<C>) { return 1; }
static char * addData(char * buffer, OUStringLiteral1_<C> literal)
{ return addDataHelper(buffer, &literal.c, 1); }
static sal_Unicode * addData(
sal_Unicode * buffer, OUStringLiteral1_<C> literal)
{ return addDataLiteral(buffer, &literal.c, 1); }
static bool const allowOStringConcat = false;
static bool const allowOUStringConcat = true;
};
#endif
/** /**
@internal @internal
......
...@@ -11,10 +11,6 @@ ...@@ -11,10 +11,6 @@
#define INCLUDED_RTL_STRINGUTILS_HXX #define INCLUDED_RTL_STRINGUTILS_HXX
#include <sal/config.h> #include <sal/config.h>
#include <cstddef>
#include <cstring>
#include <sal/types.h> #include <sal/types.h>
// The unittest uses slightly different code to help check that the proper // The unittest uses slightly different code to help check that the proper
...@@ -33,60 +29,6 @@ namespace rtl ...@@ -33,60 +29,6 @@ namespace rtl
#undef rtl #undef rtl
#endif #endif
#if defined LIBO_INTERNAL_ONLY
/// @cond INTERNAL
/** A simple wrapper around an ASCII character literal.
Can be useful to pass a char constant with ASCII value into a
OUString-related function that is optimized for ASCII string literal
arguments. That is, instead of
char const WILDCARD = '%';
...
if (s[i] == WILDCARD) ...
...
if (s.endsWith(OUString(WILDCARD))) ...
use
char const WILDCARD = '%';
...
if (s[i] == WILDCARD) ...
...
if (s.endsWith(OUStringLiteral1<WILDCARD>())) ...
to avoid creating a temporary OUString instance, and instead pick the
endsWith overload actually designed to take an argument of type
char const[N].
Instances of OUStringLiteral1 need to be const, as those literal-optimized
functions take the literal argument by non-const lvalue reference, for
technical reasons. Except with MSVC, at least up to Visual Studio 2013:
For one, it fails to take that const-ness into account when trying to match
"OUStringLiteral1_<C> const" against T in a "T & literal" parameter of a
function template. But for another, as a language extension, it allows to
bind non-const temporary OUStringLiteral1_ instances to non-const lvalue
references, but also with a warning that thus needs to be disabled.
@since LibreOffice 5.0
*/
template<char C> struct SAL_WARN_UNUSED OUStringLiteral1_ {
static_assert(
static_cast<unsigned char>(C) < 0x80,
"non-ASCII character in OUStringLiteral1");
char const c = C;
};
#if defined _MSC_VER && _MSC_VER <= 1800 // Visual Studio 2013
template<char C> using OUStringLiteral1 = OUStringLiteral1_<C>;
#pragma warning(disable: 4239)
#else
template<char C> using OUStringLiteral1 = OUStringLiteral1_<C> const;
#endif
/// @endcond
#endif
namespace libreoffice_internal namespace libreoffice_internal
{ {
/* /*
...@@ -160,27 +102,13 @@ struct ConstCharArrayDetector ...@@ -160,27 +102,13 @@ struct ConstCharArrayDetector
{ {
static const bool ok = false; static const bool ok = false;
}; };
template< std::size_t N, typename T > template< int N, typename T >
struct ConstCharArrayDetector< const char[ N ], T > struct ConstCharArrayDetector< const char[ N ], T >
{ {
typedef T Type; typedef T Type;
static const std::size_t length = N - 1; static const int size = N;
static const bool ok = true; static const bool ok = true;
static bool isValid(char const (& literal)[N])
{ return std::strlen(literal) == length; }
static char const * toPointer(char const (& literal)[N]) { return literal; }
}; };
#if defined LIBO_INTERNAL_ONLY
template<char C, typename T>
struct ConstCharArrayDetector<OUStringLiteral1<C>, T> {
typedef T Type;
static const std::size_t length = 1;
static const bool ok = true;
static bool isValid(OUStringLiteral1<C>) { return true; }
static char const * toPointer(OUStringLiteral1<C> & literal)
{ return &literal.c; }
};
#endif
// this one is used to rule out only const char[N] // this one is used to rule out only const char[N]
template< typename T > template< typename T >
...@@ -209,10 +137,6 @@ template< int N > ...@@ -209,10 +137,6 @@ template< int N >
struct ExceptCharArrayDetector< const char[ N ] > struct ExceptCharArrayDetector< const char[ N ] >
{ {
}; };
#if defined LIBO_INTERNAL_ONLY && defined _MSC_VER && _MSC_VER <= 1800
// Visual Studio 2013
template<char C> struct ExceptCharArrayDetector<OUStringLiteral1<C>> {};
#endif
template< typename T1, typename T2 = void > template< typename T1, typename T2 = void >
struct SalUnicodePtrDetector struct SalUnicodePtrDetector
......
...@@ -132,14 +132,10 @@ public: ...@@ -132,14 +132,10 @@ public:
template< typename T > template< typename T >
OUStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() ) OUStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
: pData(NULL) : pData(NULL)
, nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 ) , nCapacity( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 + 16 )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 16 );
rtl_uString_newFromLiteral(
&pData,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length, 16);
#ifdef RTL_STRING_UNITTEST #ifdef RTL_STRING_UNITTEST
rtl_string_unittest_const_literal = true; rtl_string_unittest_const_literal = true;
#endif #endif
...@@ -474,12 +470,9 @@ public: ...@@ -474,12 +470,9 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type append( T& literal ) typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type append( T& literal )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), literal,
rtl_uStringbuffer_insert_ascii( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
&pData, &nCapacity, getLength(),
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
return *this; return *this;
} }
...@@ -820,12 +813,9 @@ public: ...@@ -820,12 +813,9 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type insert( sal_Int32 offset, T& literal ) typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, offset, literal,
rtl_uStringbuffer_insert_ascii( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
&pData, &nCapacity, offset,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
return *this; return *this;
} }
...@@ -1209,13 +1199,11 @@ public: ...@@ -1209,13 +1199,11 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
sal_Int32 n = rtl_ustr_indexOfAscii_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, literal,
pData->buffer + fromIndex, pData->length - fromIndex, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), return ret < 0 ? ret : ret + fromIndex;
libreoffice_internal::ConstCharArrayDetector<T>::length);
return n < 0 ? n : n + fromIndex;
} }
/** /**
...@@ -1275,12 +1263,9 @@ public: ...@@ -1275,12 +1263,9 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
return rtl_ustr_lastIndexOfAscii_WithLength( return rtl_ustr_lastIndexOfAscii_WithLength(
pData->buffer, pData->length, pData->buffer, pData->length, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
/** /**
......
...@@ -73,6 +73,17 @@ struct SAL_WARN_UNUSED OUStringLiteral ...@@ -73,6 +73,17 @@ struct SAL_WARN_UNUSED OUStringLiteral
const char* data; const char* data;
}; };
/** A simple wrapper around an ASCII character literal, for use in certain
OUString functions designed for efficient processing of string literals.
@since LibreOffice 5.0
*/
template<char C> struct SAL_WARN_UNUSED OUStringLiteral1 {
static_assert(
static_cast<unsigned char>(C) < 0x80,
"non-ASCII character in OUStringLiteral1");
};
/// @endcond /// @endcond
#endif #endif
...@@ -215,18 +226,12 @@ public: ...@@ -215,18 +226,12 @@ public:
template< typename T > template< typename T >
OUString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() ) OUString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
pData = 0; pData = 0;
if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) { if( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
rtl_uString_new(&pData); rtl_uString_new( &pData );
} else { else
rtl_uString_newFromLiteral( rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
&pData,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
}
#ifdef RTL_STRING_UNITTEST #ifdef RTL_STRING_UNITTEST
rtl_string_unittest_const_literal = true; rtl_string_unittest_const_literal = true;
#endif #endif
...@@ -399,19 +404,27 @@ public: ...@@ -399,19 +404,27 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, OUString& >::Type operator=( T& literal ) typename libreoffice_internal::ConstCharArrayDetector< T, OUString& >::Type operator=( T& literal )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); if( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) { rtl_uString_new( &pData );
rtl_uString_new(&pData); else
} else { rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
rtl_uString_newFromLiteral( return *this;
&pData,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
} }
#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
/// @cond INTERNAL
/** Assign a new string from a single ASCII character literal.
@since LibreOffice 5.0
*/
template<char C> OUString & operator =(OUStringLiteral1<C>) {
sal_Unicode const c = C;
rtl_uString_newFromStr_WithLength(&pData, &c, 1);
return *this; return *this;
} }
/// @endcond
#endif
/** /**
Append a string to this string. Append a string to this string.
...@@ -565,12 +578,9 @@ public: ...@@ -565,12 +578,9 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
return rtl_ustr_asciil_reverseCompare_WithLength( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
pData->buffer, pData->length,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
/** /**
...@@ -648,16 +658,11 @@ public: ...@@ -648,16 +658,11 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); if ( pData->length != libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 )
return return false;
(pData->length
== libreoffice_internal::ConstCharArrayDetector<T>::length) return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, literal ) == 0;
&& (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(
pData->buffer, pData->length,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal))
== 0);
} }
/** /**
...@@ -689,15 +694,9 @@ public: ...@@ -689,15 +694,9 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
return literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
rtl_ustr_ascii_shortenedCompare_WithLength(
pData->buffer+fromIndex, pData->length-fromIndex,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0;
} }
/** /**
...@@ -733,15 +732,9 @@ public: ...@@ -733,15 +732,9 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
return literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(
pData->buffer+fromIndex, pData->length-fromIndex,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0;
} }
/** /**
...@@ -1046,19 +1039,12 @@ public: ...@@ -1046,19 +1039,12 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith( typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
T & literal, OUString * rest = 0) const T & literal, OUString * rest = 0) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
bool b && rtl_ustr_asciil_reverseEquals_WithLength( pData->buffer, literal,
= (libreoffice_internal::ConstCharArrayDetector<T>::length libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
<= sal_uInt32(pData->length))
&& rtl_ustr_asciil_reverseEquals_WithLength(
pData->buffer,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
if (b && rest != 0) { if (b && rest != 0) {
*rest = copy( *rest = copy(libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
return b; return b;
} }
...@@ -1102,19 +1088,14 @@ public: ...@@ -1102,19 +1088,14 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
startsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const startsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); bool b = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
bool b
= (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
pData->buffer, pData->buffer,
libreoffice_internal::ConstCharArrayDetector<T>::length, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, literal,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0); == 0);
if (b && rest != 0) { if (b && rest != 0) {
*rest = copy( *rest = copy(libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
return b; return b;
} }
...@@ -1151,22 +1132,16 @@ public: ...@@ -1151,22 +1132,16 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
endsWith(T & literal, OUString * rest = 0) const endsWith(T & literal, OUString * rest = 0) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
bool b
= (libreoffice_internal::ConstCharArrayDetector<T>::length
<= sal_uInt32(pData->length))
&& rtl_ustr_asciil_reverseEquals_WithLength( && rtl_ustr_asciil_reverseEquals_WithLength(
(pData->buffer + pData->length pData->buffer + pData->length - ( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ), literal,
- libreoffice_internal::ConstCharArrayDetector<T>::length), libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
if (b && rest != 0) { if (b && rest != 0) {
*rest = copy( *rest = copy(
0, 0,
(getLength() (getLength()
- libreoffice_internal::ConstCharArrayDetector<T>::length)); - (libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)));
} }
return b; return b;
} }
...@@ -1230,24 +1205,18 @@ public: ...@@ -1230,24 +1205,18 @@ public:
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
endsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const endsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
bool b
= (libreoffice_internal::ConstCharArrayDetector<T>::length
<= sal_uInt32(pData->length))
&& (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
(pData->buffer + pData->length pData->buffer + pData->length - ( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ),
- libreoffice_internal::ConstCharArrayDetector<T>::length), libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, literal,
libreoffice_internal::ConstCharArrayDetector<T>::length, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0); == 0);
if (b && rest != 0) { if (b && rest != 0) {
*rest = copy( *rest = copy(
0, 0,
(getLength() (getLength()
- libreoffice_internal::ConstCharArrayDetector<T>::length)); - (libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)));
} }
return b; return b;
} }
...@@ -1305,11 +1274,8 @@ public: ...@@ -1305,11 +1274,8 @@ public:
template< typename T > template< typename T >
friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& string, T& literal ) friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& string, T& literal )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
return string.equalsAsciiL(
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
/** /**
* Compare string to an ASCII string literal. * Compare string to an ASCII string literal.
...@@ -1321,11 +1287,8 @@ public: ...@@ -1321,11 +1287,8 @@ public:
template< typename T > template< typename T >
friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& string ) friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& string )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
return string.equalsAsciiL(
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
/** /**
* Compare string to an ASCII string literal. * Compare string to an ASCII string literal.
...@@ -1337,11 +1300,8 @@ public: ...@@ -1337,11 +1300,8 @@ public:
template< typename T > template< typename T >
friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& string, T& literal ) friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& string, T& literal )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return !string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
return !string.equalsAsciiL(
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
/** /**
* Compare string to an ASCII string literal. * Compare string to an ASCII string literal.
...@@ -1353,11 +1313,8 @@ public: ...@@ -1353,11 +1313,8 @@ public:
template< typename T > template< typename T >
friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& string ) friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& string )
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return !string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
return !string.equalsAsciiL(
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
#if defined LIBO_INTERNAL_ONLY #if defined LIBO_INTERNAL_ONLY
...@@ -1535,13 +1492,11 @@ public: ...@@ -1535,13 +1492,11 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
sal_Int32 n = rtl_ustr_indexOfAscii_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, literal,
pData->buffer + fromIndex, pData->length - fromIndex, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), return ret < 0 ? ret : ret + fromIndex;
libreoffice_internal::ConstCharArrayDetector<T>::length);
return n < 0 ? n : n + fromIndex;
} }
/** /**
...@@ -1635,12 +1590,9 @@ public: ...@@ -1635,12 +1590,9 @@ public:
template< typename T > template< typename T >
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const
{ {
assert( assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
return rtl_ustr_lastIndexOfAscii_WithLength( return rtl_ustr_lastIndexOfAscii_WithLength(
pData->buffer, pData->length, pData->buffer, pData->length, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
} }
/** /**
...@@ -1816,14 +1768,11 @@ public: ...@@ -1816,14 +1768,11 @@ public:
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to, SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
sal_Int32 * index = 0) const sal_Int32 * index = 0) const
{ {
assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
rtl_uString * s = 0; rtl_uString * s = 0;
sal_Int32 i = 0; sal_Int32 i = 0;
assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
rtl_uString_newReplaceFirstAsciiL( rtl_uString_newReplaceFirstAsciiL(
&s, pData, &s, pData, from, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, to.pData, index == 0 ? &i : index);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
libreoffice_internal::ConstCharArrayDetector<T>::length, to.pData,
index == 0 ? &i : index);
return OUString(s, SAL_NO_ACQUIRE); return OUString(s, SAL_NO_ACQUIRE);
} }
...@@ -1849,14 +1798,11 @@ public: ...@@ -1849,14 +1798,11 @@ public:
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( OUString const & from, T& to, SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( OUString const & from, T& to,
sal_Int32 * index = 0) const sal_Int32 * index = 0) const
{ {
assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
rtl_uString * s = 0; rtl_uString * s = 0;
sal_Int32 i = 0; sal_Int32 i = 0;
assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
rtl_uString_newReplaceFirstToAsciiL( rtl_uString_newReplaceFirstToAsciiL(
&s, pData, from.pData, &s, pData, from.pData, to, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, index == 0 ? &i : index);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
libreoffice_internal::ConstCharArrayDetector<T>::length,
index == 0 ? &i : index);
return OUString(s, SAL_NO_ACQUIRE); return OUString(s, SAL_NO_ACQUIRE);
} }
...@@ -1882,17 +1828,13 @@ public: ...@@ -1882,17 +1828,13 @@ public:
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
{ {
assert(libreoffice_internal::ConstCharArrayDetector<T1>::isValid(from));
assert(libreoffice_internal::ConstCharArrayDetector<T2>::isValid(to));
rtl_uString * s = 0; rtl_uString * s = 0;
sal_Int32 i = 0; sal_Int32 i = 0;
assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T1 >::size - 1 );
assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T2 >::size - 1 );
rtl_uString_newReplaceFirstAsciiLAsciiL( rtl_uString_newReplaceFirstAsciiLAsciiL(
&s, pData, &s, pData, from, libreoffice_internal::ConstCharArrayDetector< T1, void >::size - 1, to,
libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from), libreoffice_internal::ConstCharArrayDetector< T2, void >::size - 1, index == 0 ? &i : index);
libreoffice_internal::ConstCharArrayDetector<T1>::length,
libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
libreoffice_internal::ConstCharArrayDetector<T2>::length,
index == 0 ? &i : index);
return OUString(s, SAL_NO_ACQUIRE); return OUString(s, SAL_NO_ACQUIRE);
} }
...@@ -1935,12 +1877,9 @@ public: ...@@ -1935,12 +1877,9 @@ public:
template< typename T > template< typename T >
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( T& from, OUString const & to) const SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( T& from, OUString const & to) const
{ {
assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
rtl_uString * s = 0; rtl_uString * s = 0;
rtl_uString_newReplaceAllAsciiL( assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
&s, pData, rtl_uString_newReplaceAllAsciiL(&s, pData, from, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, to.pData);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
libreoffice_internal::ConstCharArrayDetector<T>::length, to.pData);
return OUString(s, SAL_NO_ACQUIRE); return OUString(s, SAL_NO_ACQUIRE);
} }
...@@ -1960,12 +1899,9 @@ public: ...@@ -1960,12 +1899,9 @@ public:
template< typename T > template< typename T >
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( OUString const & from, T& to) const SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( OUString const & from, T& to) const
{ {
assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
rtl_uString * s = 0; rtl_uString * s = 0;
rtl_uString_newReplaceAllToAsciiL( assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
&s, pData, from.pData, rtl_uString_newReplaceAllToAsciiL(&s, pData, from.pData, to, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
libreoffice_internal::ConstCharArrayDetector<T>::length);
return OUString(s, SAL_NO_ACQUIRE); return OUString(s, SAL_NO_ACQUIRE);
} }
...@@ -1986,15 +1922,12 @@ public: ...@@ -1986,15 +1922,12 @@ public:
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
replaceAll( T1& from, T2& to ) const replaceAll( T1& from, T2& to ) const
{ {
assert(libreoffice_internal::ConstCharArrayDetector<T1>::isValid(from));
assert(libreoffice_internal::ConstCharArrayDetector<T2>::isValid(to));
rtl_uString * s = 0; rtl_uString * s = 0;
assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T1 >::size - 1 );
assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T2 >::size - 1 );
rtl_uString_newReplaceAllAsciiLAsciiL( rtl_uString_newReplaceAllAsciiLAsciiL(
&s, pData, &s, pData, from, libreoffice_internal::ConstCharArrayDetector< T1, void >::size - 1,
libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from), to, libreoffice_internal::ConstCharArrayDetector< T2, void >::size - 1);
libreoffice_internal::ConstCharArrayDetector<T1>::length,
libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
libreoffice_internal::ConstCharArrayDetector<T2>::length);
return OUString(s, SAL_NO_ACQUIRE); return OUString(s, SAL_NO_ACQUIRE);
} }
...@@ -2631,6 +2564,26 @@ public: ...@@ -2631,6 +2564,26 @@ public:
#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
/// @cond INTERNAL /// @cond INTERNAL
/** Compare a string and an ASCII character literal for equality.
@since LibreOffice 5.0
*/
template<char C> bool operator ==(OUString const & string, OUStringLiteral1<C>)
{
char const c = C;
return string.equalsAsciiL(&c, 1);
}
/** Compare a string and an ASCII character literal for inequality.
@since LibreOffice 5.0
*/
template<char C> bool operator !=(
OUString const & string, OUStringLiteral1<C> literal)
{
return !(string == literal);
}
/** /**
@internal @internal
*/ */
...@@ -2655,6 +2608,18 @@ struct ToStringHelper< OUStringLiteral > ...@@ -2655,6 +2608,18 @@ struct ToStringHelper< OUStringLiteral >
static const bool allowOUStringConcat = true; static const bool allowOUStringConcat = true;
}; };
/**
@internal
*/
template<char C> struct ToStringHelper<OUStringLiteral1<C>>
{
static int length(OUStringLiteral1<C>) { return 1; }
static sal_Unicode * addData(sal_Unicode * buffer, OUStringLiteral1<C>)
{ *buffer++ = C; return buffer; }
static const bool allowOStringConcat = false;
static const bool allowOUStringConcat = true;
};
/** /**
@internal @internal
*/ */
......
...@@ -192,20 +192,6 @@ void test::oustring::StringLiterals::checkOUStringLiteral() ...@@ -192,20 +192,6 @@ void test::oustring::StringLiterals::checkOUStringLiteral()
void test::oustring::StringLiterals::checkOUStringLiteral1() void test::oustring::StringLiterals::checkOUStringLiteral1()
{ {
auto l1 = rtlunittest::OUStringLiteral1<'A'>();
CPPUNIT_ASSERT_EQUAL('A', l1.c);
char const c2 = 'A';
auto l2 = rtlunittest::OUStringLiteral1<c2>();
CPPUNIT_ASSERT_EQUAL('A', l2.c);
// char c3 = 'A'; auto l3 = rtlunittest::OUStringLiteral1<c3>();
auto l4 = rtlunittest::OUStringLiteral1<sal_Unicode('A')>();
CPPUNIT_ASSERT_EQUAL('A', l4.c);
// auto l5 = rtlunittest::OUStringLiteral1<sal_Unicode(0x100)>();
rtl::OUString s1; rtl::OUString s1;
s1 = rtlunittest::OUStringLiteral1<'A'>(); s1 = rtlunittest::OUStringLiteral1<'A'>();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getLength()); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getLength());
......
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