Page 1 of 1
GetPathPart() GetFilePart()
Posted: Sat Nov 08, 2003 3:09 pm
by dmoc
Would be nice to see these extended to handle URL's as well

And to complete the set... GetDrive(). Initially I thought of a seperate set of commands but essentially it's the same "type" of operation. With the new file systems on the horizon I think it *will* be the same operation 'coz everything in the universe will have a url!
Which reminds me, didn't I see something recently about internet "name spaces"? Basic IIRC all URL's will eventually start with "<NAMESPACE>:...".
@Fred: Adopt my suggestions and get waaaay ahead of the curve

Posted: Sat Nov 08, 2003 3:20 pm
by tinman
I'd also like to see some commands for adding paths and filenames together, that take care of the correct directory separator and look after not adding duplicate directory separators, and things like that.
Posted: Sat Nov 08, 2003 4:17 pm
by dmoc
Until then, v0.01, only tested quickly, ...
Code: Select all
Procedure.s URLHostPart(u.s)
If UCase(Left(u,7))="HTTP://"
ProcedureReturn StringField(u,3,"/")
Else
ProcedureReturn StringField(u,1,"/")
EndIf
EndProcedure
Procedure.s URLResourcePart(u.s)
Protected p.l
If FindString(u,".",1)=0: ProcedureReturn "": EndIf
For p=Len(u) To 1 Step -1
If Mid(u, p, 1)="/"
Break
EndIf
Next
ProcedureReturn Right(u, Len(u)-p)
EndProcedure
Procedure.s URLPathPart(u.s)
Protected r.s, tl.l, tr.l
tl=0: tr=0
If UCase(Left(u,7))="HTTP://": tl=8: EndIf
tl+Len(URLHostPart(u))
tr=Len(URLResourcePart(u))
ProcedureReturn Mid(u, tl, Len(u)-tl-tr)
EndProcedure
Edit: just a small correction in URLHostPart()
Posted: Sat Nov 08, 2003 5:15 pm
by tinman
dmoc wrote:"HTTP://"
URL's don't have to be HTTP AFAIK, that just designates the protocol used to get the resource. Also, you'd maybe want something to extract the username, password and port (or skip them).
Looking forward to v0.02 ;)
Posted: Sat Nov 08, 2003 8:50 pm
by dmoc
Correct, but only http interests me at the mo
Ach, here yer go then, v0.02
PS: These are nothing special, just part of a web-whacker I'm writing, but may save someone from re-creating them.
Code: Select all
Procedure.s URLProtoPart(u.s)
Protected p.l
p = FindString(u,"://",1)
If p
ProcedureReturn Left(u,p-1)
Else
ProcedureReturn ""
EndIf
EndProcedure
Procedure.s URLHostPart(u.s)
If FindString(u,"://",1)
ProcedureReturn StringField(u,3,"/")
Else
ProcedureReturn StringField(u,1,"/")
EndIf
EndProcedure
Procedure.s URLResourcePart(u.s)
Protected r.s, p.l
If FindString(u,".",1)=0: ProcedureReturn "": EndIf
For p=Len(u) To 1 Step -1
If Mid(u, p, 1)="/"
Break
EndIf
Next
ProcedureReturn Right(u, Len(u)-p)
EndProcedure
Procedure.s URLPathPart(u.s)
Protected r.s, tl.l, tr.l
tl=0: tr=0
If UCase(Left(u,7))="HTTP://": tl=8: EndIf
tl+Len(URLHostPart(u))
tr=Len(URLResourcePart(u))
ProcedureReturn Mid(u, tl, Len(u)-tl-tr)
EndProcedure