Date: 2014/12/16 11:10:52 UTC-08:00
Type: Denizen Script
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
LineWrap:
# Turn a long string into a list of smaller strings
type: procedure
definitions: string|targetLen
debug: false
script:
- define stringLen '<def[string].length>'
- if <def[stringLen].is[MORE].than[%targetLen%]> {
- define lines 'li@'
- while <def[stringLen].is[MORE].than[0]> {
- define low '<def[increment].add[1].as_int||1>'
- define hi '<def[increment].add[<def[targetLen].add[1]>].as_int||%targetLen%>'
- define pass '<def[string].substring[%low%,%hi%]>'
- if <def[pass].length.is[LESS].than[%targetLen%]> {
- define brake '0'
}
else {
- define brake '<def[pass].last_index_of[ ]>'
}
- define increment '<def[increment].add[%brake%]||%brake%>'
- define passtrim '<def[pass].substring[1,%brake%]>'
- if <def[brake].is[==].to[0]||false> {
- define lines '<def[lines].include[%pass%]||<def[lines]>>'
}
else {
- define lines '<def[lines].include[%passtrim%]||<def[lines]>>'
}
- define stringLen '<def[stringLen].sub[%brake%]>'
- if <def[brake].is[==].to[0]>
|| <def[loop_index].is[MORE].than[5]> {
- while stop
}
}
- determine '<def[lines]>'
}
else {
- determine '<def[string]>'
}