package awskit

  1. Overview
  2. Docs

Source file region.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
module Aws_error = Error
open Base
module Format = Stdlib.Format

type t = string

let has_ctl_or_del s =
  String.exists s ~f:(fun c ->
      let code = Char.to_int c in
      code < 0x20 || code = 0x7F)

let of_string region =
  if String.is_empty region then
    Error (Aws_error.validation ~field:"region" "AWS region must be non-empty")
  else if not (String.equal region (String.strip region)) then
    Error
      (Aws_error.validation ~field:"region"
         "AWS region must not have leading/trailing whitespace")
  else if has_ctl_or_del region then
    Error
      (Aws_error.validation ~field:"region"
         "AWS region contains control characters")
  else Ok region

let of_string_exn region =
  match of_string region with
  | Ok region -> region
  | Error error -> invalid_arg (Aws_error.to_string_hum error)

let to_string t = t
let pp formatter t = Format.pp_print_string formatter t
let equal = String.equal