package rpclib

  1. Overview
  2. Docs
A library to deal with RPCs in OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

rpclib-10.2.0.tbz
sha256=37ec4a4dd53fcb2d38d846415d3a45976d5a78c1531e6d876db2436e947172f3
sha512=4757df16d7cf2220787e2a6532e47130049894741ae1635e017cd583f28c5e55c016768d992c6739da70b29283141070f974f246b1ef467e64b034c5c231b00a

doc/src/rpclib.internals/internals.ml.html

Source file internals.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
(** Encodes a string using the given translation function that maps a character
    to a string that is its encoded version, if that character needs encoding. *)
let encode translate s =
  let n = String.length s in
  let need_encoding =
    let b = ref false in
    let i = ref 0 in
    while (not !b) && !i < n do
      b := translate s.[!i] <> None;
      incr i
    done;
    !b
  in
  if need_encoding
  then (
    let buf = Buffer.create 0 in
    let m = ref 0 in
    for i = 0 to n - 1 do
      match translate s.[i] with
      | None -> ()
      | Some n ->
        Buffer.add_substring buf s !m (i - !m);
        Buffer.add_string buf n;
        m := i + 1
    done;
    Buffer.add_substring buf s !m (n - !m);
    Buffer.contents buf)
  else s