Question about OUString::compareToAscii

Stephan Bergmann sbergman at redhat.com
Mon Jul 16 01:39:59 PDT 2012


On 07/13/2012 11:37 PM, Christophe JAILLET wrote:
> Le 13/07/2012 23:17, Lubos Lunak a écrit :
>>> according to my understanding,
>>>
>>> OUString::compareToAscii(RTL_CONSTASCII_STRINGPARAM("A string")) gives
>>   compareAsciiL - the L means it gets the string length from the macro
> I was speaking about compareToAscii, without the L. compareAsciiL does
> not seem to exist anyway.
>       sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32
> maxLength ) const SAL_THROW(())
>
> OUString str_1("abc");
>
> str_1.compareToAscii("a")                             --> should give false
> str_1.compareToAscii(RTL_CONSTASCII_STRINGPARAM("a")) --> should give
> true because only the first char of the 2 strings will be compared
>
> In fact I made the same mistake as you. RTL_CONSTASCII_STRINGPARAM made
> me think about the length of the literal but in this case, it also has a
> real effect on the result (unless I'm wrong :))

Indeed, see 
<http://cgit.freedesktop.org/libreoffice/core/commit/?id=4ad006fc76b0f7fdd267c64fc868aaf63e281a31> 
"Confusing behavior of cmopareToAscii overloads."  That's probably the 
reason why Lubos left compareToAscii alone when adding the string 
literal overloads.

Stephan


More information about the LibreOffice mailing list