This commit is contained in:
Andreas Rumpf 2016-10-20 23:44:55 +02:00
commit 50d593787f
2 changed files with 20 additions and 15 deletions

View file

@ -142,9 +142,9 @@ proc kind*(my: XmlParser): XmlEventKind {.inline.} =
template charData*(my: XmlParser): string = template charData*(my: XmlParser): string =
## returns the character data for the events: ``xmlCharData``, ## returns the character data for the events: ``xmlCharData``,
## ``xmlWhitespace``, ``xmlComment``, ``xmlCData``, ``xmlSpecial`` ## ``xmlWhitespace``, ``xmlComment``, ``xmlCData``, ``xmlSpecial``
## Raises an assertion in debug mode if ``my.kind`` is not one ## Raises an assertion in debug mode if ``my.kind`` is not one
## of those events. In release mode, this will not trigger an error ## of those events. In release mode, this will not trigger an error
## but the value returned will not be valid. ## but the value returned will not be valid.
assert(my.kind in {xmlCharData, xmlWhitespace, xmlComment, xmlCData, assert(my.kind in {xmlCharData, xmlWhitespace, xmlComment, xmlCData,
xmlSpecial}) xmlSpecial})
my.a my.a
@ -152,49 +152,49 @@ template charData*(my: XmlParser): string =
template elementName*(my: XmlParser): string = template elementName*(my: XmlParser): string =
## returns the element name for the events: ``xmlElementStart``, ## returns the element name for the events: ``xmlElementStart``,
## ``xmlElementEnd``, ``xmlElementOpen`` ## ``xmlElementEnd``, ``xmlElementOpen``
## Raises an assertion in debug mode if ``my.kind`` is not one ## Raises an assertion in debug mode if ``my.kind`` is not one
## of those events. In release mode, this will not trigger an error ## of those events. In release mode, this will not trigger an error
## but the value returned will not be valid. ## but the value returned will not be valid.
assert(my.kind in {xmlElementStart, xmlElementEnd, xmlElementOpen}) assert(my.kind in {xmlElementStart, xmlElementEnd, xmlElementOpen})
my.a my.a
template entityName*(my: XmlParser): string = template entityName*(my: XmlParser): string =
## returns the entity name for the event: ``xmlEntity`` ## returns the entity name for the event: ``xmlEntity``
## Raises an assertion in debug mode if ``my.kind`` is not ## Raises an assertion in debug mode if ``my.kind`` is not
## ``xmlEntity``. In release mode, this will not trigger an error ## ``xmlEntity``. In release mode, this will not trigger an error
## but the value returned will not be valid. ## but the value returned will not be valid.
assert(my.kind == xmlEntity) assert(my.kind == xmlEntity)
my.a my.a
template attrKey*(my: XmlParser): string = template attrKey*(my: XmlParser): string =
## returns the attribute key for the event ``xmlAttribute`` ## returns the attribute key for the event ``xmlAttribute``
## Raises an assertion in debug mode if ``my.kind`` is not ## Raises an assertion in debug mode if ``my.kind`` is not
## ``xmlAttribute``. In release mode, this will not trigger an error ## ``xmlAttribute``. In release mode, this will not trigger an error
## but the value returned will not be valid. ## but the value returned will not be valid.
assert(my.kind == xmlAttribute) assert(my.kind == xmlAttribute)
my.a my.a
template attrValue*(my: XmlParser): string = template attrValue*(my: XmlParser): string =
## returns the attribute value for the event ``xmlAttribute`` ## returns the attribute value for the event ``xmlAttribute``
## Raises an assertion in debug mode if ``my.kind`` is not ## Raises an assertion in debug mode if ``my.kind`` is not
## ``xmlAttribute``. In release mode, this will not trigger an error ## ``xmlAttribute``. In release mode, this will not trigger an error
## but the value returned will not be valid. ## but the value returned will not be valid.
assert(my.kind == xmlAttribute) assert(my.kind == xmlAttribute)
my.b my.b
template piName*(my: XmlParser): string = template piName*(my: XmlParser): string =
## returns the processing instruction name for the event ``xmlPI`` ## returns the processing instruction name for the event ``xmlPI``
## Raises an assertion in debug mode if ``my.kind`` is not ## Raises an assertion in debug mode if ``my.kind`` is not
## ``xmlPI``. In release mode, this will not trigger an error ## ``xmlPI``. In release mode, this will not trigger an error
## but the value returned will not be valid. ## but the value returned will not be valid.
assert(my.kind == xmlPI) assert(my.kind == xmlPI)
my.a my.a
template piRest*(my: XmlParser): string = template piRest*(my: XmlParser): string =
## returns the rest of the processing instruction for the event ``xmlPI`` ## returns the rest of the processing instruction for the event ``xmlPI``
## Raises an assertion in debug mode if ``my.kind`` is not ## Raises an assertion in debug mode if ``my.kind`` is not
## ``xmlPI``. In release mode, this will not trigger an error ## ``xmlPI``. In release mode, this will not trigger an error
## but the value returned will not be valid. ## but the value returned will not be valid.
assert(my.kind == xmlPI) assert(my.kind == xmlPI)
my.b my.b
@ -636,12 +636,14 @@ proc rawGetTok(my: var XmlParser) =
proc getTok(my: var XmlParser) = proc getTok(my: var XmlParser) =
while true: while true:
let lastKind = my.kind
rawGetTok(my) rawGetTok(my)
case my.kind case my.kind
of xmlComment: of xmlComment:
if my.options.contains(reportComments): break if my.options.contains(reportComments): break
of xmlWhitespace: of xmlWhitespace:
if my.options.contains(reportWhitespace): break if my.options.contains(reportWhitespace) or lastKind in {xmlCharData, xmlComment, xmlEntity}:
break
else: break else: break
proc next*(my: var XmlParser) = proc next*(my: var XmlParser) =

View file

@ -164,3 +164,6 @@ when isMainModule:
var xml = loadXml(filePath, errors) var xml = loadXml(filePath, errors)
assert(errors.len == 0, "The file tests/testdata/doc1.xml should be parsed without errors.") assert(errors.len == 0, "The file tests/testdata/doc1.xml should be parsed without errors.")
block bug1518:
var err: seq[string] = @[]
assert $parsexml(newStringStream"<tag>One &amp; two</tag>", "temp.xml", err) == "<tag>One &amp; two</tag>"