diff options
Diffstat (limited to 'src/State.ml')
-rw-r--r-- | src/State.ml | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/State.ml b/src/State.ml index 59391d2..4c6cedb 100644 --- a/src/State.ml +++ b/src/State.ml @@ -17,7 +17,7 @@ let last_added state = else None -(* Serialization *) +(* URL Serialization *) let sep = "|" @@ -30,13 +30,13 @@ let marker_to_string marker = |] |> Js.Array.joinWith sep -let to_string state = +let to_url_string state = state |> Js.Array.map marker_to_string |> Js.Array.joinWith sep |> String.encode -let from_string str = +let from_url_string str = let (_, _, res) = Js.Array.reduce (fun (acc_str, acc_marker, acc_state) c -> let length = Js.Array.length acc_marker in @@ -60,6 +60,23 @@ let from_string str = (Js.Array.from (Js.String.castToArrayLike ((String.decode str) ^ sep))) in res +(* CSV Serialization *) + +let to_csv_line marker = + [| Js.Float.toString marker.pos.lat + ; Js.Float.toString marker.pos.lng + ; marker.name + ; marker.color + ; marker.icon + |] + |> Js.Array.joinWith "," + +let to_csv_string state = + state + |> Js.Array.map to_csv_line + |> Fun.flip Js.Array.concat [| "lat,lng,name,color,icon" |] + |> Js.Array.joinWith "\n" + (* Colors *) let colors = |