package b0

  1. Overview
  2. Docs
Software construction and deployment kit

Install

dune-project
 Dependency

Authors

Maintainers

Sources

b0-0.0.6.tbz
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0

doc/src/b0.std/b0__char.ml.html

Source file b0__char.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
(*---------------------------------------------------------------------------
   Copyright (c) 2025 The more programmers. All rights reserved.
   SPDX-License-Identifier: ISC
  ---------------------------------------------------------------------------*)

include Char

module Ascii = struct

  (* Characters *)

  let min = '\x00'
  let max = '\x7F'

  (* Predicates *)

  let is_valid = function '\x00' .. '\x7F' -> true | _ -> false
  let is_upper = function 'A' .. 'Z' -> true | _ -> false
  let is_lower = function 'a' .. 'z' -> true | _ -> false
  let is_letter = function 'A' .. 'Z' | 'a' .. 'z' -> true | _ -> false
  let is_alphanum = function
    | '0' .. '9' | 'A' .. 'Z' | 'a' .. 'z' -> true | _ -> false

  let is_white = function ' ' | '\t' .. '\r'  -> true | _ -> false
  let is_blank = function ' ' | '\t' -> true | _ -> false
  let is_graphic = function '!' .. '~' -> true | _ -> false
  let is_print = function ' ' .. '~' -> true | _ -> false
  let is_control = function '\x00' .. '\x1F' | '\x7F' -> true | _ -> false

  (* Decimal digits *)

  let is_digit = function '0' .. '9' -> true | _ -> false
  let digit_to_int = function
    | '0' .. '9' as c -> code c - 0x30
    | c -> invalid_arg (escaped c ^ ": not a decimal digit")

  let digit_of_int n = unsafe_chr (0x30 + abs (n mod 10))

  (* Hexadecimal digits *)

  let is_hex_digit = function
    | '0' .. '9' | 'A' .. 'F' | 'a' .. 'f' -> true
    | _ -> false

  let hex_digit_to_int = function
    | '0' .. '9' as c -> code c - 0x30
    | 'A' .. 'F' as c -> 10 + code c - 0x41
    | 'a' .. 'f' as c -> 10 + code c - 0x61
    | c -> invalid_arg (escaped c ^ ": not a hexadecimal digit")

  let lower_hex_digit_of_int n =
    let d = abs (n mod 16) in
    unsafe_chr (if d < 10 then 0x30 + d else 0x57 + d)

  let upper_hex_digit_of_int n =
    let d = abs (n mod 16) in
    unsafe_chr (if d < 10 then 0x30 + d else 0x37 + d)

  (* Casing transforms *)

  let lowercase = lowercase_ascii
  let uppercase = uppercase_ascii
end