1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.core.pattern;
11
12 public class SpacePadder {
13
14 final static String[] SPACES = { " ", " ", " ", " ",
15
16 " ",
17 " " };
18
19 final static public void leftPad(StringBuffer buf, String s, int desiredLength) {
20 int actualLen = 0;
21 if (s != null) {
22 actualLen = s.length();
23 }
24 if (actualLen < desiredLength) {
25 spacePad(buf, desiredLength - actualLen);
26 }
27 if (s != null) {
28 buf.append(s);
29 }
30 }
31
32 final static public void rightPad(StringBuffer buf, String s, int desiredLength) {
33 int actualLen = 0;
34 if (s != null) {
35 actualLen = s.length();
36 }
37 if (s != null) {
38 buf.append(s);
39 }
40 if (actualLen < desiredLength) {
41 spacePad(buf, desiredLength - actualLen);
42 }
43 }
44
45
46
47
48 final static public void spacePad(StringBuffer sbuf, int length) {
49 while (length >= 32) {
50 sbuf.append(SPACES[5]);
51 length -= 32;
52 }
53
54 for (int i = 4; i >= 0; i--) {
55 if ((length & (1 << i)) != 0) {
56 sbuf.append(SPACES[i]);
57 }
58 }
59 }
60 }