Commit 075a171e authored by Stephane Glondu's avatar Stephane Glondu

Change ordering of hashes in pretty_ballots page

parent a519be8a
......@@ -150,4 +150,19 @@ let save_to filename writer x =
Bi_outbuf.flush_channel_writer ob;
close_out oc;;
let b64_order = "+/0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
let compare_b64 a b =
let na = String.length a and nb = String.length b in
let value_of c = try String.index b64_order c with Not_found -> -1 in
let rec loop i =
match (i < na), (i < nb) with
| true, true ->
let diff = value_of a.[i] - value_of b.[i] in
if diff = 0 then loop (i+1) else diff
| true, false -> 1
| false, true -> -1
| false, false -> 0
in loop 0
module SMap = Map.Make(String)
......@@ -53,4 +53,6 @@ val option_map : ('a -> 'b) -> 'a option -> 'b option
val save_to : string -> (Bi_outbuf.t -> 'a -> unit) -> 'a -> unit
val compare_b64 : string -> string -> int
module SMap : Map.S with type key = string
......@@ -1645,9 +1645,7 @@ let pretty_ballots w hashes result () =
let params = W.election.e_params in
let title = params.e_name ^ " — " ^ L.accepted_ballots in
let nballots = ref 0 in
let hashes =
List.sort (fun a b -> String.(compare (uppercase a) (uppercase b))) hashes
in
let hashes = List.sort compare_b64 hashes in
let ballots =
List.map
(fun h ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment