Escape a string.
Escape a string.
// In scala repl style scala> import com.github.tkawachi.doctest.StringUtil._ import com.github.tkawachi.doctest.StringUtil._ scala> escapeDoubleQuote("""aaa"bbb\cc"""") res2: String = aaa\"bbb\\cc\" // In Python style >>> escapeDoubleQuote("""aaa"bbb\cc"""") aaa\"bbb\\cc\" // Number of double quotes will be not changed. prop> (s: String) => | escapeDoubleQuote(s).filter(_ == '"').size >= s.filter(_ == '"').size
An original string.
An escaped string.
>>> import StringUtil._ >>> escapeLineSep("Hello,\nWorld") Hello,\nWorld >>> escapeLineSep("Hello,\rWorld") Hello,\rWorld
>>> StringUtil.indent("Hello\nWorld", "[indent]") [indent]Hello [indent]World
prop> (s: String) => s.startsWith(StringUtil.truncate(s).dropRight(4))