
Dependency-light utilities rendering Java-style escaped strings and characters with configurable quote handling, char-class friendly escapes for [] and -, Unicode/control escape forms, and truncation with suffix.
kotlin-java-escape provides small, dependency-light utilities for rendering strings and characters with Java-style escaping.
It is aimed at code generation, debugging, diagnostics, and any workflow where arbitrary text needs to be shown as a Java-friendly literal instead of raw terminal output.
commonMain.dependencies {
implementation("one.wabbit:kotlin-java-escape:1.0.1")
}import one.wabbit.formatting.escapeJavaString
val input = "Hello,\n\"world\" \\ snowman: \u2603"
val escaped = escapeJavaString(input, doubleQuoted = true)
check(escaped == "Hello,\\n\\\"world\\\" \\\\ snowman: \\u2603")doubleQuoted controls which quote character gets escaped:
true: escape "
false: escape '
import one.wabbit.formatting.escapeJavaChar
check(escapeJavaChar('\n') == "\\n")
check(escapeJavaChar('\\') == "\\\\")
check(escapeJavaChar('\u2603') == "\\u2603")escapeJavaChar also escapes [, ], and -, which makes it convenient for character-class style output and parser/debug tooling.
escapeJavaString can enforce an escaped-content budget before appending a truncation suffix:
import one.wabbit.formatting.escapeJavaString
val escaped = escapeJavaString("line1\nline2", doubleQuoted = true, limit = 6, limitEnding = "...")
check(escaped == "line1...")That matters because a single input character may expand to multiple output characters such as \\n or \\u2603.
The limitEnding suffix is appended after the budget is exhausted and is not counted against
limit.
escapeJavaString preserves letters, digits, and common ASCII punctuationescapeJavaString renders \n, \r, \t, \b, selected quotes, and backslashes with
Java-style escapesescapeJavaString
escapeJavaString become \uXXXX
escapeJavaChar renders \t, \r, \n, and backslash with short escapesescapeJavaChar renders other ISO control characters, including backspace, as \xNN
escapeJavaChar leaves quote characters unchangedThis library is small and stable in scope. It renders Java-style escaped fragments; it does not add surrounding quotes or parse escaped Java input back into text.
Generated API docs can be built locally with Dokka. See API reference notes for the command.
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) for open source use.
For commercial use, contact Wabbit Consulting Corporation at wabbit@wabbit.one.
Before contributions can be merged, contributors need to agree to the repository CLA.
kotlin-java-escape provides small, dependency-light utilities for rendering strings and characters with Java-style escaping.
It is aimed at code generation, debugging, diagnostics, and any workflow where arbitrary text needs to be shown as a Java-friendly literal instead of raw terminal output.
commonMain.dependencies {
implementation("one.wabbit:kotlin-java-escape:1.0.1")
}import one.wabbit.formatting.escapeJavaString
val input = "Hello,\n\"world\" \\ snowman: \u2603"
val escaped = escapeJavaString(input, doubleQuoted = true)
check(escaped == "Hello,\\n\\\"world\\\" \\\\ snowman: \\u2603")doubleQuoted controls which quote character gets escaped:
true: escape "
false: escape '
import one.wabbit.formatting.escapeJavaChar
check(escapeJavaChar('\n') == "\\n")
check(escapeJavaChar('\\') == "\\\\")
check(escapeJavaChar('\u2603') == "\\u2603")escapeJavaChar also escapes [, ], and -, which makes it convenient for character-class style output and parser/debug tooling.
escapeJavaString can enforce an escaped-content budget before appending a truncation suffix:
import one.wabbit.formatting.escapeJavaString
val escaped = escapeJavaString("line1\nline2", doubleQuoted = true, limit = 6, limitEnding = "...")
check(escaped == "line1...")That matters because a single input character may expand to multiple output characters such as \\n or \\u2603.
The limitEnding suffix is appended after the budget is exhausted and is not counted against
limit.
escapeJavaString preserves letters, digits, and common ASCII punctuationescapeJavaString renders \n, \r, \t, \b, selected quotes, and backslashes with
Java-style escapesescapeJavaString
escapeJavaString become \uXXXX
escapeJavaChar renders \t, \r, \n, and backslash with short escapesescapeJavaChar renders other ISO control characters, including backspace, as \xNN
escapeJavaChar leaves quote characters unchangedThis library is small and stable in scope. It renders Java-style escaped fragments; it does not add surrounding quotes or parse escaped Java input back into text.
Generated API docs can be built locally with Dokka. See API reference notes for the command.
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) for open source use.
For commercial use, contact Wabbit Consulting Corporation at wabbit@wabbit.one.
Before contributions can be merged, contributors need to agree to the repository CLA.