Skip to content

Commit

Permalink
숫자, 알파벳 각각 핸들링
Browse files Browse the repository at this point in the history
  • Loading branch information
kimcore committed Jul 26, 2020
1 parent e44d638 commit 2286f85
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id "java"
id "org.jetbrains.kotlin.jvm" version "1.3.72"
}

group 'com.github.kimcore'
version '1.2'
group "com.github.kimcore"
version "1.3"

repositories {
mavenCentral()
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
testImplementation "junit:junit:4.12"
}

compileKotlin {
Expand All @@ -23,6 +23,6 @@ compileTestKotlin {
}

task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
archiveClassifier.set("sources")
from sourceSets.main.allSource
}
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Jul 20 08:31:12 KST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'Josa.kt'
rootProject.name = "Josa.kt"
13 changes: 8 additions & 5 deletions src/main/kotlin/com/github/kimcore/josa/Josa.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ object Josa {
)

private fun has(s: String): Boolean =
("[가-힣]$|/".toRegex().containsMatchIn(s) && (s.trim().last().toInt() - 0xac00) % 28 > 0)
|| ("[가-힣]\\d*[013678]$|/".toRegex().containsMatchIn(s)
|| "[a-z]\\d*[1789]$|/i".toRegex().containsMatchIn(s))
|| "([clmnp]|[blnt](e)|[co](k)|[aeiou](t)|mb|ng|lert)$|/i".toRegex().containsMatchIn(s)
("[가-힣]$".toRegex().containsMatchIn(s) && (s.trim().last().toInt() - 0xac00) % 28 > 0)
|| ("[가-힣]\\d*[013678]$".toRegex().containsMatchIn(s)
|| "[a-z]\\d*[1789]$".toRegex(RegexOption.IGNORE_CASE).containsMatchIn(s))
|| (s.trim().length != 1 && "([clmnp]|[blnt](e)|[co](k)|[aeiou](t)|mb|ng|lert)$".toRegex(RegexOption.IGNORE_CASE).containsMatchIn(s))
|| (s.trim().length == 1 && "[lnmr]$".toRegex(RegexOption.IGNORE_CASE).matches(s))
|| ("\\d$".toRegex().matches(s) && "[013678]$".toRegex().containsMatchIn(s))

private fun replace(s: String): String = s
.replace("(.*)/gi".toRegex(), "").replace("[^ㄱ-ㅎㅏ-ㅣ가-힣a-zA-Z\\d]".toRegex(), "")
.replace("\\(.*\\)".toRegex(RegexOption.IGNORE_CASE), "")
.replace("[^ㄱ-ㅎㅏ-ㅣ가-힣a-zA-Z\\d]".toRegex(RegexOption.IGNORE_CASE), "")
.replace("", "ㄱㅅ").replace("", "ㄴㅈ")
.replace("", "ㄹㅂ").replace("", "ㄹㅅ")
.replace("", "ㄹㅌ").replace("", "ㅂㅅ")
Expand Down
40 changes: 40 additions & 0 deletions src/test/kotlin/com/github/kimcore/josa/JosaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,45 @@ class JosaTest {
assertEquals("사과 3이야", "사과 3".야이야)
assertEquals("apple 3야", "apple 3".야이야)
assertEquals("apple 이야", "apple ".야이야)

// 숫자 0-9
assertEquals("0을", "0".을를)
assertEquals("1을", "1".을를)
assertEquals("2를", "2".을를)
assertEquals("3을", "3".을를)
assertEquals("4를", "4".을를)
assertEquals("5를", "5".을를)
assertEquals("6을", "6".을를)
assertEquals("7을", "7".을를)
assertEquals("8을", "8".을를)
assertEquals("9를", "9".을를)

// 알파벳 a-z
assertEquals("a를", "a".을를)
assertEquals("b를", "b".을를)
assertEquals("c를", "c".을를)
assertEquals("d를", "d".을를)
assertEquals("e를", "e".을를)
assertEquals("f를", "f".을를)
assertEquals("g를", "g".을를)
assertEquals("h를", "h".을를)
assertEquals("i를", "i".을를)
assertEquals("j를", "j".을를)
assertEquals("k를", "k".을를)
assertEquals("l을", "l".을를)
assertEquals("n을", "n".을를)
assertEquals("m을", "m".을를)
assertEquals("o를", "o".을를)
assertEquals("p를", "p".을를)
assertEquals("q를", "q".을를)
assertEquals("r을", "r".을를)
assertEquals("s를", "s".을를)
assertEquals("t를", "t".을를)
assertEquals("u를", "u".을를)
assertEquals("v를", "v".을를)
assertEquals("w를", "w".을를)
assertEquals("x를", "x".을를)
assertEquals("y를", "y".을를)
assertEquals("z를", "z".을를)
}
}

0 comments on commit 2286f85

Please sign in to comment.