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;
|
trailing : bool;
|
||||||
} [@@deriving show { with_path = false }]
|
} [@@deriving show { with_path = false }]
|
||||||
|
|
||||||
let is_param_trailing p =
|
let rec is_trailing arg i =
|
||||||
String.starts_with p ~prefix:":" || String.contains p ' '
|
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
|
| [] -> false
|
||||||
| [p] -> is_param_trailing p
|
| [p] -> is_trailing p 0
|
||||||
| _ :: tl -> is_params_trailing tl
|
| _ :: tl -> ends_with_trailing tl
|
||||||
|
|
||||||
let make ?(prefix = No_prefix) ?(always_trailing = false) command params =
|
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 }
|
{ prefix; command; params; trailing }
|
||||||
|
|
||||||
let write buf t =
|
let write buf t =
|
||||||
|
@ -166,6 +171,12 @@ let%expect_test _ =
|
||||||
make "NICK" [":)"] |> print_msg_nl;
|
make "NICK" [":)"] |> print_msg_nl;
|
||||||
[%expect {| "NICK ::)\r\n" |}];
|
[%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;
|
make "USER" ["milo"; "0"; "*"; "milo"] ~always_trailing:true |> print_msg_nl;
|
||||||
[%expect {| "USER milo 0 * :milo\r\n" |}];
|
[%expect {| "USER milo 0 * :milo\r\n" |}];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue