-
Notifications
You must be signed in to change notification settings - Fork 81
/
Indent.java
52 lines (46 loc) · 1.44 KB
/
Indent.java
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
package dev.nipafx.demo.java12.api.string;
public class Indent {
public static void main(String[] args) {
variousIndentations();
setIndentation();
}
private static void variousIndentations() {
/*
// imagine raw string literals where a thing:
String html = ```
<body>
<h1>Header</h1>
</body>```;
*/
String html = ""
+ " <body>\n"
+ " <h1>Header</h1>\n"
+ " </body>";
// then it would be helpful to manipulate indentation depth
System.out.println("org:\n" + html + "\n");
System.out.println("0:\n" + html.indent(0) + "\n");
System.out.println("2:\n" + html.indent(2) + "\n");
System.out.println("4:\n" + html.indent(4) + "\n");
System.out.println("-2:\n" + html.indent(-2) + "\n");
System.out.println("-4:\n" + html.indent(-4) + "\n");
System.out.println("-8:\n" + html.indent(-8) + "\n");
System.out.println("-12:\n" + html.indent(-12) + "\n");
System.out.println("-16:\n" + html.indent(-16) + "\n");
}
private static void setIndentation() {
/*
// imagine raw string literals where a thing:
String html = ```
<body>
<h1>Header</h1>
</body>```;
.indent(-16);
*/
String html = (""
+ " <body>\n"
+ " <h1>Header</h1>\n"
+ " </body>")
.indent(-16);
System.out.println(html);
}
}