author | paulson <lp15@cam.ac.uk> |
Sun, 03 Aug 2025 20:34:24 +0100 | |
changeset 82913 | 7c870287f04f |
parent 74031 | 09821ca262d3 |
permissions | -rw-r--r-- |
74031 | 1 |
/* Title: Tools/Setup/src/Library.java |
73963 | 2 |
Author: Makarius |
3 |
||
4 |
Basic library. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.setup; |
|
8 |
||
9 |
||
10 |
import java.util.Arrays; |
|
11 |
import java.util.LinkedList; |
|
12 |
import java.util.List; |
|
13 |
||
14 |
||
15 |
public class Library |
|
16 |
{ |
|
74029
0701ff55780d
clarified build_props: empty module means no build;
wenzelm
parents:
74009
diff
changeset
|
17 |
public static String quote(String s) |
0701ff55780d
clarified build_props: empty module means no build;
wenzelm
parents:
74009
diff
changeset
|
18 |
{ |
0701ff55780d
clarified build_props: empty module means no build;
wenzelm
parents:
74009
diff
changeset
|
19 |
return "\"" + s + "\""; |
0701ff55780d
clarified build_props: empty module means no build;
wenzelm
parents:
74009
diff
changeset
|
20 |
} |
0701ff55780d
clarified build_props: empty module means no build;
wenzelm
parents:
74009
diff
changeset
|
21 |
|
73963 | 22 |
public static String cat_lines(Iterable<? extends CharSequence> lines) |
23 |
{ |
|
24 |
return String.join("\n", lines); |
|
25 |
} |
|
26 |
||
27 |
public static List<String> split_lines(String str) |
|
28 |
{ |
|
29 |
if (str.isEmpty()) { return List.of(); } |
|
30 |
else { |
|
31 |
List<String> result = new LinkedList<String>(); |
|
32 |
result.addAll(Arrays.asList(str.split("\\n"))); |
|
33 |
return List.copyOf(result); |
|
34 |
} |
|
35 |
} |
|
36 |
||
37 |
public static String prefix_lines(String prfx, String str) |
|
38 |
{ |
|
39 |
if (str.isEmpty()) { return str; } |
|
40 |
else { |
|
74009 | 41 |
List<String> lines = new LinkedList<String>(); |
42 |
for (String line : split_lines(str)) { lines.add(prfx + line); } |
|
43 |
return cat_lines(lines); |
|
73963 | 44 |
} |
45 |
} |
|
46 |
||
47 |
public static String trim_line(String s) |
|
48 |
{ |
|
49 |
if (s.endsWith("\r\n")) { return s.substring(0, s.length() - 2); } |
|
50 |
else if (s.endsWith("\r") || s.endsWith("\n")) { return s.substring(0, s.length() - 1); } |
|
51 |
else { return s; } |
|
52 |
} |
|
53 |
} |