-
Notifications
You must be signed in to change notification settings - Fork 12
/
format.red
53 lines (48 loc) · 904 Bytes
/
format.red
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
Red[
Title: "Formating functions"
Author: "Boleslav Březovský"
]
context [
tabs: func [
"Return required number of tabs"
count [integer!]
][
append/dup copy {} tab count
]
spaces: func [
"Return required number of spaces"
count [integer!]
][
append/dup copy {} space count
]
set 'entab func [
"Convert spaces to tabs (modifies)"
value [string!] "Script to convert"
/count "Number of spaces in tab /default is 4)"
cnt [integer!]
][
cnt: any [cnt 4]
parse value [
some [
opt [change copy indent some space (tabs (length? indent) / cnt)]
thru newline
]
]
value
]
set 'detab func [
"Convert tabs to spaces (modifies)"
value [string!] "Script to convert"
/count "Number of spaces in tab /default is 4)"
cnt [integer!]
][
cnt: any [cnt 4]
parse value [
some [
opt [change copy indent some tab (spaces (length? indent) * cnt)]
thru newline
]
]
value
]
]