File: _text_utils.tcl

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (60 lines) | stat: -rw-r--r-- 1,816 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- tcl -*-
#
# Copyright (c) 2019 Andreas Kupries <andreas_kupries@sourceforge.net>
# Freely redistributable.
#
# _text_utils.tcl -- Text formatting utilities

# # ## ### ##### ########
## API

proc Dots {x} { string map {{ } . {	} .} $x }

proc Compose {lb} {
    upvar 1 $lb linebuffer
    return [string trimright [join $linebuffer \n]]
}

proc ReHead {line prefix} {
    set n [string length [DeIce $prefix]]
    incr n -1
    string replace $line 0 $n $prefix
}

proc MaxLen {v s} {
    upvar 1 $v max
    set n [string length $s]
    if {$n <= $max} return
    set max $n
}

proc DeIce {x} { string map [list \1 {}] $x }

proc BlankMargin {} { global lmarginIncrement ; Blank $lmarginIncrement }

proc Repeat  {char n}      { textutil::repeat::strRepeat $char $n }
proc Blank   {n}           { textutil::repeat::blank $n }
proc RepeatM {char text}   { Repeat $char [string length [DeIce $text]] }
proc BlankM  {text}        { Blank        [string length [DeIce $text]] }
proc Undent  {text}        { textutil::adjust::undent $text }
proc Reflow  {text maxlen} { textutil::adjust::adjust $text -length $maxlen }
proc Indent  {text prefix} { textutil::adjust::indent $text $prefix }
proc Indent1 {text p1 p}   { return "${p1}[textutil::adjust::indent $text $p 1]" }
proc InFlow {text maxlen prefix1 prefix} {
    # Reformats the paragraph `text` to keep line length under
    # `maxlen` and then indents the result using `prefix1` and
    # `prefix`.  `prefix1` is applied to the first line, and `prefix`
    # to the remainder. The caller is responsible for ensuring that
    # both prefixes have the same length.
    Indent1 [Reflow $text $maxlen] $prefix1 $prefix
}

proc Provenance {} {
    textutil::string::uncap [c_provenance]
}

# # ## ### ##### ########
# Internals

# # ## ### ##### ########
return