File: strings.gle

package info (click to toggle)
gle-graphics-library 4.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,164 kB
  • sloc: python: 183; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download | duplicates (2)
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
! Subroutines for string processing.
! Author: Francois Tonneau

! List of subroutines:

! grouped$: return a string with separated groups of letters/digits.

! spaced$: return a string with spaces in it.

sub grouped$ string$ grouping separator$
    !
    ! string$    = target string, e.g., "884401"
    ! grouping   = number of characters forming a group (e.g., 3)
    ! separator$ = char to be inserted between groups (e.g, ",")
    !
    if (len(string$) = 0) or (grouping <= 0) then return
    local output$ = ""
    local last = len(string$)
    local pos, char$, tailsize
    for pos = 1 to last
        char$ = seg$(string$, pos, pos)
        tailsize = last - pos
        if (tailsize > 0) and (tailsize % grouping = 0) then
            output$ = output$ + char$ + separator$
        else
            output$ = output$ + char$
        end if
    next pos
    return output$
end sub

sub spaced$ string$ pseudoblank$
    !
    ! string$       = string with space surrogates (to be converted to spaces)
    ! pseudoblank $ = char to be replaced by spaces (e.g, "_")
    !
    if len(string$) = 0 then return
    local output$ = ""
    local last = len(string$)
    local pos, char$
    for pos = 1 to last
        char$ = seg$(string$, pos, pos)
        if char$ = pseudoblank$ then
            !
            ! We use \char{32} (which prints as space) instead of a litteral
            ! space (" ") to permit multiple spaces in a row.
            output$ = output$ + "\char{32}"
        else
            output$ = output$ + char$
        end if
    next pos
    return output$
end sub