Unified · Split
| @@ -709,6 +709,28 @@ let keys_of_string s = · 708 unmodified lines | ||
| 709 | 709 | List.map (key_of_string (Str.regexp "-")) elems |
| 710 | 710 | ;; |
| 711 | 711 | |
| 712 | +let validatehcs d v = | |
| 713 | + if String.length v > 1 && | |
| 714 | + let module S = Set.Make ( | |
| 715 | + struct type t = char | |
| 716 | + let compare a b = Char.code a - Char.code b | |
| 717 | + end) | |
| 718 | + in | |
| 719 | + let l = String.length v in | |
| 720 | + let rec fold s i = | |
| 721 | + if i = l | |
| 722 | + then true | |
| 723 | + else | |
| 724 | + let e = String.get v i in | |
| 725 | + if S.mem e s | |
| 726 | + then false | |
| 727 | + else fold (S.add e s) (i+1) | |
| 728 | + in | |
| 729 | + fold (S.singleton (String.get v 0)) 1 | |
| 730 | + then v | |
| 731 | + else (Format.eprintf "invalid hint charset %S@." v; d) | |
| 732 | +;; | |
| 733 | + | |
| 712 | 734 | let config_of c attrs = |
| 713 | 735 | let maxv ?(f=int_of_string) u s = max u @@ f s in |
| 714 | 736 | let apply c k v = |
| @@ -803,7 +825,7 @@ let config_of c attrs = · 88 unmodified lines | ||
| 803 | 825 | | "coarse-presentation-positioning" -> |
| 804 | 826 | { c with coarseprespos = bool_of_string v } |
| 805 | 827 | | "use-document-css" -> { c with usedoccss = bool_of_string v } |
| 806 | − | "hint-charset" -> { c with hcs = v } | |
| 828 | + | "hint-charset" -> { c with hcs = validatehcs c.hcs v } | |
| 807 | 829 | | _ -> c |
| 808 | 830 | with exn -> |
| 809 | 831 | dolog "error processing attribute (`%S' = `%S'): %s" k v @@ exntos exn; |
| @@ -2533,24 +2533,7 @@ let enterinfomode = · 2532 unmodified lines | ||
| 2533 | 2533 | (fun v -> conf.hfsize <- bound v 5 100); |
| 2534 | 2534 | src#string "hint chars" |
| 2535 | 2535 | (fun () -> conf.hcs) |
| 2536 | − (fun v -> | |
| 2537 | − if String.length v > 1 && | |
| 2538 | − let module S = | |
| 2539 | − Set.Make (struct type t = char | |
| 2540 | − let compare a b = Char.code a - Char.code b | |
| 2541 | − end) in | |
| 2542 | − let l = String.length v in | |
| 2543 | − let rec fold s i = | |
| 2544 | − if i = l | |
| 2545 | − then true | |
| 2546 | − else | |
| 2547 | − let e = String.get v i in | |
| 2548 | − if S.mem e s | |
| 2549 | − then false | |
| 2550 | − else fold (S.add e s) (i+1) | |
| 2551 | − in | |
| 2552 | − fold (S.singleton (String.get v 0)) 1 | |
| 2553 | − then conf.hcs <- v); | |
| 2536 | + (fun v -> conf.hcs <- Config.validatehcs conf.hcs v); | |
| 2554 | 2537 | src#string "trim fuzz" |
| 2555 | 2538 | (fun () -> irect_to_string conf.trimfuzz) |
| 2556 | 2539 | (fun v -> |
| @@ -28,3 +28,4 @@ · 27 unmodified lines | ||
| 28 | 28 | |
| 29 | 29 | it takes an error in utils making deps dirty and then another... |
| 30 | 30 | (IOW i need to get some sleep before trying to wrap my head around it) |
| 31 | +* TODO hintchars validation should report errors differently (how?) | |