e9353c83ccde43c2c77128359fe329cfc11dec17
1 package be
.nikiroo
.jvcard
.tui
;
3 import com
.googlecode
.lanterna
.gui2
.LinearLayout
.Alignment
;
5 public class StringUtils
{
7 static public String
padString(String text
, int width
) {
8 return padString(text
, width
, true, Alignment
.Beginning
);
11 // TODO: doc it, width of -1 == no change to text
12 static public String
padString(String text
, int width
, boolean cut
,
19 int diff
= width
- text
.length();
23 text
= text
.substring(0, width
);
24 } else if (diff
> 0) {
25 if (diff
< 2 && align
!= Alignment
.End
)
26 align
= Alignment
.Beginning
;
30 text
= text
+ new String(new char[diff
]).replace('\0', ' ');
33 text
= new String(new char[diff
]).replace('\0', ' ') + text
;
38 int pad1
= (diff
) / 2;
39 int pad2
= (diff
+ 1) / 2;
40 text
= new String(new char[pad1
]).replace('\0', ' ') + text
41 + new String(new char[pad2
]).replace('\0', ' ');