1. DLLs, a better split()
- Posted by Buddy Hyllberg <budmeister1 at JUNO.COM>
Sep 19, 1998
-
Last edited Sep 20, 1998
Hi everybody,
Does anybody know of a Windows utility that can show you the routines in
a dll? Is it possible to do such a thing? I thought I heard mention of
one a while back...
Also, I'm writing a simple split function; does anyone have a better way?
-- a simple split
function split( atom a, sequence b )
sequence x, buf buf = {} x = {}
for i = 1 to length( b ) do
if compare( a, b[i] ) != 0 then
buf = buf & b[i]
else
x = append( x, buf )
buf = {}
end if
end for
return x
end function
_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]
2. Re: DLLs, a better split()
Buddy Hyllberg wrote:
>Also, I'm writing a simple split function; does anyone have a better way?
>
>-- a simple split
>function split( atom a, sequence b )
> sequence x, buf buf = {} x = {}
> for i = 1 to length( b ) do
> if compare( a, b[i] ) != 0 then
> buf = buf & b[i]
> else
> x = append( x, buf )
> buf = {}
> end if
> end for
> return x
>end function
Yes, Buddy, I have a couple of routines in my toolbox that are both
better and faster than yours:
function split(integer c, sequence s)
-- split string s using c as delimiter
sequence os
integer i
os={}
i=find(c,s)
while i do
if i>1 then os=append(os,s[1..i-1]) end if
s=s[i+1..length(s)]
i=find(c,s)
end while
if length(s) then return append(os,s) end if
return os
end function
function words(sequence c, sequence s)
-- split string s using *every* element of c as delimiter
sequence os
integer i,j,inword
os={}
inword=0
j=1
while j<=length(s) do
if inword then
if find(s[j],c) then
os=append(os,s[i..j-1])
inword=0
end if
elsif not find(s[j],c) then
i=j
inword=1
end if
j=j+1
end while
if inword then os=append(os,s[i..j-1]) end if
return os
end function
The problem with your function is that leading as well as trailing
occurrences of the delimiter show up as empty strings each, and so do
multiple occurrences of it inside the string.
Now, I cannot even remember whether I wrote the above functions
myself, or just stole them from someone else (but I usually make a
note of all stolen bits) - would the rightful owner put up his/her
hand?! jiri
ps I leave the Windows (dll) query to the masochists on the list.
3. Re: DLLs, a better split()
- Posted by Hawke <mdeland at NWINFO.NET>
Sep 19, 1998
-
Last edited Sep 20, 1998
Buddy Hyllberg wrote:
> Also, I'm writing a simple split function; does anyone have a better way?
try this:
-----------begin split.ex
--the safe, tested, verbose, and error checking version
function split1(atom lookfor, sequence data)
--makes the sequence data into 2 sequences, at the point
--lookfor. the resulting pair of sequences are such that
--the first part is up to and including the split point
--lookfor, and the last half of the result begins just
--after the lookfor point and continues to the end of data.
integer where,len
len = length(data)
if len < 2 then
puts(1,"Error in function split: data=invalid sequence.\n")
return data
end if
where = find(lookfor, data)
if not where then
puts(1,"Error in function split: lookfor not found.\n")
return data
end if
--need this, where+1 might be past end of data
if where=len then
return {data,{}}
else return {data[1..where],data[where+1..len]}
end if
end function
--the stripped, no error check, fast, code only version
function split2(atom lookfor, sequence data)
integer where
where = find(lookfor, data)
return {data[1..where],data[where+1..length(data)]}
end function
--main
sequence mary
mary="mary had a little lamb; whose fleece was white as snow."
puts(1,mary & "\n" )
mary=split1(';',mary)
puts(1,mary[1] & "\n" & mary[2] & "\n" )
-------------------end split.ex
i put split2 in there so you could see the actual algorithm...
it could actually be made into 1 line, but it would be slower
since you would have to call find() twice.
hope this helps...
--Hawke'
4. Re: DLLs, a better split()
- Posted by Hawke <mdeland at NWINFO.NET>
Sep 19, 1998
-
Last edited Sep 20, 1998
Hawke wrote:
> i put split2 in there so you could see the actual algorithm...
> it could actually be made into 1 line, but it would be slower
> since you would have to call find() twice.
> hope this helps...
> --Hawke'
errrr.... a line i intended in this close somehow became vaporware.
One other thing about my split.ex is that it's more
tuned to strings (1 dimension sequences) as that is what
your code seemed to me was doing...
I didn't read your code, however, with a very fine-toothed comb.
If that is not what you needed for your split, then jiri's
reply would be more appropriate. If you need simple
string splitting, I think mine might run faster... not sure.
5. Re: DLLs, a better split()
I posted my split and split_match () some time ago, I dunno about speed, but
they are much more simpeler than the ones offered here. And they dont assume
your sequence is a string. You can have any kind of delimiter (object,
sequence) wich is then compared against either every element of the search
sequence (split) or as a whole sequence (split_match).
Here is my split.e again:
-- Split & Split_Match by Ralf Nieuwenhuijsen (nieuwen at xs4all.nl)
-- Use NiceForm /d splits.e to get some documentation
function split (object x, sequence s)
--/ Usage: s = split (delimiter, sequence)
--/ The sequence (second arg) will be divided in pieces by the delimiter
--/ The delimiter object is compared agains every element of the sequence
--/ All pieces are returned in one sequence
sequence ret
integer pos, prev
ret = {}
prev = 1
pos = find (x,s)
while pos do
ret = append(ret, s[prev..pos])
prev = pos + 1
pos = find(x, s[prev..length(s)])
end while
return append(ret, s[prev..length(s)])
end function
function split_match (object x, sequence s)
--/ Usage: s = split_match (delimiter, sequence)
--/ The sequence (second arg) will be divided in pieces by the delimiter
--/ The delimiter object is matched against any section of the sequence
--/ All pieces are returned in one sequence
sequence ret
integer pos, prev
ret = {}
prev = 1
if atom(x) then x = {x} end if
pos = match (x,s)
while pos do
ret = append(ret, s[prev..pos])
prev = pos + length(x)
pos = match(x, s[prev..length(s)])
end while
return append(ret, s[prev..length(s)])
end function
>The problem with your function is that leading as well as trailing
>occurrences of the delimiter show up as empty strings each, and so do
>multiple occurrences of it inside the string.
Yes, when two delimiters follow each other up, an empty sequence is added,
but thats the most consitent and wanted behaviour. Because, there is missing
something. If we do \n\n we dont want ex.exe to think that we only jump down
one line do we ?
>Now, I cannot even remember whether I wrote the above functions
>myself, or just stole them from someone else (but I usually make a
>note of all stolen bits) - would the rightful owner put up his/her
>hand?! jiri
There most definately not mine. Any one wish to start bench marking on this
?
Ralf
6. Re: DLLs, a better split()
Commenting on a posted split() function I originally wrote:
>>The problem with your function is that leading as well as trailing
>>occurrences of the delimiter show up as empty strings each, and so do
>>multiple occurrences of it inside the string.
Ralf responded:
>Yes, when two delimiters follow each other up, an empty sequence is added,
>but thats the most consitent and wanted behaviour. Because, there is
missing
>something. If we do \n\n we dont want ex.exe to think that we only jump
down
>one line do we ?
There is definitely something missing in there ok, how about a bit of
common sense and some logic? So three spaces will convert to two extra
empty strings (or is it two extra one line jumps?), and the most
common DOS line delimiter (cr lf) will force double spacing... Thanks,
but most definitely not in mine! jiri
7. Re: DLLs, a better split()
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL>
Sep 20, 1998
-
Last edited Sep 21, 1998
Jiri wrote:
>>Yes, when two delimiters follow each other up, an empty sequence is added,
>>but thats the most consitent and wanted behaviour. Because, there is
>missing
>>something. If we do \n\n we dont want ex.exe to think that we only jump
>down
>>one line do we ?
>
>There is definitely something missing in there ok, how about a bit of
>common sense and some logic? So three spaces will convert to two extra
>empty strings (or is it two extra one line jumps?), and the most
>common DOS line delimiter (cr lf) will force double spacing... Thanks,
>but most definitely not in mine! jiri
The most common line delimiter works fine using my split_match ()
And to your first question, if space (32) is the delimiter, yes.
Jiri, that are many cases, your function works fine, and nice, and it the
removal of empty sequences is the wanted behaviour. But there are also many
cases when this is not the wanted behaviour.
With my function the choice is left to the user. But to make it even easier
for those cases..
function clean (sequence s)
sequence ret
object item
for index = 1 to length(s) do
item = s[index]
if compare (item, {}) then
ret = append(ret, item)
end if
end for
return ret
end function
So now you can do things like this to get the jiri-type-of-result:
? clean(split (32, "The number of spaces in between dont matter
!"))
The use of clean has the advantage you know that a number of delimiters are
discarded.
However, to split up lines:
? split ( 32, "The number of \n lines used \n\n in this thingie \n are
five !")
And you can be certain the number of delimiters are one less than the number
of elements in the sequence returned.
Jiri happy again ?
Ralf