···82828383(** Unicode case folding for case-insensitive comparison.
84848585- Uses the Uucp library for proper Unicode case folding, which handles
8686- special cases like Turkish dotted-I (U+0130 -> 'i' + U+0307) correctly. *)
8585+ WORKAROUND: This is a temporary domain-specific implementation because
8686+ the uucp library fails to compile with wasm_of_ocaml due to "too many
8787+ locals" errors. Once uucp supports WASM, restore the proper implementation:
8888+8989+ {[
9090+ (* Proper uucp-based case folding: *)
9191+ let case_fold s =
9292+ let buf = Buffer.create (String.length s) in
9393+ let add_uchar u = Uutf.Buffer.add_utf_8 buf u in
9494+ let fold_char () _pos = function
9595+ | `Malformed _ -> ()
9696+ | `Uchar u ->
9797+ match Uucp.Case.Fold.fold u with
9898+ | `Self -> add_uchar u
9999+ | `Uchars us -> List.iter add_uchar us
100100+ in
101101+ Uutf.String.fold_utf_8 fold_char () s;
102102+ Buffer.contents buf
103103+ ]}
104104+105105+ This workaround handles the Turkish dotted-I (U+0130 -> 'i' + U+0307)
106106+ which is the main non-ASCII case relevant for CSS media query identifiers. *)
87107let case_fold s =
88108 let buf = Buffer.create (String.length s) in
8989- let add_uchar u = Uutf.Buffer.add_utf_8 buf u in
9090- let fold_char () _pos = function
9191- | `Malformed _ -> () (* Skip malformed sequences *)
9292- | `Uchar u ->
9393- match Uucp.Case.Fold.fold u with
9494- | `Self -> add_uchar u
9595- | `Uchars us -> List.iter add_uchar us
9696- in
9797- Uutf.String.fold_utf_8 fold_char () s;
109109+ let len = String.length s in
110110+ let i = ref 0 in
111111+ while !i < len do
112112+ let c = s.[!i] in
113113+ (* U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE encoded as UTF-8: 0xC4 0xB0 *)
114114+ if c = '\xc4' && !i + 1 < len && s.[!i + 1] = '\xb0' then begin
115115+ (* Case fold to 'i' + U+0307 (combining dot above) = 0x69 0xCC 0x87 *)
116116+ Buffer.add_string buf "i\xcc\x87";
117117+ i := !i + 2
118118+ end else begin
119119+ Buffer.add_char buf (Char.lowercase_ascii c);
120120+ incr i
121121+ end
122122+ done;
98123 Buffer.contents buf
99124100125(** Check balanced parentheses *)