1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
string *quote_from;
string *quote_to;
string *unquote_from;
string *unquote_to;
void create()
{
quote_from=quote_to=unquote_from=unquote_to=({});
for(int e=0;e<256;e++)
{
switch(e)
{
case 'a'..'z':
case 'A'..'Z':
case '0'..'9':
case '': case '': case '':
case '': case '': case '':
case '': case '':
case '!':
case '#':
case '$':
case '&':
case '/':
case '(':
case ')':
case '=':
case '-':
case '_':
case '+':
case '?':
case '~':
case '*':
case ',':
case '.':
case ';':
case ':':
break;
default:
quote_from+=({sprintf("%c",e)});
quote_to+=({sprintf("%%%02x",e)});
}
unquote_from+=({sprintf("%%%02x",e)});
unquote_to+=({sprintf("%c",e)});
}
}
string quote_param(string s) { return replace(s,quote_from,quote_to); }
string unquote_param(string s) { return replace(s,unquote_from,unquote_to); }
string mktag(string tag, mapping params)
{
string ret="<"+tag;
foreach(indices(params),string i)
{
ret+=" "+i;
if(stringp(params[i]))
{
switch(i)
{
case "href":
case "name":
ret+="='"+quote_param(params[i])+"'";
break;
default:
if(search(params[i],"\"")==-1)
ret+="=\""+params[i]+"\"";
else if(search(params[i],"'")==-1)
ret+="='"+params[i]+"'";
else
ret+="=\""+replace(params[i],"\"","'")+"\"";
}
}
}
return ret+">";
}
|