Files
harbour-core/harbour/source/rtl/right.c
Przemyslaw Czerpak bdb38dde43 2006-12-15 16:55 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbapi.h
  * harbour/include/hbcomp.h
  * harbour/include/hbcompdf.h
  * harbour/include/hbdefs.h
  * harbour/include/hberrors.h
  * harbour/include/hbexpra.c
  * harbour/include/hbexprb.c
  * harbour/include/hbexprc.c
  * harbour/include/hbpcode.h
  * harbour/include/hbxvm.h
  * harbour/source/common/expropt1.c
  * harbour/source/common/expropt2.c
  * harbour/source/common/hbstr.c
  * harbour/source/compiler/cmdcheck.c
  * harbour/source/compiler/genc.c
  * harbour/source/compiler/gencc.c
  * harbour/source/compiler/gencobj.c
  * harbour/source/compiler/harbour.c
  * harbour/source/compiler/harbour.y
  * harbour/source/compiler/harbour.yyc
  * harbour/source/compiler/hbdead.c
  * harbour/source/compiler/hbfix.c
  * harbour/source/compiler/hbgenerr.c
  * harbour/source/compiler/hblbl.c
  * harbour/source/compiler/hbpcode.c
  * harbour/source/compiler/hbstripl.c
  * harbour/source/macro/macro.y
  * harbour/source/macro/macro.yyc
  * harbour/source/rtl/console.c
  * harbour/source/rtl/isprint.c
  * harbour/source/rtl/left.c
  * harbour/source/rtl/right.c
  * harbour/source/rtl/strtran.c
  * harbour/source/vm/codebloc.c
  * harbour/source/vm/hvm.c
  * harbour/source/vm/macro.c
    * general PCODE cleanup and address most of TODO/TOFIX notes in
      source code:
      ! fixed GPF traps when too long string or codeblock is generatd
      + added support for 16MB codeblocks and strings
      ! removed macrocompiler limitation for jumps range
      ! fixed GPF when more then 255 local variables is used and added
        support for 2^15 locals
      ! removed all strtok() functions
      % added optimization for all +=, -=, *=, %=, ^=, **= operations
        when left side of expression is variable or array item
      % added optimization for all +=, -=, *=, %=, ^=, **= operations
        when left side of expression is object method and updated ++, --
        for new code. It's still disabled until we will not add support
        for late evaluated reference items to HVM
      ! fixed a[++i]++ and similar operations (a[++i]*=2, ...). Now ++i is
        executed only once. It's not Clipper compatible but it was in
        TODO note in source code. It can be disabled by -kc option
      * finished support to xHarbour like #pragma TEXTHIDDEN(1)
      ! fixed local add int optimization when PARAMETERS used after
        optimization changed local variable number over 255
      ! fixed GPF trap when in HB_P_<op>EQ PCODEs when executed for
        direct values
      * others
    ! fixed problems reported by Chen
    * optimized strtran(), left(), right() to not create new string copy
      when the same value is returned
2006-12-15 15:54:28 +00:00

80 lines
2.8 KiB
C

/*
* $Id$
*/
/*
* Harbour Project source code:
* RIGHT() function
*
* Copyright 1999 Antonio Linares <alinares@fivetech.com>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#include "hbapi.h"
#include "hbapiitm.h"
#include "hbapierr.h"
/* returns the right-most n characters in string */
HB_FUNC( RIGHT )
{
PHB_ITEM pText = hb_param( 1, HB_IT_STRING );
if( pText && ISNUM( 2 ) )
{
long lLen = hb_parnl( 2 );
if( lLen < 0 )
hb_retc( NULL );
else
{
ULONG ulText = hb_itemGetCLen( pText );
if( ( ULONG ) lLen >= ulText )
hb_itemReturn( pText );
else
hb_retclen( hb_itemGetCPtr( pText ) + ulText - lLen, lLen );
}
}
else
hb_retc( NULL ); /* Clipper doesn't error */
}