From 5a3c88d3ad599cc02af9f566e073f868cfaaf559 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 18 Jul 2014 12:54:52 +0200 Subject: Mentions countLines() may return unexpected values. --- lib/pure/strutils.nim | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 51392ba50..949f9e52e 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -280,9 +280,11 @@ iterator split*(s: string, sep: string): string = inc(last, sep.len) iterator splitLines*(s: string): string = - ## Splits the string `s` into its containing lines. Every newline - ## combination (CR, LF, CR-LF) is supported. The result strings contain - ## no trailing ``\n``. + ## Splits the string `s` into its containing lines. + ## + ## Every `character literal `_ newline + ## combination (CR, LF, CR-LF) is supported. The result strings contain no + ## trailing ``\n``. ## ## Example: ## @@ -315,13 +317,25 @@ iterator splitLines*(s: string): string = proc splitLines*(s: string): seq[string] {.noSideEffect, rtl, extern: "nsuSplitLines".} = - ## The same as the `splitLines` iterator, but is a proc that returns a - ## sequence of substrings. + ## The same as the `splitLines <#splitLines.i,string>`_ iterator, but is a + ## proc that returns a sequence of substrings. accumulateResult(splitLines(s)) proc countLines*(s: string): int {.noSideEffect, rtl, extern: "nsuCountLines".} = - ## same as ``len(splitLines(s))``, but much more efficient. + ## Returns the number of new line separators 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 `_ 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 while i < s.len: case s[i] -- cgit 1.4.1-2-gfad0