File: hyphenation.lisp

package info (click to toggle)
cl-typesetting 117-3
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 808 kB
  • ctags: 508
  • sloc: lisp: 4,073; makefile: 33; sh: 22
file content (18 lines) | stat: -rw-r--r-- 804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
;;; cl-typesetting copyright 2002 Marc Battyani see license.txt for details of the license
;;; You can reach me at marc.battyani@fractalconcept.com or marc@battyani.net

(in-package typeset)

(defun hyphenate-string (string)
  (let ((min-word-size (+ nix::*left-hyphen-minimum* nix::*right-hyphen-minimum*)))
    (when (>= (length string) min-word-size)
      (loop
	  for prev-word-end = 0 then word-end
	  for word-start = (position-if #'alpha-char-p string :start prev-word-end)
	  for word-end = (when word-start (position-if-not #'alpha-char-p string :start word-start))
	  while word-end
	  when (>= (- word-end word-start) min-word-size)
	  nconc (mapcar #'(lambda (n) (+ word-start n))
			(nix::hyphen-find-hyphen-points
			 nix::*american-hyphen-trie* (subseq string word-start word-end)))))))