File: cloc.ml

package info (click to toggle)
pcre2-ocaml 8.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 356 kB
  • sloc: ml: 2,435; ansic: 562; makefile: 34
file content (19 lines) | stat: -rw-r--r-- 521 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
open Pcre2

let read_whole_channel ch =
  let size = 4096 in
  let strbuf = Bytes.create size in
  let buf = Buffer.create 65536 in
  let len = ref size in
  while !len <> 0 do
    len := input ch strbuf 0 size;
    Buffer.add_subbytes buf strbuf 0 !len
  done;
  Buffer.contents buf

let () =
  let str = read_whole_channel stdin in
  let str = qreplace ~pat:"/\\*(.|\n)*?\\*/" str in
  let str = qreplace_first ~pat:"^(\n|\\s)+" str in
  let str = qreplace ~pat:"\n+((\n|\\s)\n)*" ~templ:"\n" str in
  print_string str