Make countLines() the same as len(splitLines(s)) (#5470)
The result of countLines() is now increased by 1 compared to the old version. Fixes #5460.
This commit is contained in:
parent
f7af16a1c9
commit
a42801d100
3 changed files with 6 additions and 10 deletions
|
|
@ -870,7 +870,7 @@ proc buildLinesHTMLTable(d: PDoc; params: CodeBlockParams, code: string):
|
||||||
d.config.getOrDefault"doc.listing_end" % id)
|
d.config.getOrDefault"doc.listing_end" % id)
|
||||||
return
|
return
|
||||||
|
|
||||||
var codeLines = 1 + code.strip.countLines
|
var codeLines = code.strip.countLines
|
||||||
assert codeLines > 0
|
assert codeLines > 0
|
||||||
result.beginTable = """<table class="line-nums-table"><tbody><tr><td class="blob-line-nums"><pre class="line-nums">"""
|
result.beginTable = """<table class="line-nums-table"><tbody><tr><td class="blob-line-nums"><pre class="line-nums">"""
|
||||||
var line = params.startLine
|
var line = params.startLine
|
||||||
|
|
|
||||||
|
|
@ -767,20 +767,16 @@ proc splitLines*(s: string): seq[string] {.noSideEffect,
|
||||||
|
|
||||||
proc countLines*(s: string): int {.noSideEffect,
|
proc countLines*(s: string): int {.noSideEffect,
|
||||||
rtl, extern: "nsuCountLines".} =
|
rtl, extern: "nsuCountLines".} =
|
||||||
## Returns the number of new line separators in the string `s`.
|
## Returns the number of lines in the string `s`.
|
||||||
##
|
##
|
||||||
## This is the same as ``len(splitLines(s))``, but much more efficient
|
## This is the same as ``len(splitLines(s))``, but much more efficient
|
||||||
## because it doesn't modify the string creating temporal objects. Every
|
## because it doesn't modify the string creating temporal objects. Every
|
||||||
## `character literal <manual.html#character-literals>`_ newline combination
|
## `character literal <manual.html#character-literals>`_ newline combination
|
||||||
## (CR, LF, CR-LF) is supported.
|
## (CR, LF, CR-LF) is supported.
|
||||||
##
|
##
|
||||||
## Despite its name this proc might not actually return the *number of lines*
|
## In this context, a line is any string seperated by a newline combination.
|
||||||
## in `s` because the concept of what a line is can vary. For example, a
|
## A line can be an empty string.
|
||||||
## string like ``Hello world`` is a line of text, but the proc will return a
|
var i = 1
|
||||||
## value of zero because there are no newline separators. Also, text editors
|
|
||||||
## usually don't count trailing newline characters in a text file as a new
|
|
||||||
## empty line, but this proc will.
|
|
||||||
var i = 0
|
|
||||||
while i < s.len:
|
while i < s.len:
|
||||||
case s[i]
|
case s[i]
|
||||||
of '\c':
|
of '\c':
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,7 @@ proc add*(m: PMessageArea, msg: ScChat) =
|
||||||
of CPriv, CSystem: mmm.color = Green
|
of CPriv, CSystem: mmm.color = Green
|
||||||
of CError: mmm.color = Red
|
of CError: mmm.color = Red
|
||||||
|
|
||||||
mmm.lines = countLines(mmm.text)+1
|
mmm.lines = countLines(mmm.text)
|
||||||
|
|
||||||
m.messages.add mmm
|
m.messages.add mmm
|
||||||
update m
|
update m
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue