connectivity/source/drivers/postgresql/pq_xkeys.cxx: compareToAscii -> operator== sound?

Stephan Bergmann sbergman at redhat.com
Tue Mar 19 09:25:07 PDT 2013


On 03/19/2013 03:13 PM, Stephan Bergmann wrote:
>> commit c69436f7b76237f2b99a29737dc897fb0a86bfd7
>> Author: Marcos Paulo de Souza <marcos.souza.org at gmail.com>
>> Date:   Sat Jan 19 10:08:21 2013 -0200
>>
>>     fdo#57950: Remove some chained appends in connectivity and..
>>
>>     ... remove some RTL* macros.
>>
>>     Change-Id: I919d17e14334c9220b47775355512df8dfa00bca
>>     Reviewed-on: https://gerrit.libreoffice.org/1768
>>     Reviewed-by: Olivier Hallot <olivier.hallot at alta.org.br>
>>     Tested-by: Olivier Hallot <olivier.hallot at alta.org.br>
>>
>> diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.cxx
>> b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
>> index 314924d..2a8d521 100644
>> --- a/connectivity/source/drivers/postgresql/pq_xkeys.cxx
>> +++ b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
>> @@ -127,58 +126,17 @@ static sal_Int32 string2keytype( const
>> rtl::OUString &type )
>>  static sal_Int32 string2keyrule( const rtl::OUString & rule )
>>  {
>>      sal_Int32 ret = com::sun::star::sdbc::KeyRule::NO_ACTION;
>> -    if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "r" ) ) == 0 )
>> +    if( rule == "r" )
>>          ret = com::sun::star::sdbc::KeyRule::RESTRICT;
>> -    else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "c" ) )
>> == 0 )
>> +    else if( rule == "c" )
>>          ret = com::sun::star::sdbc::KeyRule::CASCADE;
>> -    else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "n" ) )
>> == 0 )
>> +    else if( rule == "n" )
>>          ret = com::sun::star::sdbc::KeyRule::SET_NULL;
>> -    else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "d" ) )
>> == 0 )
>> +    else if( rule == "d" )
>>          ret = com::sun::star::sdbc::KeyRule::SET_DEFAULT;
>>      return ret;
>>  }
>
> smells like an incorrect conversion from
> rtl::OUString::compareToAscii(asciiStr,maxLength) to operator== rather
> than rtl::OUString::startsWith, but then again, given the preceeding
>
>> static sal_Int32 string2keytype( const rtl::OUString &type )
>> {
>>     sal_Int32 ret = com::sun::star::sdbcx::KeyType::UNIQUE;
>>     if ( type == "p" )
>>         ret = com::sun::star::sdbcx::KeyType::PRIMARY;
>>     else if ( type == "f" )
>>         ret =  com::sun::star::sdbcx::KeyType::FOREIGN;
>>     return ret;
>> }
>
> I'm not really sure.

...though I just notice that that preceding string2keytype got changed 
from using rtl::OUString::compareToAscii(asciiStr,maxLength) with

> commit c4fc6b22b3af76eb1ae1df8f2e739df46cc3e1a0
> Author: Lionel Elie Mamane <lionel at mamane.lu>
> Date:   Fri Aug 5 12:08:40 2011 +0200
>
>     Janitorial clean-up
>
>      - fix a bunch of compiler warnings
>
>      - move to recommended way of comparing C strings and OUString
>
>      - Copyright statement on files I modified
>
> diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.cxx b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
> index 2b7b540..d84a76c 100644
> --- a/connectivity/source/drivers/postgresql/pq_xkeys.cxx
> +++ b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
> @@ -124,9 +126,9 @@ Keys::~Keys()
>  static sal_Int32 string2keytype( const rtl::OUString &type )
>  {
>      sal_Int32 ret = com::sun::star::sdbcx::KeyType::UNIQUE;
> -    if( type.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "p" ) ) == 0 )
> +    if( type.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("p")) )
>          ret = com::sun::star::sdbcx::KeyType::PRIMARY;
> -    else if( type.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "f" ) ) == 0 )
> +    else if( type.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("f")) )
>          ret =  com::sun::star::sdbcx::KeyType::FOREIGN;
>      return ret;
>  }

Stephan


More information about the LibreOffice mailing list