refactor: optimize CharItem to handle special characters in toString method

This commit is contained in:
monoid 2025-06-29 16:21:51 +09:00
parent 4f7cfae72d
commit c7926c1f4d

View file

@ -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 {