[PATCH] replace (Xub)String with OUString in vcl

Christina Roßmanith ChrRossmanith at gmx.de
Wed Feb 6 03:36:33 PST 2013


Hi,

when changing (Xub)String to OUString I came across a strange for-loop. 
You find it at the end of the quotation. I've kept some context... 
(continue below the quotation)
> diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
> index 387acea..e632b4a 100644
> --- a/vcl/source/control/field.cxx
> +++ b/vcl/source/control/field.cxx
> @@ -89,29 +89,29 @@
>   
>   // -----------------------------------------------------------------------
>   
> -static sal_Bool ImplNumericGetValue( const XubString& rStr, double& rValue,
> +static sal_Bool ImplNumericGetValue( const OUString& rStr, double& rValue,
>                                    sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrappper,
>                                    sal_Bool bCurrency = sal_False )
>   {
> -    XubString   aStr = rStr;
> -    XubString   aStr1;
> +    OUString   aStr = rStr;
> +    OUString   aStr1;
>       rtl::OUStringBuffer aStr2;
>       sal_Bool        bNegative = sal_False;
> -    xub_StrLen  nDecPos;
> +    sal_Int32  nDecPos;
>   
>       // react on empty string
> -    if ( !rStr.Len() )
> +    if ( rStr.isEmpty() )
>           return sal_False;
>   
>       // remove leading and trailing spaces
> -    aStr = string::strip(aStr, ' ');
> +    aStr = aStr.trim();
>   
>       // find position of decimal point
> -    nDecPos = aStr.Search( rLocaleDataWrappper.getNumDecimalSep() );
> -    if ( nDecPos != STRING_NOTFOUND )
> +    nDecPos = aStr.indexOf( rLocaleDataWrappper.getNumDecimalSep() );
> +    if ( nDecPos >= 0)
>       {
> -        aStr1 = aStr.Copy( 0, nDecPos );
> -        aStr2.append(aStr.Copy(nDecPos+1));
> +        aStr1 = aStr.copy( 0, nDecPos );
> +        aStr2.append(aStr.getStr()+nDecPos+1);
>       }
>       else
>           aStr1 = aStr;
> @@ -119,32 +119,32 @@
>       // negative?
>       if ( bCurrency )
>       {
> -        if ( (aStr.GetChar( 0 ) == '(') && (aStr.GetChar( aStr.Len()-1 ) == ')') )
> +        if ( aStr.startsWith("(") && aStr.endsWith(")") )
>               bNegative = sal_True;
>           if ( !bNegative )
>           {
> -            for (xub_StrLen i=0; i < aStr.Len(); i++ )
> +            for (sal_Int32 i=0; i < aStr.getLength(); i++ )
>               {
> -                if ( (aStr.GetChar( i ) >= '0') && (aStr.GetChar( i ) <= '9') )
> +                if ( (aStr[i] >= '0') && (aStr[i] <= '9') )
>                       break;
> -                else if ( aStr.GetChar( i ) == '-' )
> +                else if ( aStr[i] == '-' )
>                   {
>                       bNegative = sal_True;
>                       break;
>                   }
>               }
>           }
> -        if ( !bNegative && bCurrency && aStr.Len() )
> +        if ( !bNegative && bCurrency && !aStr.isEmpty() )
>           {
>               sal_uInt16 nFormat = rLocaleDataWrappper.getCurrNegativeFormat();
> -            if ( (nFormat == 3) || (nFormat == 6)  ||
> -                 (nFormat == 7) || (nFormat == 10) )
> +            if ( (nFormat == 3) || (nFormat == 6)  || // $1- || 1-$
> +                 (nFormat == 7) || (nFormat == 10) )  // 1$- || 1 $-
>               {
> -                for (xub_StrLen i = (xub_StrLen)(aStr.Len()-1); i > 0; i++ )
> +                for (sal_Int32 i = aStr.getLength()-1; i > 0; i++ )
>                   {
> -                    if ( (aStr.GetChar( i ) >= '0') && (aStr.GetChar( i ) <= '9') )
> +                    if ( (aStr[i] >= '0') && (aStr[i] <= '9') )
>                           break;
> -                    else if ( aStr.GetChar( i ) == '-' )
> +                    else if ( aStr[i] == '-' )
>                       {
>                           bNegative = sal_True;
>                           break;

In

for (sal_Int32 i = aStr.getLength()-1; i > 0; i++ )

i starts with at least -1 is tested to be non negative and incremented. 
Is this code ever used??? Or am I failing to see the magic behind the 
scenes?

Christina


More information about the LibreOffice mailing list