You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openoffice.apache.org by bu...@apache.org on 2023/01/17 02:47:58 UTC
[Issue 128533] The BASIC function Str inserts a space before negative numbers
https://bz.apache.org/ooo/show_bug.cgi?id=128533
damjan@apache.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Latest|--- |4.2.0-dev
Confirmation in| |
Hardware|PC |All
CC| |damjan@apache.org
OS|Windows, all |All
--- Comment #1 from damjan@apache.org ---
Our StarBasic implementation is in main/basic. In there, built-in functions
like Str() are declared with the form RTLFUNC(Str), and be found with:
$ grep RTLFUNC\(Str * -R
which gives, among others:
runtime/methods.cxx:RTLFUNC(Str)
where we see what it does:
---snip---
1573 RTLFUNC(Str)
1574 {
1575 (void)pBasic;
1576 (void)bWrite;
1577
1578 if ( rPar.Count() < 2 )
1579 StarBASIC::Error( SbERR_BAD_ARGUMENT );
1580 else
1581 {
1582 String aStr;
1583 SbxVariableRef pArg = rPar.Get( 1 );
1584 pArg->Format( aStr );
1585
1586 // Numbers start with a space
1587 if( pArg->IsNumericRTL() )
1588 {
1589 // Kommas durch Punkte ersetzen, damit es symmetrisch zu
Val ist!
1590 aStr.SearchAndReplace( ',', '.' );
1591
1592 SbiInstance* pInst = pINST;
1593 bool bCompatibility = ( pInst && pInst->IsCompatibility()
);
1594 if( bCompatibility )
1595 {
1596 xub_StrLen nLen = aStr.Len();
1597
1598 const sal_Unicode* pBuf = aStr.GetBuffer();
1599
1600 bool bNeg = ( pBuf[0] == '-' );
1601 sal_uInt16 iZeroSearch = 0;
1602 if( bNeg )
1603 iZeroSearch++;
1604
1605 sal_uInt16 iNext = iZeroSearch + 1;
1606 if( pBuf[iZeroSearch] == '0' && nLen > iNext &&
pBuf[iNext] == '.' )
1607 {
1608 aStr.Erase( iZeroSearch, 1 );
1609 pBuf = aStr.GetBuffer();
1610 }
1611 if( !bNeg )
1612 aStr.Insert( ' ', 0 );
1613 }
1614 else
1615 aStr.Insert( ' ', 0 );
1616 }
1617 rPar.Get(0)->PutString( aStr );
1618 }
1619 }
---snip---
Put a breakpoint on SbRtl_Str (which is what RTLFUNC(Str) mangles the name to),
and debugging, line 1587 is true, and line 1594 is false, so a space is
unconditionally appended in line 1615.
Maybe line 1615 should check for bNeg before adding the space, like lines
1611-1612 do?
As for the relationship between Str() and Format(), note that line 1584 calls
pArg->Format(). The built-in Format() function in RTLFUNC(Format) also calls
the Format() method on its arg. These end up in SbxValue::Format() of
main/basic/source/sbx/sbxscan.cxx, and end up converting the double to a
string. Yet Str() adds the space after calling Format(). So it's not accurate
to say "the Format function works like the Str function".
--
You are receiving this mail because:
You are the assignee for the issue.