
org.http4s.CharsetRange.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4s-core_2.10 Show documentation
Show all versions of http4s-core_2.10 Show documentation
Core http4s library for servers and clients
package org.http4s
import util._
import scalaz.{Show, Order}
sealed abstract class CharsetRange extends HasQValue with Renderable {
def qValue: QValue
def withQValue(q: QValue): CharsetRange
def isSatisfiedBy(charset: Charset): Boolean
}
object CharsetRange extends CharsetRangeInstances {
sealed case class `*`(qValue: QValue) extends CharsetRange {
final override def withQValue(q: QValue): CharsetRange.`*` = copy(qValue = q)
final def isSatisfiedBy(charset: Charset): Boolean = qValue.isAcceptable
final def render(writer: Writer): writer.type = writer << "*" << qValue
}
object `*` extends `*`(QValue.One)
final case class Atom protected[http4s] (charset: Charset, qValue: QValue = QValue.One) extends CharsetRange {
override def withQValue(q: QValue): CharsetRange.Atom = copy(qValue = q)
def isSatisfiedBy(charset: Charset): Boolean = qValue.isAcceptable && this.charset == charset
def render(writer: Writer): writer.type = writer << charset << qValue
}
implicit def fromCharset(cs: Charset): CharsetRange.Atom = cs.toRange
}
trait CharsetRangeInstances {
implicit val CharacterSetOrder: Order[CharsetRange] = Order[QValue].reverseOrder.contramap(_.qValue)
implicit val CharsetShow: Show[Charset] = Show.shows(_.toString)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy