-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitter.ml
92 lines (79 loc) · 2.25 KB
/
splitter.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
(* Convert .NET XML Comments file to plain text. *)
open Soup
let soup = read_file "bin/Debug/net5.0/dotnet-libcpdf.xml" |> parse
let body_contents = soup $$ "member"
let explode s =
let l = ref [] in
for p = String.length s downto 1 do
l := String.unsafe_get s (p - 1)::!l
done;
!l
let implode l =
let s = Bytes.create (List.length l) in
let rec list_loop x = function
[] -> ()
| i::t -> Bytes.unsafe_set s x i; list_loop (x + 1) t
in
list_loop 0 l;
Bytes.to_string s
let rec dropwhile p = function
| [] -> []
| h::t -> if p h then dropwhile p t else (h::t)
let string_replace_all x x' s =
if x = "" then s else
let p = ref 0
and slen = String.length s
and xlen = String.length x in
let output = Buffer.create (slen * 2) in
while !p < slen do
try
if String.sub s !p xlen = x
then (Buffer.add_string output x'; p := !p + xlen)
else (Buffer.add_char output s.[!p]; incr p)
with
_ -> Buffer.add_char output s.[!p]; incr p
done;
Buffer.contents output
let replacements =
[("CoherentGraphics.", "");
("F:", "");
("T:", "");
("M:", "");
("System.Collections.Generic.", "");
("System.", "")]
(* Simple search and replace *)
let replace s =
let s = ref s in
List.iter
(fun (f, t) -> s := string_replace_all f t !s)
replacements;
!s
(* Add spaces after commas *)
let rec bulk_comments = function
| ','::x::t when x <> ' ' -> ','::' '::x::bulk_comments t
| h::t -> h::bulk_comments t
| [] -> []
(* Remove spaces at begining of lines *)
let rec remove_spaces = function
| '\n'::t -> '\n'::remove_spaces (dropwhile (( = ) ' ') t)
| h::t -> h::remove_spaces t
| [] -> []
let process s =
let s = replace s in
let s = explode s in
let s = bulk_comments s in
let s = remove_spaces s in
implode s
let b = Buffer.create 4096
let () =
iter
(fun node ->
match element node with
e ->
Buffer.add_string b
(Printf.sprintf "%s\n\n%s\n\n"
(R.attribute "name" node)
(match leaf_text (node $ "summary") with Some s -> s | None -> ""))
)
body_contents;
print_string (process (Buffer.contents b))