refactor: optimize CharItem to handle special characters in toString method
This commit is contained in:
parent
4f7cfae72d
commit
c7926c1f4d
1 changed files with 4 additions and 5 deletions
|
@ -76,12 +76,11 @@ class AndThenItem(val left: RegexItem, val right: RegexItem) : RegexItem {
|
|||
}
|
||||
|
||||
class CharItem(val value: String) : RegexItem {
|
||||
companion object {
|
||||
private val META_CHARS = setOf("\\", "+", "*", "?", ".", "(", ")", "|", "[", "]", "^", "$")
|
||||
}
|
||||
override fun toString(): String =
|
||||
// escape 특수 문자를 처리하여 출력
|
||||
when (value) {
|
||||
"\\", "+", "*", "?", ".", "(", ")", "|", "[", "]" -> "\\$value"
|
||||
else -> value // 일반 문자 그대로 반환
|
||||
}
|
||||
if (value in META_CHARS) "\\$value" else value
|
||||
|
||||
override fun findMatch(str: String, position: Int): AvailableState {
|
||||
return when {
|
||||
|
|
Loading…
Add table
Reference in a new issue