Re: [PATCH] replace (Xub)String with OUString in vcl
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_BoolbNegative = 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 ___ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice
Re: [PATCH] replace (Xub)String with OUString in vcl
Hi Christina, On Wednesday, 2013-02-06 12:36:33 +0100, Christina Roßmanith wrote: -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? No, that code doesn't make sense and to me looks it should be for (sal_Int32 i = aStr.getLength()-1; i 0; --i) Awkward guessing of negative currency formats anyway.. Thanks for catching! Eike -- LibreOffice Calc developer. Number formatter stricken i18n transpositionizer. New GnuPG key 0x65632D3A : 2265 D7F3 A7B0 95CC 3918 630B 6A6C D5B7 6563 2D3A Old GnuPG key 0x293C05FD : 997A 4C60 CE41 0149 0DB3 9E96 2F1A D073 293C 05FD Support the FSFE, care about Free Software! https://fsfe.org/support/?erack pgpYLBzP_kKhk.pgp Description: PGP signature ___ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice
Re: [PATCH] replace (Xub)String with OUString in vcl
Hi Eike, Am 06.02.2013 13:38, schrieb Eike Rathke: Hi Christina, On Wednesday, 2013-02-06 12:36:33 +0100, Christina Roßmanith wrote: -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? No, that code doesn't make sense and to me looks it should be for (sal_Int32 i = aStr.getLength()-1; i 0; --i) Awkward guessing of negative currency formats anyway.. Do you think it is ever used? It would be an endless loop, wouldn't it?!? The question is modify to --i or remove some code. Well there are lots of formats for negativ currencies: -if ( (nFormat == 3) || (nFormat == 6) || - (nFormat == 7) || (nFormat == 10) ) +if ( (nFormat == 3) || (nFormat == 6) || // $1- || 1-$ + (nFormat == 7) || (nFormat == 10) ) // 1$- || 1 $- I've added them as a comment because the numerical codes for the various formats are quite non intuitive. Christina ___ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice
Re: [PATCH] replace (Xub)String with OUString in vcl
Hi Christina, On Wednesday, 2013-02-06 13:44:09 +0100, Christina Roßmanith wrote: -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? No, that code doesn't make sense and to me looks it should be for (sal_Int32 i = aStr.getLength()-1; i 0; --i) Awkward guessing of negative currency formats anyway.. Do you think it is ever used? It probably is, when a currency amount is entered in such field. It would be an endless loop, wouldn't it?!? Not really endless ;-) in some cases the old code would access invalid memory and probably bail out earlier.. In other cases we were lucky if aStr ended in a digit or '-' The question is modify to --i or remove some code. Changing to --i at least does what the code aimed for, detecting backwards if a character is digit or '-' for these nFormat values: +if ( (nFormat == 3) || (nFormat == 6) || // $1- || 1-$ + (nFormat == 7) || (nFormat == 10) ) // 1$- || 1 $- I've added them as a comment because the numerical codes for the various formats are quite non intuitive. Agreed, it's a legacy from pre-i18n-framework-times and we could have proper named constants instead. Eike -- LibreOffice Calc developer. Number formatter stricken i18n transpositionizer. New GnuPG key 0x65632D3A : 2265 D7F3 A7B0 95CC 3918 630B 6A6C D5B7 6563 2D3A Old GnuPG key 0x293C05FD : 997A 4C60 CE41 0149 0DB3 9E96 2F1A D073 293C 05FD Support the FSFE, care about Free Software! https://fsfe.org/support/?erack pgpNqE8blcAZ4.pgp Description: PGP signature ___ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice