All Downloads are FREE. Search and download functionalities are using the official Maven repository.

toml.Escape.scala Maven / Gradle / Ivy

There is a newer version: 0.3.0-M2
Show newest version
package toml

object Escape {
  def escapeJavaString(str: String): String = {
    val sb = new StringBuilder(str.length())

    var i = 0
    while (i < str.length) {
      val ch = str.charAt(i)
      i += 1

      ch match {
        case '\b' => sb.append("\\b")
        case '\t' => sb.append("\\t")
        case '\n' => sb.append("\\n")
        case '\f' => sb.append("\\f")
        case '\r' => sb.append("\\r")
        case '"' => sb.append("\\\"")
        case '\\' => sb.append("\\\\")
        case c => sb.append(c)
      }
    }

    sb.toString()
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy