한글 관련 처리 클래스 패키지 변경

main
이범준 4 days ago
parent c7939d5209
commit 36c298588b

@ -49,6 +49,13 @@
<artifactId>xit-docs</artifactId> <artifactId>xit-docs</artifactId>
<version>23.04.01-SNAPSHOT</version> <version>23.04.01-SNAPSHOT</version>
</dependency> </dependency>
<!-- 유니코드, 캐릭터셋 탐지 -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>75.1</version>
</dependency>
</dependencies> </dependencies>

@ -5,6 +5,56 @@ import java.util.regex.Pattern;
public class AppCmmnUtil { public class AppCmmnUtil {
/**
* (,) .
* @param
* @return boolean
*/
public static boolean isTelno(String str) {
//01X
String REGEXP_PHONE = "^(01)\\d{8,9}$";
if(Pattern.matches(REGEXP_PHONE, str)) {
return true;
}
//서울
String REGEXP_TEL = "^(02)\\d{7,8}$";
if(Pattern.matches(REGEXP_TEL, str)) {
return true;
}
//지방
REGEXP_TEL = "^(0)(3|4|5|6)\\d{8,9}$";
if(Pattern.matches(REGEXP_TEL, str)) {
return true;
}
//070
REGEXP_TEL = "^(070)\\d{7,8}$";
if(Pattern.matches(REGEXP_TEL, str)) {
return true;
}
//전국대표번호(0000-0000)
REGEXP_TEL = "^\\d{8}$";
if(Pattern.matches(REGEXP_TEL, str)) {
return true;
}
return false;
}
/**
* .
* @param
* @return boolean
*/
public static boolean isReceivePhone(String str) {
String REGEXP_PHONE = "^(01)\\d{8,9}$";
return Pattern.matches(REGEXP_PHONE, str);
}
/** /**
* . * .
* @param * @param
@ -35,4 +85,72 @@ public class AppCmmnUtil {
return false; return false;
} }
} }
/**
* .
* @param
* @return String
*/
public static String extractCarNumber(String carNum){
try{
String regex = "[서울|부산|대구|인천|대전|광주|울산|제주|경기|강원|충남|전남|전북|경남|경북|세종]{2}\\d{2}[가|나|다|라|마|거|너|더|러|머|버|서|어|저|고|노|도|로|모|보|소|오|조|구|누|두|루|무|부|수|우|주|바|사|아|자|허|배|호|하\\x20]\\d{4}";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(carNum);
if (m.find()) {
return m.group();
}
regex = "\\d{3}[가|나|다|라|마|거|너|더|러|머|버|서|어|저|고|노|도|로|모|보|소|오|조|구|누|두|루|무|부|수|우|주|바|사|아|자|허|배|호|하\\x20]\\d{4}";
p = Pattern.compile(regex);
m = p.matcher(carNum);
if (m.find()) {
return m.group();
}
regex = "\\d{2}[가|나|다|라|마|거|너|더|러|머|버|서|어|저|고|노|도|로|모|보|소|오|조|구|누|두|루|무|부|수|우|주|바|사|아|자|허|배|호|하\\x20]\\d{4}";
p = Pattern.compile(regex);
m = p.matcher(carNum);
if (m.find()) {
return m.group();
}
return "";
}catch(Exception e){
return "";
}
}
/**
* "연-월-일 시:분:초" .
* @param
* @return boolean
*/
public static boolean isDateTimePattern(String str){
String DATETIME_PATTERN = "(19|20)\\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9]";
Pattern datetimePattern = Pattern.compile(DATETIME_PATTERN);
if(datetimePattern.matcher(str).matches()) {
return true;
} else {
return false;
}
}
/**
* "연월일시분초" 14 .
* @param
* @return boolean
*/
public static boolean isDateTimeDigitPattern(String str){
String DATETIME_PATTERN = "^\\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])([0-1][0-9]|2[0-3])([0-5][0-9])([0-5][0-9])$";
if(Pattern.matches(DATETIME_PATTERN, str)) {
return true;
} else {
return false;
}
}
} }

@ -0,0 +1,222 @@
package cokr.xit.applib;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import com.ibm.icu.text.CharsetDetector;
import com.ibm.icu.text.CharsetMatch;
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) {
if(str == null) {
return 0;
}
int byteLen = 0;
for(int i=0;i<str.length();i++) {
char ch = str.charAt(i);
if((ch > 127) || (ch < 0)) {
byteLen += this.is();
} else {
byteLen += 1;
}
}
return byteLen;
}
/**
*
*
* @param str
* @param byteLen
* @param ch
* @return
*/
public String lpadByte(String str, int byteLen, String ch) {
String result = str;
int strLen = this.getByteLength(str);
for(int i=0; i < byteLen - strLen ; i++) {
result = ch + result;
}
return result;
}
/**
*
*
* @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);
}
/**
*
*
* @param path
* @return
*/
public String encodingDetect(String path) throws IOException {
File f = new File(path);
return encodingDetect(f);
}
/**
*
*
* @param file
* @return
*/
public String encodingDetect(File file) throws IOException {
CharsetDetector detector;
CharsetMatch match;
FileInputStream fis = null;
try {
String result = "";
fis = new FileInputStream(file);
byte[] byteData = new byte[(int) file.length()];
fis.read(byteData);
fis.close();
detector = new CharsetDetector();
detector.setText(byteData);
match = detector.detect();
System.out.println("encoding is \"" + match.getName() + "\"");
if(match.getName().equals("UTF-8") || match.getName().equals("EUC-KR")) {
result = match.getName();
} else {
result = "EUC-KR";
}
return result;
}
finally {
IOUtils.closeQuietly(fis);
}
}
}
Loading…
Cancel
Save