File: cloc.ml

package info (click to toggle)
pcre-ocaml 7.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 324 kB
  • sloc: ml: 1,445; ansic: 631; makefile: 38
file content (19 lines) | stat: -rw-r--r-- 520 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
open Pcre

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