dom :: XMLProcessor :: parse_arg
src
# Parses the next argument in `src`
private fun parse_arg(endtags: Array[Char]): XMLAttribute do
var srclen = src.length
ignore_whitespaces
var st_loc = new Location(line, line_offset)
if pos >= srclen then return new BadXMLAttribute(st_loc, "Unfinished attribute name")
# FIXME: Ugly, but as long as it remains private, it is OK I guess
if endtags.has(src[pos]) then return new XMLAttributeEnd(st_loc, "")
var attrname_st = pos
while pos < srclen and src[pos] != '=' and not endtags.has(src[pos]) do pos += 1
if pos >= srclen then return new BadXMLAttribute(st_loc, "Unfinished attribute name")
if src[pos] != '=' then return new BadXMLAttribute(st_loc, "Malformed attribute")
var attrname_end = pos - 1
var name = src.substring(attrname_st, attrname_end - attrname_st + 1).trim
pos += 1
ignore_whitespaces
var attrval_st = pos
if pos >= srclen then return new BadXMLAttribute(st_loc, "Unfinished attribute `{name}`")
var match = src[pos]
if match != '\'' and match != '"' then return new BadXMLAttribute(st_loc, "Invalid string delimiter `{match}` for attribute `{name}`")
pos += 1
while pos < srclen and src[pos] != match do pos += 1
if pos >= srclen then return new BadXMLAttribute(st_loc, "Unfinished attribute `{name}`")
var attrval_end = pos
var val = src.substring(attrval_st, attrval_end - attrval_st + 1).trim
pos += 1
return new XMLStringAttr(st_loc, name, val.substring(1, val.length - 2), match)
end
lib/dom/parser.nit:259,2--286,4