Repl: refactoring, move common parts to utils
This commit is contained in:
@@ -17,9 +17,35 @@
|
||||
package org.jetbrains.kotlin.cli.common.repl
|
||||
|
||||
import com.google.common.base.Throwables
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.LineSeparator
|
||||
import org.jetbrains.kotlin.utils.repl.ReplEscapeType
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
|
||||
// using '#' to avoid collisions with xml escaping
|
||||
private val SOURCE_CHARS: List<String> = listOf("\n", "#")
|
||||
private val XML_REPLACEMENTS: List<String> = listOf("#n", "#diez")
|
||||
|
||||
private val END_LINE: String = LineSeparator.getSystemLineSeparator().separatorString
|
||||
private const val XML_PREAMBLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
|
||||
fun String.replUnescapeLineBreaks() = StringUtil.replace(this, XML_REPLACEMENTS, SOURCE_CHARS)
|
||||
fun String.replEscapeLineBreaks() = StringUtil.replace(this, SOURCE_CHARS, XML_REPLACEMENTS)
|
||||
|
||||
fun String.replOutputAsXml(escapeType: ReplEscapeType): String {
|
||||
val escapedXml = StringUtil.escapeXml(replEscapeLineBreaks())
|
||||
return "$XML_PREAMBLE<output type=\"$escapeType\">$escapedXml</output>"
|
||||
}
|
||||
|
||||
fun String.replInputAsXml(): String {
|
||||
val escapedXml = StringUtil.escapeXml(replEscapeLineBreaks())
|
||||
return "$XML_PREAMBLE<input>$escapedXml</input>"
|
||||
}
|
||||
|
||||
fun String.replAddLineBreak() = this + END_LINE
|
||||
fun String.replRemoveLineBreaksInTheEnd() = trimEnd(*END_LINE.toCharArray())
|
||||
|
||||
fun makeScriptBaseName(codeLine: ReplCodeLine) =
|
||||
"Line_${codeLine.no}${if (codeLine.generation > REPL_CODE_LINE_FIRST_GEN) "_gen_${codeLine.generation}" else ""}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user