-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.groovy
43 lines (35 loc) · 928 Bytes
/
layout.groovy
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
def (aligns, spaces) = getLayoutStringParsed(args[0])
println "aligns: [${aligns.join('|')}]"
println "spaces: [${spaces.join('|')}]"
List getLayoutStringParsed(layoutString) {
if (!layoutString) throw new Exception("No layoutString specified!")
def aligns = []
def spaces = ['']
boolean inBrace = false
layoutString.each { c ->
if (c == '[') return inBrace = true
if (c == ']') {
inBrace = false
spaces << ''
return
}
if (inBrace) return aligns << Align.parse(c)
spaces[-1] += c
}
[aligns, spaces.collect { it.toLowerCase() == 'fill' ? 'fill' : it }]
}
enum Align {
LEFT, RIGHT
public static Align parse(String s) {
switch (s) {
case ['l','L']:
LEFT
break
case ['r','R']:
RIGHT
break
default:
throw new RuntimeException("Unsupported layout specifier '${s}' encountered for StringLayout")
}
}
}