summaryrefslogtreecommitdiff
path: root/module/texinfo/string-utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-03-22 22:05:23 +0100
committerLudovic Courtès <ludo@gnu.org>2013-03-22 22:05:23 +0100
commit43c2a48323803e9aae41ba896ce6b6a0067343ad (patch)
tree888100914bfac45ec24ea04ec485c51fd88f0cf0 /module/texinfo/string-utils.scm
parentc5c7c1146f2488f92b11b1edbe36fa99ffdf2771 (diff)
downloadguile-43c2a48323803e9aae41ba896ce6b6a0067343ad.tar.gz
texinfo: Add whitespace after periods.
* module/texinfo/string-utils.scm (end-of-sentence?): New procedure. (make-text-wrapper): Append an extra space after LINE when it matches `end-of-sentence?' and COLLAPSE-WHITESPACE? is false. * test-suite/tests/texinfo.serialize.test ("test-serialize"): Adjust accordingly. * test-suite/tests/texinfo.string-utils.test ("text wrapping")["two spaces after end of sentence"]: New test prefix.
Diffstat (limited to 'module/texinfo/string-utils.scm')
-rw-r--r--module/texinfo/string-utils.scm15
1 files changed, 13 insertions, 2 deletions
diff --git a/module/texinfo/string-utils.scm b/module/texinfo/string-utils.scm
index 767514952..22f969c04 100644
--- a/module/texinfo/string-utils.scm
+++ b/module/texinfo/string-utils.scm
@@ -1,6 +1,6 @@
;;;; (texinfo string-utils) -- text filling and wrapping
;;;;
-;;;; Copyright (C) 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2013 Free Software Foundation, Inc.
;;;; Copyright (C) 2003 Richard Todd
;;;;
;;;; This library is free software; you can redistribute it and/or
@@ -262,6 +262,13 @@ the default value for @var{num} is 1.
;; did not find non-ws... only ws at end of the string...
(reverse ans))))))
+(define (end-of-sentence? str)
+ "Return #t when STR likely denotes the end of sentence."
+ (let ((len (string-length str)))
+ (and (> len 1)
+ (eqv? #\. (string-ref str (- len 1)))
+ (not (eqv? #\. (string-ref str (- len 2)))))))
+
(define* (make-text-wrapper #:key
(line-width 80)
(expand-tabs? #t)
@@ -352,7 +359,11 @@ returns a list of strings, where each element of the list is one line."
length-left)
(loop ans
(cdr words)
- (string-append line next-word)
+ (if (and collapse-whitespace?
+ (end-of-sentence? line))
+ ;; Add an extra space after the period.
+ (string-append line " " next-word)
+ (string-append line next-word))
(+ count 1)))
;; ok, it didn't fit...is there already at least one word on the line?