slightly modify is_trailing so we don't use String.starts_with
This commit is contained in:
parent
6e4b1af984
commit
59511905c9
|
@ -21,16 +21,21 @@ type t = {
|
|||
trailing : bool;
|
||||
} [@@deriving show { with_path = false }]
|
||||
|
||||
let is_param_trailing p =
|
||||
String.starts_with p ~prefix:":" || String.contains p ' '
|
||||
let rec is_trailing arg i =
|
||||
if i >= String.length arg then
|
||||
arg = ""
|
||||
else match arg.[i] with
|
||||
| ' ' | '\t' -> true
|
||||
| ':' when i = 0 -> true
|
||||
| _ -> is_trailing arg (i + 1)
|
||||
|
||||
let rec is_params_trailing = function
|
||||
let rec ends_with_trailing = function
|
||||
| [] -> false
|
||||
| [p] -> is_param_trailing p
|
||||
| _ :: tl -> is_params_trailing tl
|
||||
| [p] -> is_trailing p 0
|
||||
| _ :: tl -> ends_with_trailing tl
|
||||
|
||||
let make ?(prefix = No_prefix) ?(always_trailing = false) command params =
|
||||
let trailing = always_trailing || is_params_trailing params in
|
||||
let trailing = always_trailing || ends_with_trailing params in
|
||||
{ prefix; command; params; trailing }
|
||||
|
||||
let write buf t =
|
||||
|
@ -166,6 +171,12 @@ let%expect_test _ =
|
|||
make "NICK" [":)"] |> print_msg_nl;
|
||||
[%expect {| "NICK ::)\r\n" |}];
|
||||
|
||||
make "NICK" ["(:"] |> print_msg_nl;
|
||||
[%expect {| "NICK (:\r\n" |}];
|
||||
|
||||
make "NICK" [""] |> print_msg_nl;
|
||||
[%expect {| "NICK :\r\n" |}];
|
||||
|
||||
make "USER" ["milo"; "0"; "*"; "milo"] ~always_trailing:true |> print_msg_nl;
|
||||
[%expect {| "USER milo 0 * :milo\r\n" |}];
|
||||
|
||||
|
|
Loading…
Reference in New Issue