66import org .robolectric .RuntimeEnvironment ;
77import org .robolectric .annotation .Config ;
88
9- import java .io .File ;
10- import java .util .List ;
11-
12- import static com .blankj .utilcode .util .TestConfig .FILE_SEP ;
13- import static com .blankj .utilcode .util .TestConfig .LINE_SEP ;
14-
159/**
1610 * <pre>
1711 * author: Blankj
@@ -28,97 +22,6 @@ public static void init() {
2822 Utils .init (RuntimeEnvironment .application );
2923 }
3024
31- private static final String LONG_SPACE = " " ;
32-
33- // @Test
34- public void readme2Eng () throws Exception {
35- String rootPath = new File (System .getProperty ("user.dir" )).getAbsolutePath () + FILE_SEP ;
36- File readmeCN = new File (rootPath + "utilcode" + FILE_SEP + "README-CN.md" );
37- File readme = new File (rootPath + "utilcode" + FILE_SEP + "README.md" );
38- readmeOfUtilCode (readmeCN , readme );
39-
40- readmeCN = new File (rootPath + "subutil" + FILE_SEP + "README-CN.md" );
41- readme = new File (rootPath + "subutil" + FILE_SEP + "README.md" );
42- readmeOfSubUtil (readmeCN , readme );
43- }
44-
45-
46- private void readmeOfUtilCode (File readmeCN , File readme ) throws Exception {
47- formatCN (readmeCN );
48- List <String > lines = FileIOUtils .readFile2List (readmeCN , "UTF-8" );
49- StringBuilder sb = new StringBuilder ();
50- for (String line : lines ) {
51- if (line .contains ("* ###" )) {
52- String utilsName = line .substring (line .indexOf ("[" ) + 1 , line .indexOf ("Utils" ));
53- sb .append ("* ### About " ).append (utilsName ).append (line .substring (line .indexOf ("→" )));
54- } else if (line .contains (": " ) && !line .contains ("[" )) {
55- sb .append (line .substring (0 , line .indexOf (':' )).trim ());
56- } else {
57- sb .append (line );
58- }
59- sb .append (LINE_SEP );
60- }
61- FileIOUtils .writeFileFromString (readme , sb .toString ());
62- }
63-
64-
65- private void readmeOfSubUtil (File readmeCN , File readme ) throws Exception {
66- formatCN (readmeCN );
67- List <String > lines = FileIOUtils .readFile2List (readmeCN , "UTF-8" );
68- StringBuilder sb = new StringBuilder ("## How to use" + LINE_SEP
69- + LINE_SEP +
70- "You should copy the following classes which you want to use in your project." + LINE_SEP );
71- for (int i = 3 , len = lines .size (); i < len ; ++i ) {
72- String line = lines .get (i );
73- if (line .contains ("* ###" )) {
74- String utilsName = line .substring (line .indexOf ("[" ) + 1 , line .indexOf ("Utils" ));
75- sb .append ("* ### About " ).append (utilsName ).append (line .substring (line .indexOf ("→" )));
76- } else if (line .contains (": " ) && !line .contains ("[" )) {
77- sb .append (line .substring (0 , line .indexOf (':' )).trim ());
78- } else {
79- sb .append (line );
80- }
81- sb .append (LINE_SEP );
82- }
83- FileIOUtils .writeFileFromString (readme , sb .toString ());
84- }
85-
86- public void formatCN (File file ) throws Exception {
87- List <String > list = FileIOUtils .readFile2List (file , "UTF-8" );
88- StringBuilder sb = new StringBuilder ();
89- for (int i = 0 , len = list .size (); i < len ; ++i ) {
90- String line = list .get (i );
91- if (line .contains ("* ###" )) {
92- sb .append (line ).append (LINE_SEP );
93- int maxLen = 0 ;
94- line = list .get (++i );
95- // get the max length of space
96- for (int j = i ; !line .equals ("" ); line = list .get (++j )) {
97- if (line .equals ("```" )) continue ;
98- maxLen = Math .max (maxLen , line .replace (" " , "" ).replace ("," , ", " ).indexOf (':' ));
99- }
100- line = list .get (i );
101- for (; !line .equals ("" ); line = list .get (++i )) {
102- if (line .equals ("```" )) {
103- sb .append ("```" );
104- } else {
105- String noSpaceLine = line .replace (" " , "" );
106- int spaceLen = maxLen - line .replace (" " , "" ).replace ("," , ", " ).indexOf (':' );
107- sb .append (noSpaceLine .substring (0 , noSpaceLine .indexOf (':' )).replace ("," , ", " ))
108- .append (LONG_SPACE .substring (0 , spaceLen ))// add the space
109- .append (": " )
110- .append (noSpaceLine .substring (noSpaceLine .indexOf (':' ) + 1 ));
111- }
112- sb .append (LINE_SEP );
113- }
114- } else {
115- sb .append (line );
116- }
117- sb .append (LINE_SEP );
118- }
119- FileIOUtils .writeFileFromString (file , sb .toString ());
120- }
121-
12225 @ Test
12326 public void test () throws Exception {
12427
0 commit comments