From a777fd85681407e7d841fe89280ef478ac635ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Fri, 5 Sep 2014 13:24:05 +0200 Subject: [PATCH] 2014-09-05 13:24 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/harbour.hbx * src/rtl/val.c + added new function: hb_Val( [, ] ) -> it works like a val but set length for numeric result to passed string length or parameter if is large enough. * src/rtl/tget.prg ! use hb_Val() instead of Val() for numeric GETs to replicate Clipper behavior for pictures longer then 10 characters. --- ChangeLog.txt | 11 +++++++++++ include/harbour.hbx | 1 + src/rtl/tget.prg | 2 +- src/rtl/val.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 31bd329e37..471687a53b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,17 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-09-05 13:24 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * include/harbour.hbx + * src/rtl/val.c + + added new function: hb_Val( [, ] ) -> + it works like a val but set length for numeric result to passed string + length or parameter if is large enough. + + * src/rtl/tget.prg + ! use hb_Val() instead of Val() for numeric GETs to replicate Clipper + behavior for pictures longer then 10 characters. + 2014-09-04 21:17 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rtl/itemseri.c * minor update in comments diff --git a/include/harbour.hbx b/include/harbour.hbx index 4764c73a68..e26228590f 100644 --- a/include/harbour.hbx +++ b/include/harbour.hbx @@ -879,6 +879,7 @@ DYNAMIC hb_utf8Stuff DYNAMIC hb_utf8SubStr DYNAMIC hb_UTF8ToStr DYNAMIC hb_UTF8ToStrBox +DYNAMIC hb_Val DYNAMIC hb_ValToExp DYNAMIC hb_ValToStr DYNAMIC hb_Version diff --git a/src/rtl/tget.prg b/src/rtl/tget.prg index 22dfe322d8..f4a9ce0462 100644 --- a/src/rtl/tget.prg +++ b/src/rtl/tget.prg @@ -1339,7 +1339,7 @@ METHOD unTransform() CLASS Get ENDIF ENDIF - xValue := Val( cBuffer ) + xValue := hb_Val( cBuffer ) EXIT diff --git a/src/rtl/val.c b/src/rtl/val.c index 8c6231065c..9ad10e3305 100644 --- a/src/rtl/val.c +++ b/src/rtl/val.c @@ -73,3 +73,43 @@ HB_FUNC( VAL ) else hb_errRT_BASE_SubstR( EG_ARG, 1098, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } + +HB_FUNC( HB_VAL ) +{ + PHB_ITEM pText = hb_param( 1, HB_IT_STRING ); + + if( pText ) + { + const char * szText = hb_itemGetCPtr( pText ); + int iWidth, iDec, iLen = ( int ) hb_itemGetCLen( pText ); + HB_BOOL fDbl; + HB_MAXINT lValue; + double dValue; + + fDbl = hb_valStrnToNum( szText, iLen, &lValue, &dValue , &iDec, &iWidth ); + + if( HB_ISNUM( 2 ) ) + iLen = ( int ) hb_parni( 2 ); + + if( fDbl && iDec > 0 ) + iLen -= iDec + 1; + + if( iLen > iWidth ) + iWidth = iLen; + else if( iLen > 0 ) + { + while( iWidth > iLen && *szText == ' ' ) + { + iWidth--; + szText++; + } + } + + if( ! fDbl ) + hb_retnintlen( lValue, iWidth ); + else + hb_retndlen( dValue, iWidth, iDec ); + } + else + hb_errRT_BASE_SubstR( EG_ARG, 1098, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +}