add SAL_WARN_UNUSED_RESULT in OString and OUString where appropriate

String used to do some operation by modifying itself
whereas OUString never does that and when a modificaiton is needed
it create a new copy.

so it is very easy when one convert String code to OUString code to
miss stuff like

sString.ToUpperCase()

which need to be converted into

sString = sString.toAsciiUpperCase()

and not
sString.toAsciiUpperCase()

This patch make the compiler generate a warning in that later _wrong_ case

Change-Id: I4a9c0b4c7d0b75ad8850ac23b86e8508a334f5fe
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Norbert Thiebaud 2012-11-28 04:01:17 -06:00 committed by Stephan Bergmann
parent 04c79bcbbc
commit 2048151000
2 changed files with 18 additions and 18 deletions

View file

@ -1056,7 +1056,7 @@ public:
@return a string that represents the concatenation of this string
followed by the string argument.
*/
OString concat( const OString & str ) const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const SAL_THROW(())
{
rtl_String* pNew = 0;
rtl_string_newConcat( &pNew, pData, str.pData );
@ -1081,7 +1081,7 @@ public:
@param newStr the new substring.
@return the new string.
*/
OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const SAL_THROW(())
{
rtl_String* pNew = 0;
rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
@ -1101,7 +1101,7 @@ public:
@return a string derived from this string by replacing every
occurrence of oldChar with newChar.
*/
OString replace( sal_Char oldChar, sal_Char newChar ) const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OString replace( sal_Char oldChar, sal_Char newChar ) const SAL_THROW(())
{
rtl_String* pNew = 0;
rtl_string_newReplace( &pNew, pData, oldChar, newChar );
@ -1126,7 +1126,7 @@ public:
@since LibreOffice 3.6
*/
OString replaceFirst(
SAL_WARN_UNUSED_RESULT OString replaceFirst(
OString const & from, OString const & to, sal_Int32 * index = 0) const
{
rtl_String * s = 0;
@ -1150,7 +1150,7 @@ public:
@since LibreOffice 3.6
*/
OString replaceAll(OString const & from, OString const & to) const {
SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
rtl_String * s = 0;
rtl_string_newReplaceAll(
&s, pData, from.pData->buffer, from.pData->length,
@ -1168,7 +1168,7 @@ public:
@return the string, converted to ASCII lowercase.
*/
OString toAsciiLowerCase() const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OString toAsciiLowerCase() const SAL_THROW(())
{
rtl_String* pNew = 0;
rtl_string_newToAsciiLowerCase( &pNew, pData );
@ -1185,7 +1185,7 @@ public:
@return the string, converted to ASCII uppercase.
*/
OString toAsciiUpperCase() const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OString toAsciiUpperCase() const SAL_THROW(())
{
rtl_String* pNew = 0;
rtl_string_newToAsciiUpperCase( &pNew, pData );
@ -1203,7 +1203,7 @@ public:
@return the string, with white space removed from the front and end.
*/
OString trim() const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OString trim() const SAL_THROW(())
{
rtl_String* pNew = 0;
rtl_string_newTrim( &pNew, pData );

View file

@ -1394,7 +1394,7 @@ public:
@return a string that represents the concatenation of this string
followed by the string argument.
*/
OUString concat( const OUString & str ) const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OUString concat( const OUString & str ) const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newConcat( &pNew, pData, str.pData );
@ -1419,7 +1419,7 @@ public:
@param newStr the new substring.
@return the new string.
*/
OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
@ -1439,7 +1439,7 @@ public:
@return a string derived from this string by replacing every
occurrence of oldChar with newChar.
*/
OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
@ -1464,7 +1464,7 @@ public:
@since LibreOffice 3.6
*/
OUString replaceFirst(
SAL_WARN_UNUSED_RESULT OUString replaceFirst(
OUString const & from, OUString const & to, sal_Int32 * index = 0) const
{
rtl_uString * s = 0;
@ -1493,8 +1493,8 @@ public:
@since LibreOffice 3.6
*/
template< typename T >
typename internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
sal_Int32 * index = 0) const
SAL_WARN_UNUSED_RESULT typename internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
sal_Int32 * index = 0) const
{
rtl_uString * s = 0;
sal_Int32 i = 0;
@ -1522,7 +1522,7 @@ public:
@since LibreOffice 3.6
*/
template< typename T1, typename T2 >
typename internal::ConstCharArrayDetector< T1, typename internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
SAL_WARN_UNUSED_RESULT typename internal::ConstCharArrayDetector< T1, typename internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
{
rtl_uString * s = 0;
@ -1609,7 +1609,7 @@ public:
@return the string, converted to ASCII lowercase.
*/
OUString toAsciiLowerCase() const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OUString toAsciiLowerCase() const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newToAsciiLowerCase( &pNew, pData );
@ -1626,7 +1626,7 @@ public:
@return the string, converted to ASCII uppercase.
*/
OUString toAsciiUpperCase() const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OUString toAsciiUpperCase() const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newToAsciiUpperCase( &pNew, pData );
@ -1644,7 +1644,7 @@ public:
@return the string, with white space removed from the front and end.
*/
OUString trim() const SAL_THROW(())
SAL_WARN_UNUSED_RESULT OUString trim() const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newTrim( &pNew, pData );