|
@@ -1,14 +1,22 @@
|
|
|
package lib;
|
|
|
|
|
|
public class TextLayoutHelper {
|
|
|
- public static String strToLen( String s, int l )
|
|
|
+ /**
|
|
|
+ * Modifies the given string such that its lenght matches the given length.
|
|
|
+ * If the string is too small, whitespace is appended on both sides equally.
|
|
|
+ * Then, if the string is too large, it is cut off on the right.
|
|
|
+ * @param s the string
|
|
|
+ * @param lenght the target length
|
|
|
+ * @return the modified string
|
|
|
+ */
|
|
|
+ public static String strToLen( String s, int lenght )
|
|
|
{
|
|
|
- while( s.length() < l )
|
|
|
+ while( s.length() < lenght )
|
|
|
{
|
|
|
s = " " + s + " ";
|
|
|
}
|
|
|
- if( s.length() > l )
|
|
|
- return s.substring( 0, l );
|
|
|
+ if( s.length() > lenght )
|
|
|
+ return s.substring( 0, lenght );
|
|
|
return s;
|
|
|
}
|
|
|
}
|