package lsp
LSP protocol implementation in OCaml
Install
Dune Dependency
Authors
Maintainers
Sources
jsonrpc-1.3.0.tbz
sha256=598e27258e4749b6e2511e2c5efe00d16f0965806296e808d202cd614d655fba
sha512=febe80f8a88fac7683cafbd045dceee4869beda1f250b78a1d94d3ad19e746388d24869e805abcb2f33f93687508d65db19a38424c1059670915c050b4f6dbb9
doc/src/lsp.stdune/escape.ml.html
Source file escape.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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
module String = StringLabels type quote = | Needs_quoting_with_length of int | No_quoting let quote_length s = let n = ref 0 in let len = String.length s in let needs_quoting = ref false in for i = 0 to len - 1 do n := !n + match String.unsafe_get s i with | '\"' | '\\' | '\n' | '\t' | '\r' | '\b' -> needs_quoting := true; 2 | ' ' -> needs_quoting := true; 1 | '!' .. '~' -> 1 | _ -> needs_quoting := true; 4 done; if !needs_quoting then Needs_quoting_with_length len else ( assert (len = !n); No_quoting ) let escape_to s ~dst:s' ~ofs = let n = ref ofs in let len = String.length s in for i = 0 to len - 1 do ( match String.unsafe_get s i with | ('\"' | '\\') as c -> Bytes.unsafe_set s' !n '\\'; incr n; Bytes.unsafe_set s' !n c | '\n' -> Bytes.unsafe_set s' !n '\\'; incr n; Bytes.unsafe_set s' !n 'n' | '\t' -> Bytes.unsafe_set s' !n '\\'; incr n; Bytes.unsafe_set s' !n 't' | '\r' -> Bytes.unsafe_set s' !n '\\'; incr n; Bytes.unsafe_set s' !n 'r' | '\b' -> Bytes.unsafe_set s' !n '\\'; incr n; Bytes.unsafe_set s' !n 'b' | ' ' .. '~' as c -> Bytes.unsafe_set s' !n c | c -> let a = Char.code c in Bytes.unsafe_set s' !n '\\'; incr n; Bytes.unsafe_set s' !n (Char.unsafe_chr (48 + (a / 100))); incr n; Bytes.unsafe_set s' !n (Char.unsafe_chr (48 + (a / 10 mod 10))); incr n; Bytes.unsafe_set s' !n (Char.unsafe_chr (48 + (a mod 10))) ); incr n done (* Surround [s] with quotes, escaping it if necessary. *) let quote_if_needed s = let len = String.length s in match quote_length s with | No_quoting -> if s = "" then "\"\"" else s | Needs_quoting_with_length n -> let s' = Bytes.create (n + 2) in Bytes.unsafe_set s' 0 '"'; if len = 0 || n > len then escape_to s ~dst:s' ~ofs:1 else Bytes.blit_string ~src:s ~src_pos:0 ~dst:s' ~dst_pos:1 ~len; Bytes.unsafe_set s' (n + 1) '"'; Bytes.unsafe_to_string s'
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>