XubString -> OUString question

Jan Holesovsky kendy at suse.cz
Mon Mar 18 03:28:19 PDT 2013


Hi Jean-Noël,

Jean-Noël Rouvignac píše v Po 18. 03. 2013 v 09:45 +0100:

> The problem you are facing is due to the return type of the method:
> XubString& then OUString& .
> To fix this, you need to return a reference to a non locally created
> OUString.
> I have successfully used a static OUString in the past for these
> cases.
> Can you get access to the variable aEmptyOUStr in sw/inc/swtypes.hxx
> from your piece of code?

OUString is reference counted, so I think in many cases it is just
safe / not hitting performance at all to use the much more readable form
of changing the return type to OUString (from OUString&), and just
return OUString() :-)

Ie. in this case, I'd just change

-const XubString& ToolBox::GetItemText( sal_uInt16 nItemId ) const
-OUString ToolBox::GetItemText( sal_uInt16 nItemId ) const
 {
     ImplToolItem* pItem = ImplGetItem( nItemId );

     if ( pItem )
         return pItem->maText;
-    else
-        return ImplGetSVEmptyStr();
+
+    return OUString();
}

and be done with that ;-)

All the best,
Kendy




More information about the LibreOffice mailing list