forked from Blankj/AndroidUtilCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.gradle
90 lines (84 loc) · 3.39 KB
/
readme.gradle
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import groovy.transform.Field
@Field LINE_SEP = System.getProperty("line.separator")
@Field LONG_SPACE = " "
task readmeTask << {
def readmeCN = file("./utilcode/README-CN.md")
def readmeEng = file("./utilcode/README.md")
readmeOfUtilCode2Eng(readmeCN, readmeEng)
readmeCN = file("./subutil/README-CN.md")
readmeEng = file("./subutil/README.md")
readmeOfSubUtil2Eng(readmeCN, readmeEng)
}
def readmeOfUtilCode2Eng(File readmeCN, File readmeEng) {
format(readmeCN)
def lines = readmeCN.readLines("UTF-8")
def sb = new StringBuilder()
readmeCN.eachLine { line ->
if (line.contains("* ###")) {
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"))
sb.append("* ### About ").append(utilsName).append(line.substring(line.indexOf(" -> ")))
} else if (line.contains(": ") && !line.contains("[")) {
sb.append(line.substring(0, line.indexOf(':')).trim())
} else {
sb.append(line)
}
sb.append(LINE_SEP)
}
readmeEng.write(sb.toString(), "UTF-8")
}
def readmeOfSubUtil2Eng(File readmeCN, File readmeEng) {
format(readmeCN)
def lines = readmeCN.readLines("UTF-8"),
sb = new StringBuilder("## How to use" + LINE_SEP
+ LINE_SEP +
"You should copy the following classes which you want to use in your project." + LINE_SEP),
i = 3,
size = lines.size()
for (; i < size; ++i) {
String line = lines.get(i)
if (line.contains("* ###")) {
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"))
sb.append("* ### About ").append(utilsName).append(line.substring(line.indexOf(" -> ")))
} else if (line.contains(": ") && !line.contains("[")) {
sb.append(line.substring(0, line.indexOf(':')).trim())
} else {
sb.append(line)
}
sb.append(LINE_SEP)
}
readmeEng.write(sb.toString(), "UTF-8")
}
def format(File readmeCN) {
def sb = new StringBuilder(),
lines = readmeCN.readLines("UTF-8"),
i = 0,
size = lines.size()
for (; i < size; ++i) {
String line = lines.get(i)
if (line.contains("* ###")) {
sb.append(line).append(LINE_SEP)
.append("```").append(LINE_SEP)
def maxLen = 0
line = lines.get(i += 2)
// get the max length of space
for (def j = i; !line.equals("```"); line = lines.get(++j)) {
maxLen = Math.max(maxLen, line.replace(" ", "").replace(",", ", ").indexOf(':'))
}
line = lines.get(i)
for (; !line.equals("```"); line = lines.get(++i)) {
def noSpaceLine = line.replace(" ", "")
def spaceLen = maxLen - line.replace(" ", "").replace(",", ", ").indexOf(':')
sb.append(noSpaceLine.substring(0, noSpaceLine.indexOf(':')).replace(",", ", "))
.append(LONG_SPACE.substring(0, spaceLen))// add the space
.append(': ')
.append(line.substring(line.indexOf(':') + 1).trim())
.append(LINE_SEP)
}
sb.append("```")
} else {
sb.append(line)
}
sb.append(LINE_SEP)
}
readmeCN.write(sb.toString(), "UTF-8")
}