Files
harbour-core/harbour/contrib/hbnf/aading.prg
Viktor Szakats 53bf2585ca 2011-05-11 18:04 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbnf/scancode.prg
  * contrib/hbnf/vidmode.prg
  * contrib/hbnf/miltime.prg
  * contrib/hbnf/savearr.prg
  * contrib/hbnf/dispmsg.prg
  * contrib/hbnf/mouse1.prg
  * contrib/hbnf/settime.prg
  * contrib/hbnf/page.prg
  * contrib/hbnf/pegs.prg
  * contrib/hbnf/min2dhm.prg
  * contrib/hbnf/dosver.prg
  * contrib/hbnf/metaph.prg
  * contrib/hbnf/woy.prg
  * contrib/hbnf/setdate.prg
  * contrib/hbnf/linked.prg
  * contrib/hbnf/aredit.prg
  * contrib/hbnf/xbox.prg
  * contrib/hbnf/ftround.prg
  * contrib/hbnf/dectobin.prg
  * contrib/hbnf/aemaxlen.prg
  * contrib/hbnf/nwlstat.prg
  * contrib/hbnf/tempfile.prg
  * contrib/hbnf/scregion.prg
  * contrib/hbnf/mouse2.prg
  * contrib/hbnf/pickday.prg
  * contrib/hbnf/datecnfg.prg
  * contrib/hbnf/easter.prg
  * contrib/hbnf/aeminlen.prg
  * contrib/hbnf/pchr.prg
  * contrib/hbnf/tbwhile.prg
  * contrib/hbnf/calendar.prg
  * contrib/hbnf/elapsed.prg
  * contrib/hbnf/aading.prg
  * examples/hbvpdf/hbvpdf.prg
  * examples/hbvpdf/hbvpdft.prg
  * examples/gtwvw/tests/prog1.prg
  * examples/gtwvw/tests/prog2.prg
  * examples/gtwvw/tests/wvwtest9.prg
  * examples/gtwvw/tests/ebtest7.prg
  * examples/gtwvw/tests/prog0.prg
    ! eliminated most (if not all) ' = ' operators
      some minor compatibility notes added to NF
      (NF being buggy by behaving inconsistently 
      due to _SET_EXACT setting)
2011-05-11 16:05:43 +00:00

115 lines
2.7 KiB
Plaintext

/*
* $Id$
*/
/*
* File......: aadding.prg
* Author....: Ralph Oliver, TRANSCOM SYSTEMS
* CIS ID....: 74030,703
*
* This is an original work by Ralph Oliver and is placed in the
* public domain.
*
* Modification history:
* ---------------------
*
* Rev 1.1 15 Aug 1991 23:05:40 GLENN
* Forest Belt proofread/edited/cleaned up doc
*
* Rev 1.0 07 Jun 1991 23:03:08 GLENN
* Initial revision.
*
*
*/
#ifdef FT_TEST
FUNCTION MAIN()
LOCAL aList1,aList2,var0,nstart,nstop,nelapsed,nCtr
CLS
? "TEST TO DEMONSTRATE EXAMPLES OF FT_AADDITION"
?
aList1 := {"apple", "orange", "pear"}
aList2 := {"apple ", "banana", "PEAR"}
? "aList1 : "
AEVAL( aList1, { |x| QQOUT(x + ",") } )
?
? "aList2 : "
AEVAL( aList2, { |x| QQOUT(x + ",") } )
?
nstart := SECONDS()
FOR nCtr := 1 to 100
var0 := FT_AADDITION( aList1, aList2 )
NEXT
nstop := SECONDS()
nelapsed := nstop - nstart
? "time for 100 merges:", nelapsed
? PADR("FT_AADDITION( aList1, aList2 ) ->",44)
AEVAL( var0, { |x| QQOUT(x + ",") } )
?
var0 := FT_AADDITION( aList1, aList2, , .F. )
? PADR("FT_AADDITION( aList1, aList2, , .F. ) ->",44)
AEVAL( var0, { |x| QQOUT(x + ",") } )
?
var0 := FT_AADDITION( aList1, aList2, .F., .F. )
? PADR("FT_AADDITION( aList1, aList2, .F., .F. ) ->",44)
AEVAL( var0, { |x| QQOUT(x + ",") } )
?
RETURN NIL
#endif
FUNCTION FT_AADDITION( aList1, aList2, lTrimmer, lCaseSens )
LOCAL nElement, nPos, bScanCode
LOCAL aNewArray := ACLONE( aList1 )
// Set default parameters as necessary.
IF lCaseSens == NIL
lCaseSens := .T.
ENDIF
IF lTrimmer == NIL
lTrimmer := .T.
ENDIF
// Assign code blocks according to case sensitivity and trim.
IF lCaseSens
IF lTrimmer // Ignore spaces.
bScanCode := { |x| ;
ALLTRIM( x ) == ;
ALLTRIM( aList2[ nElement ]) }
ELSE
bScanCode := { |x| x == ( aList2[ nElement ]) }
ENDIF
ELSE // Ignore case.
IF lTrimmer // Ignore spaces.
bScanCode := { |x| ;
UPPER( ALLTRIM( x )) == ;
UPPER( ALLTRIM( aList2[ nElement ] )) }
ELSE
bScanCode := { |x| ;
UPPER( x ) == ;
UPPER( aList2[ nElement ] ) }
ENDIF
ENDIF
// Add the unique elements of aList2 to aList1.
FOR nElement := 1 TO LEN( aList2 )
nPos := ASCAN( aList1, bScanCode )
// If unique, then add element to new array.
IF nPos == 0
AADD( aNewArray, aList2[ nElement ] )
ENDIF
NEXT
RETURN aNewArray