Date: 2017/03/03 19:58:44 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
40
41
42
43
44
#
#--------------------------------------
#
# Line Wrap Utility
#
# Turn a long string into a list of smaller strings
#
# Usage: <procedure[script:LineWrap|string:string|length:10].return>
# Example: <procedure[script:LineWrap|string:Hi i am a long string m8|length:10].return>
LineWrap:
type: procedure
speed: 0
debug: minimal
script:
- define string '<context.string>'
- define stringLen <context.string.length>
- define targetLen <context.length>
- define increment 0
- if <def[stringLen]> > <def[targetLen]>:
- define lines '<list[]>'
- while <def[stringLen].is_greater_than[0]>:
- define low '<def[increment].add[1]>'
- define hi '<def[increment].add[<def[targetLen]>]>'
- define pass '<def[string].substring[<def[low]>|<def[hi]>]>'
- if <def[pass].length> == <def[stringLen]>:
- addto lines list '<def[pass]>'
- while stop
- else:
- define brake '<def[pass].last_index_of_cased[ ]>'
- define increment '<def[increment].add[<def[brake]>]>'
- if <def[brake]> > 0:
- define passtrim '<def[brake]>'
- else:
- define passtrim '<def[pass].length>'
- define passtrim '<def[pass].substring[1|<def[passtrim]>]>'
- addto lines list '<def[passtrim]>'
- define stringLen '<def[stringLen].subtract[<def[brake]>]>'
- determine return '<def[lines]>'
- else:
- determine return '<def[string]>'
#
# END Line Wrap Utility
#--------------------------------------