package ldp

  1. Overview
  2. Docs

Simple content-type parsing/printing. Tries to implement RFC 2045.

Base types

type token = string

Non-empty string containing only ascii CHAR except SPACE, CTLs, or tspecials as defined here.

type ty =
  1. | Application
  2. | Audio
  3. | Ietf of token
  4. | Image
  5. | Message
  6. | Multipart
  7. | Text
  8. | Video
  9. | X of token
type subty = token
type value =
  1. | T of token
  2. | Quoted of string
type parameter = token * value
type error = string * Lexing.position
val string_of_error : error -> string

Content-types

type t = {
  1. ty : ty;
  2. subty : subty;
  3. parameters : parameter list;
}
val create : ?parameters:parameter list -> ty -> subty -> t

create ?paramers ty subty creates a new content-type.

val default : t

Default content-type is text/plain with charset parameter set to "us-ascii".

val of_string : string -> (t, error) result
val to_string : t -> string
val value : token -> t -> string option

value p t returns value associated to parameter p in t, if any.

val value_def : token -> string -> t -> string

value p def t returns value associated to p in t, or def if there is no parameter p in t.

val charset : t -> string option

Same as value but for parameter "charset".

val charset_def : string -> t -> string

Same as value_def but for paramter "charset".

Mime-types

type mime = ty * subty
val to_mime : t -> mime
val of_mime : mime -> t
val mime_to_string : mime -> string
val mime_of_string : string -> (mime, error) result
val has_mime : t -> mime -> bool

has_mime ct mime returns true is type and subtype of mime are the same as in ct, else false.

Predefined content-types

val ct_turtle : t

text/turtle

val ct_xmlrdf : t

application/rdf+xml

val ct_sparql_update : t

application/sparql-update

val ct_text : t

text/plain

val ct_xhtml : t

application/xhtml+xml

Predefined mime-types

val mime_turtle : mime

text/turtle

val mime_xmlrdf : mime

application/rdf+xml

val mime_sparql_update : mime

application/sparql-update

val mime_text : mime

text/plain

val mime_xhtml : mime

application/xhtml+xml

OCaml

Innovation. Community. Security.