Module : html
<module title="Html handling routines"
author="Jurjen Stellingwerff"
revision="20010419"
URL="www.unibase.org">
<sub title="Future developments">
String to html conversion.
Inclusive tabs -> table conversion, point listings, headers, seperator lines
and smily's.
<list heading="Known bugs">
<item name="Cookies as too simple">
The cookies should gain their full functionality like their time to live.
</list>
<routine name="http_encode" use="Write + for spaces and %xx for special characters"
type="string" use="Resulting string"
parameter="str" type="string" use="Source string">
var r as string
var t as string
var pos as number
separate str as p by " "
if p.first then r=p else r+="+"+p endif
next
pos=1
loop
if pos > length(r) then break endif
if isalpha(mid(r, pos, 1)) or mid(r, pos, 1)="+" then
t+=mid(r, pos, 1)
else
if ascii(mid(r, pos, 1))=10 then
t+="%0D"
endif
t+="%"+tohex(ascii(mid(r, pos, 1)))
endif
pos=pos+1
do
return t
</routine>
<routine name="http_decode" use="Get spaces from + and special characters from %xx tokens"
type="string" use="Resulting string"
parameter="str" type="string" use="Source string">
var r as string
var t as string
separate str as p by "+"
if p.first then r=p else r+=" "+p endif
next
separate r as q by "%"
if q.first then t=q else
if left(q, 2)<>"0D" then
t+=char(fromhex(left(q, 2)))+mid(q, 3, 99999)
endif
endif
next
return t
</routine>
<routine name="cookie" use="Encode a cookie"
type="string" use="The text that describes cookie"
parameter="name" type="constr" use="The name of the cookie"
parameter="value" type="constr" use="The data of the cookie"
parameter="duration" type="[Browser Day Minute Week Quaterhour Hour]" use="Time to live">
return "Set-Cookie: "+http_encode(name)+"="+http_encode(value)+"; path=/"
</routine>
<routine name="tag" use="Create one XML tag"
type="string"
parameter="str" type="constr">
return "<"+str+">"
</routine>
<routine name="html" use="Create html code from a text. By now only returns are replaced"
type="string"
parameter="str" type="constr">
var r as string
separate str as a by char(10)
if a.first then
r=r+a
else
r=r+tag("br")
endif
next
return r
</routine>
<routine name="notag" use="Recreate a string as closely as possible"
type="string"
parameter="str" type="constr">
var r as string
var cr as string
var r2 as string
var r3 as string
var lpos as number
var rpos as number
separate str as a by "<"
if a.first then
r=r+a
else
r=r+"<"+a
endif
next
separate r as b by " "
if b.first then
r2=r2+b
else
r2=r2+" "+b
endif
next
cr=char(10)
separate r2 as b2 by cr
if b2.first then
r3=r3+b2
else
r3=r3+tag("br")+cr+b2
endif
next
lpos=findstring(r3, "#", 1)
loop
if lpos<1 then break endif
rpos=findstring(r3, "#", lpos+1)
if rpos<1 or findstring(mid(r3, lpos+1, rpos-lpos-1), " ", 1)>0 then break endif
r3=left(r3, lpos-1)+tag("i")+mid(r3, lpos+1, rpos-lpos-1)+tag("/i")+mid(r3, rpos+1)
lpos=findstring(r3, "#", 1)
do
return r3
</routine>
Copyright (C) 2001 Jurjen J. Stellingwerff