From 54ac3a167e31cfdb68ac9a068837b56bc9ba9c54 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Mon, 11 Dec 2023 09:24:41 +0900 Subject: [PATCH] =?UTF-8?q?=ED=95=9C=EA=B8=80=20=EC=9D=B8=EC=BD=94?= =?UTF-8?q?=EB=94=A9=20=EA=B4=80=EB=A0=A8=20=EC=9C=A0=ED=8B=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cokr/xit/fims/cmmn/CmmnUtil.java | 80 ---------- src/main/java/cokr/xit/fims/cmmn/Hangul.java | 140 ++++++++++++++++++ .../xit/fims/crdn/parsing/LayoutParser.java | 5 +- .../fims/crdn/parsing/SingleFileParser.java | 6 +- .../xit/fims/crdn/web/Crdn05Controller.java | 5 +- 5 files changed, 150 insertions(+), 86 deletions(-) create mode 100644 src/main/java/cokr/xit/fims/cmmn/Hangul.java diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index 3737a8be..2faa8103 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -57,86 +57,6 @@ public class CmmnUtil { return Pattern.matches(REGEXP_PATTERN_KOR, str); } - /** - * 문자열을 바이트 단위로 substring하기 - * - * new String(str.getBytes(), 0, endBytes) 코드를 사용하면 - * 한글 바이트에 딱 맞춰 자르지 않는 경우 깨지는 문제가 있어서 따로 메서드를 만들었다. - * - * UTF-8 기준 한글은 3바이트, 알파벳 대소문자나 숫자 및 띄어쓰기는 1바이트로 계산된다. - * - * @param str - * @param beginBytes - * @param endBytes - * @return - */ - public static String substringByBytes(String str, int beginBytes, int endBytes) { - if (str == null || str.length() == 0) { - return ""; - } - - if (beginBytes < 0) { - beginBytes = 0; - } - - if (endBytes < 1) { - return ""; - } - - int len = str.length(); - - int beginIndex = -1; - int endIndex = 0; - - int curBytes = 0; - String ch = null; - for (int i = 0; i < len; i++) { - ch = str.substring(i, i + 1); - curBytes += ch.getBytes().length; - - - if (beginIndex == -1 && curBytes >= beginBytes) { - beginIndex = i; - } - - if (curBytes > endBytes) { - break; - } else { - endIndex = i + 1; - } - } - - return str.substring(beginIndex, endIndex); - } - - public static String substringByBytes(String str, int beginBytes) { - if (str == null || str.length() == 0) { - return ""; - } - - if (beginBytes < 0) { - beginBytes = 0; - } - - int len = str.length(); - - int beginIndex = -1; - - int curBytes = 0; - String ch = null; - for (int i = 0; i < len; i++) { - ch = str.substring(i, i + 1); - curBytes += ch.getBytes().length; - - - if (beginIndex == -1 && curBytes >= beginBytes) { - beginIndex = i; - } - - } - - return str.substring(beginIndex); - } /** * 하위 폴더가 비워져 있으면 삭제한다. diff --git a/src/main/java/cokr/xit/fims/cmmn/Hangul.java b/src/main/java/cokr/xit/fims/cmmn/Hangul.java new file mode 100644 index 00000000..236321a3 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/Hangul.java @@ -0,0 +1,140 @@ +package cokr.xit.fims.cmmn; + +public class Hangul { + + public Hangul(int hangulIsNByte){ + this.hangulIsNByte = hangulIsNByte; + } + + private int hangulIsNByte; + + public int is() { + return this.hangulIsNByte; + } + + /** + * 문자열의 바이트 수 구하기 + * + * @param str + * @return + */ + public int getByteLength(String str) { + + int byteLen = 0; + + for(int i=0;i 127) || (ch < 0)) { + byteLen += this.is(); + } else { + byteLen += 1; + } + } + + return byteLen; + } + + /** + * 문자열을 바이트 단위로 패딩 + * + * @param str + * @param byteLen + * @param ch + * @return + */ + public String rpadByte(String str, int byteLen, String ch) { + String result = str; + + int strLen = this.getByteLength(str); + + for(int i=0; i < byteLen - strLen ; i++) { + result += ch; + } + + return result; + } + + /** + * 문자열을 바이트 단위로 substring하기 + * + * @param str + * @param beginBytes + * @param endBytes + * @return + */ + public String substringByBytes(String str, int beginBytes, int endBytes) { + if (str == null || str.length() == 0) { + return ""; + } + + if (beginBytes < 0) { + beginBytes = 0; + } + + if (endBytes < 1) { + return ""; + } + + int len = str.length(); + + int beginIndex = -1; + int endIndex = 0; + + int curBytes = 0; + String ch = null; + for (int i = 0; i < len; i++) { + ch = str.substring(i, i + 1); + curBytes += this.getByteLength(ch); + + + if (beginIndex == -1 && curBytes >= beginBytes) { + beginIndex = i; + } + + if (curBytes > endBytes) { + break; + } else { + endIndex = i + 1; + } + } + + return str.substring(beginIndex, endIndex); + } + + /** + * 문자열을 바이트 단위로 substring하기 + * + * @param str + * @param beginBytes + * @return + */ + public String substringByBytes(String str, int beginBytes) { + if (str == null || str.length() == 0) { + return ""; + } + + if (beginBytes < 0) { + beginBytes = 0; + } + + int len = str.length(); + + int beginIndex = -1; + + int curBytes = 0; + String ch = null; + for (int i = 0; i < len; i++) { + ch = str.substring(i, i + 1); + curBytes += this.getByteLength(ch); + + + if (beginIndex == -1 && curBytes >= beginBytes) { + beginIndex = i; + } + + } + + return str.substring(beginIndex); + } +} diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java b/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java index dc8d231d..d3f84558 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java @@ -14,8 +14,8 @@ import java.util.stream.Collectors; import org.apache.commons.io.FilenameUtils; import cokr.xit.base.code.CommonCode; -import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.CodeConverter; +import cokr.xit.fims.cmmn.Hangul; import cokr.xit.foundation.data.DataObject; import net.minidev.json.JSONArray; import net.minidev.json.JSONObject; @@ -369,6 +369,7 @@ abstract public class LayoutParser { * @return */ public String[] smartSplit(String string, JSONArray jsonArray) { + Hangul hangul = new Hangul(2); List byteNums = new ArrayList(); for(int i=0; i fileList = null; try { //폴더는 제외하고 파일만 필터링