Re: Path separators...final

new topic     » goto parent     » topic index » view thread      » older message » newer message

Derek Parnell wrote:
> 
> Here is another possibility ...
> 
> }}}
<eucode>
> sequence vPossibleDelims
> vPossibleDelims = ";,`'<>|=+"
> 
> -- Separates a delimited set of paths into a sequence of paths.
> function SplitPaths(sequence pPathList)
>     sequence lPathSet
>     integer lDelim
>     integer lPosn
> 
>     -- Split up the old list into separate paths
>     lPathSet = ""
>     if length(pPathList) > 0 then
>         lDelim = pPathList[1]
>         pPathList = pPathList[2..$]
>         lPosn =  find(lDelim, pPathList)
>         while lPosn != 0 do
>             lPathSet = append(lPathSet, pPathList[1..lPosn-1])
>             pPathList = pPathList[lPosn+1 .. $]
>             lPosn =  find(lDelim, pPathList)
>         end while
>     end if
>     return lPathSet
> end function
> 
> function AddPath(sequence pPathList, sequence pNewPath)
>     sequence lPathSet
>     integer lDelim
>     integer lPosn
> 
>     -- Split up the old list into separate paths
>     lPathSet = SplitPaths(pPathList)
>     lPathSet = append(lPathSet, pNewPath)
> 
>     -- Find new delimiter, one that isn't in any of the paths.
>     for i = 1 to length(vPossibleDelims) do
>         lDelim = vPossibleDelims[i]
>         for j = 1 to length(lPathSet) do
>             lPosn = find(lDelim, lPathSet[j])
>             if lPosn != 0 then
>                 exit
>             end if
>         end for
>         if lPosn = 0 then
>             exit
>         end if
>     end for
> 
>     -- Reconstruct list using new delimiter.
>     -- Format is <delim>(<path><delim>)...
>     -- That is, list always starts and ends with the delimiter,
>     -- and the delimiter is not in any of the paths.
>     pPathList = ""
>     for i = 1 to length(lPathSet) do
>         pPathList &= lDelim
>         pPathList &= lPathSet[i]
>     end for
>     pPathList &= lDelim
> 
>     return pPathList
> end function
> 
> 
> sequence test
> if find("UNITTEST:AddPath", command_line()) then
> test = AddPath("", "c:\\temp\\file.exw")
> test = AddPath(test, "Another file")
> test = AddPath(test, "funny,name")
> test = AddPath(test, "f`u n; y,name")
> 
> 
> printf(1, "%s\n", {test})
> test = SplitPaths(test)
> for i = 1 to length(test) do
>    printf(1, "%s\n", {test[i]})
> end for
> end if
> </eucode>
{{{

> 
> 
> -- 
> Derek Parnell
> Melbourne, Australia
> Skype name: derek.j.parnell

Hi Derek,


Would it be possible for you to describe what you are trying to
achieve here (and how you're trying to achieve it), or should i
just run the code and see how it works?


Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

 From "Black Knight":
"I can live with losing the good fight,
 but i can not live without fighting it".
"Well on second thought, maybe not."

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu