@@ -12,79 +12,60 @@ type windowDescription =
12
12
; instance : int Js.Nullable .t }
13
13
[@@ bs.deriving abstract ]
14
14
15
- type windowDescriptor =
16
- | Title of string
17
- | ClassName of string
18
- | RegexpTitle of string
19
- | RegexpClassName of string
20
- | Last of bool
21
- | Active of bool
22
- | X of int
23
- | Y of int
24
- | W of int
25
- | H of int
26
- | Instance of int
27
-
28
15
let escaped s = s |. Js.String2. replaceByRe [% re " /;/g" ] " ;;"
29
16
30
- let stringOfWindowDescriptor = function
31
- | Title title ->
32
- Some (" TITLE:" ^ escaped title)
33
- | ClassName className ->
34
- Some (" CLASS:" ^ escaped className)
35
- | RegexpTitle regexpTitle ->
36
- Some (" REGEXPTITLE:" ^ escaped regexpTitle)
37
- | RegexpClassName regexpClassName ->
38
- Some (" REGEXPCLASS:" ^ escaped regexpClassName)
39
- | Last last ->
40
- if last then Some " LAST" else None
41
- | Active active ->
42
- if active then Some " ACTIVE" else None
43
- | X x ->
44
- Some (" X:" ^ string_of_int x)
45
- | Y y ->
46
- Some (" Y:" ^ string_of_int y)
47
- | W w ->
48
- Some (" W:" ^ string_of_int w)
49
- | H h ->
50
- Some (" H:" ^ string_of_int h)
51
- | Instance instance ->
52
- Some (" INSTANCE:" ^ string_of_int instance)
17
+ let addStringDescriptor acc key value =
18
+ let value = Js.Nullable. toOption value in
19
+ match value with
20
+ | Some value ->
21
+ ignore @@ Js.Array2. push acc (key ^ " :" ^ escaped value)
22
+ | None ->
23
+ ()
53
24
54
- let optionMap f = function Some x -> Some (f x) | None -> None
25
+ let addIntegerDescriptor acc key value =
26
+ let value = Js.Nullable. toOption value in
27
+ match value with
28
+ | Some value ->
29
+ ignore @@ Js.Array2. push acc (key ^ " :" ^ string_of_int @@ value)
30
+ | None ->
31
+ ()
55
32
56
- let filterSome xs =
57
- xs |. Js.Array2. filter Js.Option. isSome |. Js.Array2. map Js.Option. getExn
33
+ let addBooleanDescriptor acc key value =
34
+ let value = Js.Nullable. toOption value in
35
+ match value with
36
+ | Some true ->
37
+ ignore @@ Js.Array2. push acc key
38
+ | Some false | None ->
39
+ ()
58
40
59
- let splitDescription windowDescription =
60
- [| windowDescription |. titleGet |. Js.Nullable. toOption
61
- |> optionMap (fun title -> Title title)
62
- ; windowDescription |. classNameGet |. Js.Nullable. toOption
63
- |> optionMap (fun className -> ClassName className)
64
- ; windowDescription |. regexpTitleGet |. Js.Nullable. toOption
65
- |> optionMap (fun regexpTitle -> RegexpTitle regexpTitle)
66
- ; windowDescription |. regexpClassNameGet |. Js.Nullable. toOption
67
- |> optionMap (fun regexpClassName -> RegexpClassName regexpClassName)
68
- ; windowDescription |. lastGet |. Js.Nullable. toOption
69
- |> optionMap (fun last -> Last last)
70
- ; windowDescription |. activeGet |. Js.Nullable. toOption
71
- |> optionMap (fun active -> Active active)
72
- ; windowDescription |. xGet |. Js.Nullable. toOption
73
- |> optionMap (fun x -> X x)
74
- ; windowDescription |. yGet |. Js.Nullable. toOption
75
- |> optionMap (fun y -> Y y)
76
- ; windowDescription |. wGet |. Js.Nullable. toOption
77
- |> optionMap (fun w -> W w)
78
- ; windowDescription |. hGet |. Js.Nullable. toOption
79
- |> optionMap (fun h -> H h)
80
- ; windowDescription |. instanceGet |. Js.Nullable. toOption
81
- |> optionMap (fun instance -> Instance instance) |]
82
- |. filterSome
41
+ let descriptorTagged ~title ~className ~regexpTitle ~regexpClassName ~last
42
+ ~active ~x ~y ~w ~h ~instance () =
43
+ let descriptors = [||] in
44
+ addStringDescriptor descriptors " TITLE" title ;
45
+ addStringDescriptor descriptors " CLASS" className ;
46
+ addStringDescriptor descriptors " REGEXPTITLE" regexpTitle ;
47
+ addStringDescriptor descriptors " REGEXPCLASS" regexpClassName ;
48
+ addIntegerDescriptor descriptors " INSTANCE" instance ;
49
+ addBooleanDescriptor descriptors " ACTIVE" active ;
50
+ addBooleanDescriptor descriptors " LAST" last ;
51
+ addIntegerDescriptor descriptors " X" x ;
52
+ addIntegerDescriptor descriptors " Y" y ;
53
+ addIntegerDescriptor descriptors " W" w ;
54
+ addIntegerDescriptor descriptors " H" h ;
55
+ let body = descriptors |. Js.Array2. joinWith " ; " in
56
+ " [" |. Js.String2. concatMany [|body; " ]" |]
83
57
84
58
let descriptor windowDescription =
85
- let descriptors = splitDescription windowDescription in
86
- " ["
87
- ^ ( descriptors
88
- |. Js.Array2. map stringOfWindowDescriptor
89
- |. filterSome |. Js.Array2. joinWith " ; " )
90
- ^ " ]"
59
+ let title = windowDescription |. titleGet in
60
+ let className = windowDescription |. classNameGet in
61
+ let regexpTitle = windowDescription |. regexpTitleGet in
62
+ let regexpClassName = windowDescription |. regexpClassNameGet in
63
+ let instance = windowDescription |. instanceGet in
64
+ let active = windowDescription |. activeGet in
65
+ let last = windowDescription |. lastGet in
66
+ let x = windowDescription |. xGet in
67
+ let y = windowDescription |. yGet in
68
+ let w = windowDescription |. wGet in
69
+ let h = windowDescription |. hGet in
70
+ descriptorTagged ~title ~class Name ~regexp Title ~regexp ClassName ~instance
71
+ ~active ~last ~x ~y ~w ~h ()
0 commit comments