View/Edit #52:tag_explode_args

Switch to edit mode.

Name(s): tag_explode_args
1:  "Returns the name, properties and arguments of a tag."
2:  "eg: '<A HREF='/passwd' NOROBOTS TARGET='_new'>'"
3:  "=> {'A', {'HREF','/passwd'}, 'NOROBOTS', {'TARGET','_new'}}"
4:  tag = $su:trim(args[1])
5:  if (length(tag) < 3 || tag[1] != "<" || tag[$] != ">")
6:    raise(E_INVARG, "Invalid HTML tag", tag)
7:  endif
8:  tag = $su:trim(tag[2..$ - 1])
9:  output = {}
10: state = 0
11: prop = value = div = ""
12: for x in [1..length(tag)]
13:   char = tag[x]
14:   if (state == 0)
15:     if (char == "=")
16:       prop || raise(E_INVARG, "Invalid HTML parameter", args[1])
17:       state = 1
18:     elseif (char == " " && prop)
19:       output = {@output, prop}
20:       prop = ""
21:     elseif (char != " ")
22:       prop = prop + char
23:     endif
24:   elseif (state == 1)
25:     if (char == "\"" || char == "'")
26:       div = char
27:     else
28:       div = " "
29:       value = char
30:     endif
31:     state = 2
32:   elseif (state == 2)
33:     if (char == div)
34:       state = 0
35:       output = {@output, {prop, value}}
36:       prop = value = ""
37:     else
38:       value = value + char
39:     endif
40:   endif
41: endfor
42: if (value)
43:   output = {@output, {prop, value}}
44: elseif (prop)
45:   output = {@output, prop}
46: endif
47: if (state)
48:   prop || raise(E_INVARG, "Invalid final HTML parameter", args[1])
49: endif
50: return output
51: "Last modified by Cecil (#7407) on Tue Jul 23 15:17:58 2002 MDT."

Verb arguments: this none this
Verb perms: Readable eXecutable NOT-Debug
Verb owned by: Hacker (#60)

You are not logged in.

[home | help | who | search | setup | code]