Skip to content

Commit

Permalink
1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kimcore committed Dec 18, 2020
1 parent b8d8345 commit 51aaf52
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ allprojects {
}
dependencies {
implementation 'im.kimcore:Josa.kt:1.5'
implementation 'im.kimcore:Josa.kt:1.6'
}
```
Maven
Expand All @@ -30,7 +30,7 @@ Maven
<dependency>
<groupId>im.kimcore</groupId>
<artifactId>Josa.kt</artifactId>
<version>1.5</version>
<version>1.6</version>
</dependency>
</dependencies>
```
Expand Down Expand Up @@ -80,15 +80,24 @@ println(Josa.get("준식", "은/는")) // 은
* 이/가
* 라/이라
* 야/이야

#### 지원되지 않는 포맷을 입력할 경우

## 커스텀 포맷
기본으로 지원하는 포맷 외에도, 사용자가 직접 지정한 포맷을 사용할 수 있습니다.
`을/를`같이 적용할 조사를 `/`로 구분하여 받침이 있는 경우를 앞에, 받침이 없는 경우를 뒤에 입력하시면 됩니다.
```kotlin
import com.github.kimcore.josa.Josa.josa

println("2".josa("이었/였") + "습니다!") // 2였습니다!
println("3".josa("이었/였") + "습니다!") // 3이었습니다!
```
#### 잘못된 포맷을 입력할 경우
```kotlin
import com.github.kimcore.josa.Josa
import com.github.kimcore.josa.Josa.josa
try {
println("샌즈".josa("존재하지 않는 포맷"))
} catch(e: Josa.UnknownFormatException) {
println("지원되지 않는 포맷입니다!")
println("샌즈".josa("잘못된 포맷"))
} catch(e: Josa.MalformedFormatException) {
println("잘못된 포맷입니다!")
}
```
## 라이선스
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group "com.github.kimcore"
version "1.5"
version "1.6"

repositories {
mavenCentral()
Expand Down
Empty file modified gradle/wrapper/gradle-wrapper.jar
100644 → 100755
Empty file.
16 changes: 11 additions & 5 deletions src/main/kotlin/com/github/kimcore/josa/Josa.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ object Josa {

@JvmStatic
fun get(s: String, format: String): String {
if (!formats.containsKey(format)) throw UnknownFormatException()
if (!format.contains("/") || format.count { it == '/' } > 1) throw MalformedFormatException()
val handler = formats.getOrDefault(format) {
val first = format.split("/")[0]
val second = format.split("/")[1]
if (has(it)) first else second
}
val value = replace(s)
if (value.isBlank()) return when (formats.getValue(format)) {
if (value.isBlank()) return when (handler) {
handlers[0] -> "을(를)"
handlers[1] -> "은(는)"
handlers[2] -> "이(가)"
Expand All @@ -77,9 +82,10 @@ object Josa {
handlers[5] -> "(이)나"
handlers[6] -> "아(야)"
handlers[7] -> "(이)라"
else -> "(이)야"
handlers[8] -> "(이)야"
else -> "(${format.split("/")[0]})${format.split("/")[1]}"
}
return formats.getValue(format)(value)
return handler(value)
}

@JvmStatic
Expand Down Expand Up @@ -124,5 +130,5 @@ object Josa {
val String.야이야: String
get() = getAttached(this, "야/이야")

class UnknownFormatException : Exception("Unknown format for Josa.")
class MalformedFormatException : Exception("Malformed format for Josa.")
}
5 changes: 5 additions & 0 deletions src/test/kotlin/com/github/kimcore/josa/JosaTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.kimcore.josa

import com.github.kimcore.josa.Josa.josa
import com.github.kimcore.josa.Josa.나이나
import com.github.kimcore.josa.Josa.로으로
import com.github.kimcore.josa.Josa.아야
Expand Down Expand Up @@ -102,5 +103,9 @@ class JosaTest {
assertEquals("x를", "x".을를)
assertEquals("y를", "y".을를)
assertEquals("z를", "z".을를)

// 커스텀 포맷
assertEquals("2였", "2".josa("이었/였"))
assertEquals("3이었", "3".josa("이었/였"))
}
}

0 comments on commit 51aaf52

Please sign in to comment.