package gettext

  1. Overview
  2. Docs

Source file gettextCategory.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(**************************************************************************)
(*  ocaml-gettext: a library to translate messages                        *)
(*                                                                        *)
(*  Copyright (C) 2003-2008 Sylvain Le Gall <sylvain@le-gall.net>         *)
(*                                                                        *)
(*  This library is free software; you can redistribute it and/or         *)
(*  modify it under the terms of the GNU Lesser General Public            *)
(*  License as published by the Free Software Foundation; either          *)
(*  version 2.1 of the License, or (at your option) any later version;    *)
(*  with the OCaml static compilation exception.                          *)
(*                                                                        *)
(*  This library is distributed in the hope that it will be useful,       *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *)
(*  Lesser General Public License for more details.                       *)
(*                                                                        *)
(*  You should have received a copy of the GNU Lesser General Public      *)
(*  License along with this library; if not, write to the Free Software   *)
(*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307   *)
(*  USA                                                                   *)
(**************************************************************************)

(** Functions to manipulate category.
    @author Sylvain Le Gall *)

type category =
  | LC_CTYPE
  | LC_NUMERIC
  | LC_TIME
  | LC_COLLATE
  | LC_MONETARY
  | LC_MESSAGES
  | LC_ALL

let string_of_category cat =
  match cat with
  | LC_CTYPE -> "LC_CTYPE"
  | LC_NUMERIC -> "LC_NUMERIC"
  | LC_TIME -> "LC_TIME"
  | LC_COLLATE -> "LC_COLLATE"
  | LC_MONETARY -> "LC_MONETARY"
  | LC_MESSAGES -> "LC_MESSAGES"
  | LC_ALL -> "LC_ALL"

let category_of_string str =
  match str with
  | "LC_CTYPE" -> LC_CTYPE
  | "LC_NUMERIC" -> LC_NUMERIC
  | "LC_TIME" -> LC_TIME
  | "LC_COLLATE" -> LC_COLLATE
  | "LC_MONETARY" -> LC_MONETARY
  | "LC_MESSAGES" -> LC_MESSAGES
  | "LC_ALL" -> LC_ALL
  | _ -> raise (Invalid_argument "category_of_string")

let categories =
  [
    LC_CTYPE; LC_NUMERIC; LC_TIME; LC_COLLATE; LC_MONETARY; LC_MESSAGES; LC_ALL;
  ]

let compare c1 c2 =
  let val_category x =
    match x with
    | LC_CTYPE -> 0
    | LC_NUMERIC -> 1
    | LC_TIME -> 2
    | LC_COLLATE -> 3
    | LC_MONETARY -> 4
    | LC_MESSAGES -> 5
    | LC_ALL -> 6
  in
  compare (val_category c1) (val_category c2)

module MapCategory = Map.Make (struct
  type t = category

  let compare = compare
end)
OCaml

Innovation. Community. Security.