examples: Trim .nim files trailing whitespace
via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
This commit is contained in:
parent
e80465dacf
commit
5d80548cce
15 changed files with 141 additions and 141 deletions
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
import os, streams, parsexml, strutils
|
||||
|
||||
proc `=?=` (a, b: string): bool =
|
||||
proc `=?=` (a, b: string): bool =
|
||||
# little trick: define our own comparator that ignores case
|
||||
return cmpIgnoreCase(a, b) == 0
|
||||
|
||||
if paramCount() < 1:
|
||||
if paramCount() < 1:
|
||||
quit("Usage: htmlrefs filename[.html]")
|
||||
|
||||
var links = 0 # count the number of links
|
||||
|
|
@ -21,17 +21,17 @@ next(x) # get first event
|
|||
block mainLoop:
|
||||
while true:
|
||||
case x.kind
|
||||
of xmlElementOpen:
|
||||
of xmlElementOpen:
|
||||
# the <a href = "xyz"> tag we are interested in always has an attribute,
|
||||
# thus we search for ``xmlElementOpen`` and not for ``xmlElementStart``
|
||||
if x.elementName =?= "a":
|
||||
if x.elementName =?= "a":
|
||||
x.next()
|
||||
if x.kind == xmlAttribute:
|
||||
if x.kind == xmlAttribute:
|
||||
if x.attrKey =?= "href":
|
||||
var link = x.attrValue
|
||||
inc(links)
|
||||
# skip until we have an ``xmlElementClose`` event
|
||||
while true:
|
||||
while true:
|
||||
x.next()
|
||||
case x.kind
|
||||
of xmlEof: break mainLoop
|
||||
|
|
@ -40,14 +40,14 @@ block mainLoop:
|
|||
x.next() # skip ``xmlElementClose``
|
||||
# now we have the description for the ``a`` element
|
||||
var desc = ""
|
||||
while x.kind == xmlCharData:
|
||||
while x.kind == xmlCharData:
|
||||
desc.add(x.charData)
|
||||
x.next()
|
||||
echo(desc & ": " & link)
|
||||
else:
|
||||
x.next()
|
||||
x.next()
|
||||
of xmlEof: break # end of file reached
|
||||
of xmlError:
|
||||
of xmlError:
|
||||
echo(errorMsg(x))
|
||||
x.next()
|
||||
else: x.next() # skip other events
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue