forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Parsing Functions

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 5 Source Code
View previous topic :: View next topic  
Author Message
dmonckton
Contributor
Contributor


Joined: 09 Aug 2002
Posts: 117
Location: Lewes, U.K.

PostPosted: Mon Dec 12, 2005 1:55 pm    Post subject: Parsing Functions Reply with quote

Hi

May recent project called for a lot of work with parsed strings, so I wrote these functions, comments welcome.....

Code:

#define function,parseCount,subParse,parseIns

rem ***********************************************************
rem * FUNCTION:
REM * @parseIns(string1,pos1,string2)
REM *
REM * DATE:
REM * 121205A
REM *
rem * DSCRPTN:
rem * returns a parsed string consisting of string1 with string2
rem * inserted at parse pos1. If pos1 is omitted or zero unmodified
rem * string1 is returned. If pos1 is greater than the length
rem * of string1 then string2 is inserted at the end of string1
rem *
rem * RETURNS:
rem * substring
rem *
rem ***********************************************************
:parseIns
    if @null(%2)@zero(%2)
        exit %1
    end
    if @equal(%2,1)
        exit %3
    end
    if @greater(%2,@parseCount(%1))
        %a = %1|%3
        exit %a
    end
    %a = @subParse(%1,1,@pred(%2))
    %a = %a|%3
    exit %a
rem ***********************************************************


rem ***********************************************************
rem * FUNCTION:
REM * @subParse(string,pos1,pos2)
REM *
REM * DATE:
REM * 211105A
REM *
rem * DSCRPTN:
rem * returns a parsed substring from pos1 to pos2
rem * if pos1 is ommitted or zero unmodified string is returned
rem * if pos2 is zero, omitted or less than pos1, single field
rem * is returned
rem *
rem * RETURNS:
rem * substring
rem *
rem ***********************************************************
:subParse
    if @null(%2)@zero(%2)
        exit %1
    end

    if @equal(%2,1)
        %a =
    else
        %a =
        %i = 0
        %l = @diff(%2,1)
        repeat
            %a = %a;
            %i = @succ(%i)
        until @equal(%i,%l)
    end

    if @null(%3)@zero(%3)
        %l = %2
    else
        %l = %3
    end

    %i = %2
    if @zero(@diff(%l,%i))@greater(%i,%l)
        parse %a"%c",%1
    else
        parse %a"%c",%1
        repeat
            %a = %a;
            parse %a"%b",%1
            %c = %c|%b
            %i = @succ(%i)
        until @equal(%i,%l)
    end
    exit %c
rem ***********************************************************


rem ***********************************************************
rem * FUNCTION:
REM * @parseCount(string)
REM *
REM * DATE:
REM * 211105A
REM *
rem * DSCRPTN:
rem * counts the number of parsed sections in a string
rem * if 1 is returned then string did not contain any
rem * parsed sections or it was empty
rem *
rem * RETURNS:
rem * count
rem *
rem ***********************************************************
:parseCount
    %a = ;
    %c = 1
    repeat
        parse %a"%b",%1
        if @null(%b)
            exit %c
        end
        %c = @succ(%c)
        %a = %a;
    until
    exit
rem ***********************************************************


Thanks

David.M
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 5 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group