[futurebasic] Re: [FB] Would an assemply line routine be faster than FN MUNGER()?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 1999 : Group Archive : Group : All Groups

From: "Michael Evans" <mikonic@...>
Date: Thu, 01 Jul 1999 13:16:25 -0400
> michael said:
>>   Would an assemply line routine be faster than FN MUNGER()?
>
> trying to make munger work
> has wasted weeks of my time.
>
> so i hope you include that time
> in any "speed" tests you conduct...         ;+)
>
> i finally patched something together,
> but it seems i have to re-work it
> massively for every new app.
>
> if someone has something that is
> simple, stable, and universal,
> i for one would appreciate it immensely...
>
> -bowerbird
>
> --
> To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>
>

How about this?


'WARNING NOT TESTED....
'WARNING NOT TESTED....
'WARNING NOT TESTED....
CLEAR LOCAL
LOCAL FN mySearchReplace(handleToSearch&,textToFind$,replaceText$)
  DIM searchSize%, replaceSize%, currOffset&, oldOffset&

  searchSize%    = LEN(textToFind$)               ' length of textToFind$
  replaceSize%   = LEN(replaceText$)              ' length of textToFind$ [=
0 deletes textToFind$ found]
  currOffset&    = 0                              ' start search at
beginning
  oldOffset&     = 0                              ' last replace offset
  replaceCount&  = 0                              ' count of replacements
accomplished

  DO
    currOffset& = FN
MUNGER(handleToSearch&,currOffset&,@textToFind$+1,searchSize%,@replaceText$+
1,replaceSize%)
    LONG IF currOffset& > oldOffset&
      INC(replaceCount&)
      oldOffset& = currOffset&
    END IF
  UNTIL currOffset& <= 0
  ' currOffset& will = -1 when done....
END FN = replaceCount&


CLEAR LOCAL
LOCAL FN DispatchSearchReplace$(strToSearch$,TxtFind$,TxtReplace$)
  DIM replacements&, mySTRhandle&, STRhandleSize%, STRhandleSize&, err%
  DIM replaceStr$

  STRhandleSize% = LEN(strToSearch$)
  LONG IF STRhandleSize% > 0
    STRhandleSize& = STRhandleSize%
    mySTRhandle& = FN NEWHANDLE(STRhandleSize&)
    LONG IF mySTRhandle&

      err%   = FN HLOCK(mySTRhandle&)
      BLOCKMOVE @strToSearch$ + 1, [mySTRhandle&], STRhandleSize&
      err%   = FN HUNLOCK(mySTRhandle&)
      replacements& = FN mySearchReplace(mySTRhandle&,TxtFind$,TxtReplace$)

      LONG IF replacements& > 0                   ' replacement or deletion
occurred....

        STRhandleSize& = FN GETHANDLESIZE(mySTRhandle&)'size changed by
munging
        LONG IF STRhandleSize& > 255              'string length max
          STRhandleSize& = 255
        END IF

        LONG IF STRhandleSize& > 0
          STRhandleSize% = STRhandleSize&
          POKE @replaceStr$, STRhandleSize%
          err%   = FN HLOCK(mySTRhandle&)
          BLOCKMOVE @replaceStr$ + 1, [mySTRhandle&], STRhandleSize&
          err%   = FN HUNLOCK(mySTRhandle&)
        END IF

      END IF                                      ' IF replacements& > 0

      DEF DISPOSEH(mySTRhandle&)
    END IF                                        ' IF mySTRhandle&

  END IF                                          ' IF STRhandleSize% > 0

END FN = replaceStr$


'Call as in
'result$ = FN
DispatchSearchReplace$(oldStr$,findTheseChars$,ReplaceWithTheseChars$)
' if ReplaceWithTheseChars$ = "" then all instances of findTheseChars$ are
deleted....
'WARNING NOT TESTED....

Cheers,

----------------------------------------------------------
Michael Evans
Manager of Software Development * Photo Systems, Inc.
3301 Wood Valley Road, NW * Atlanta, GA, 30327-1515
Voice: (404) 846-9386
Fax: (404) 240-0878 * Cell: (404) 229-3930
E-mail: evans@... * michael_evans@...
----------------------------------------------------------