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

io.lemonlabs.uri.encoding.UriEncoder.scala Maven / Gradle / Ivy

There is a newer version: 4.0.3
Show newest version
package io.lemonlabs.uri.encoding

trait UriEncoder extends Product with Serializable {
  def shouldEncode(ch: Char): Boolean
  def encodeChar(ch: Char): String

  def encode(s: String, charset: String) = {
    val chars = s.getBytes(charset).map(_.toChar)

    val encChars = chars.flatMap(ch => {
      if (shouldEncode(ch)) {
        encodeChar(ch).getBytes(charset)
      } else {
        Array(ch.toByte)
      }
    })

    new String(encChars, charset)
  }

  def +(other: UriEncoder) = ChainedUriEncoder(other :: this :: Nil)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy