|
|
@@ -316,4 +316,46 @@ public class StringUtil {
|
|
|
return decimalFormat.format(s);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 일정 규칙에 따라서 두 줄로 처리된 문자열을 반환한다.
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String twoLine(String str) {
|
|
|
+
|
|
|
+ // 타이틀 줄바꿈이 사라져서 강제로 줄바꿈 해줌
|
|
|
+ if (StringUtil.isEmpty(str)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // \\n 문자를 줄바꿈 문자로 변경
|
|
|
+ str = str.replaceAll("\\\\n", System.getProperty("line.separator"));
|
|
|
+
|
|
|
+ // 줄바꿈이 있으면 그대로 전달
|
|
|
+ if (str.contains("\n")) {
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (str.length() < 13) {
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ String[] titles = str.split(" ");
|
|
|
+ int len = titles.length;
|
|
|
+ // 줄바꿈 위치 지정 6단어 이상이면 4번째부터, 그 이하는 3번째 단어에서 줄바꿈 해줌
|
|
|
+ int target = len > 5 ? 3 : 2;
|
|
|
+ // 줄바꿈 할 위치보다 단어가 적으면 하지 않음
|
|
|
+ if (target >= len) {
|
|
|
+ target = -1;
|
|
|
+ }
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ if (i == target) {
|
|
|
+ stringBuilder.append("\n");
|
|
|
+ }
|
|
|
+ stringBuilder.append(titles[i]).append(" ");
|
|
|
+ }
|
|
|
+ return stringBuilder.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|