summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSimon Krauter <trustable-code@users.noreply.github.com>2017-03-03 01:31:17 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-03-03 01:31:17 +0100
commita42801d100c2ec33b93af89f7fd2b17cfe5d4fbc (patch)
tree5c5062ab96e6f53dbe10fbb3e8331e0448b1d12c
parentf7af16a1c90914901082ad6a0ba3a7a891f807ee (diff)
downloadNim-a42801d100c2ec33b93af89f7fd2b17cfe5d4fbc.tar.gz
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.
-rw-r--r--lib/packages/docutils/rstgen.nim2
-rw-r--r--lib/pure/strutils.nim12
-rw-r--r--tests/manyloc/keineschweine/lib/sg_gui.nim2
3 files changed, 6 insertions, 10 deletions
diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim
index 47247dd7c..ce63d780c 100644
--- a/lib/packages/docutils/rstgen.nim
+++ b/lib/packages/docutils/rstgen.nim
@@ -870,7 +870,7 @@ proc buildLinesHTMLTable(d: PDoc; params: CodeBlockParams, code: string):
               d.config.getOrDefault"doc.listing_end" % id)
     return
 
-  var codeLines = 1 + code.strip.countLines
+  var codeLines = code.strip.countLines
   assert codeLines > 0
   result.beginTable = """<table class="line-nums-table"><tbody><tr><td class="blob-line-nums"><pre class="line-nums">"""
   var line = params.startLine
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 9b2526337..a87df7f52 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -767,20 +767,16 @@ proc splitLines*(s: string): seq[string] {.noSideEffect,
 
 proc countLines*(s: string): int {.noSideEffect,
   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
   ## because it doesn't modify the string creating temporal objects. Every
   ## `character literal <manual.html#character-literals>`_ newline combination
   ## (CR, LF, CR-LF) is supported.
   ##
-  ## Despite its name this proc might not actually return the *number of lines*
-  ## in `s` because the concept of what a line is can vary. For example, a
-  ## string like ``Hello world`` is a line of text, but the proc will return a
-  ## 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
+  ## In this context, a line is any string seperated by a newline combination.
+  ## A line can be an empty string.
+  var i = 1
   while i < s.len:
     case s[i]
     of '\c':
diff --git a/tests/manyloc/keineschweine/lib/sg_gui.nim b/tests/manyloc/keineschweine/lib/sg_gui.nim
index aae51baec..ffc4e8215 100644
--- a/tests/manyloc/keineschweine/lib/sg_gui.nim
+++ b/tests/manyloc/keineschweine/lib/sg_gui.nim
@@ -240,7 +240,7 @@ proc add*(m: PMessageArea, msg: ScChat) =
   of CPriv, CSystem: mmm.color = Green
   of CError: mmm.color = Red
 
-  mmm.lines = countLines(mmm.text)+1
+  mmm.lines = countLines(mmm.text)
 
   m.messages.add mmm
   update m