Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
(and
:with-test
(>= 1.10.0)))
uucp
; tools/data-packer
ppx_deriving_yaml
ppx_import
Expand Down
1 change: 1 addition & 0 deletions ocamlorg.opam
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ depends: [
"ounit"
"alcotest" {with-test}
"mdx" {with-test & >= "1.10.0"}
"uucp"
"ppx_deriving_yaml"
"ppx_import"
"ppx_stable"
Expand Down
3 changes: 2 additions & 1 deletion src/global/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(library
(name ocamlorg)
(public_name ocamlorg.global))
(public_name ocamlorg.global)
(libraries uucp))
18 changes: 17 additions & 1 deletion src/global/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,24 @@ module String = struct
false
with Exit -> true

let case_fold s =
let buf = Buffer.create (length s * 2) in
let rec loop i max =
if i > max then Buffer.contents buf
else
let dec = get_utf_8_uchar s i in
let u = Uchar.utf_decode_uchar dec in
(match Uucp.Case.Fold.fold u with
| `Self -> Buffer.add_utf_8_uchar buf u
| `Uchars us -> List.iter (Buffer.add_utf_8_uchar buf) us);
loop (i + Uchar.utf_decode_length dec) max
in
loop 0 (length s - 1)

let caseless_equal a b = case_fold a = case_fold b

let is_sub_ignore_case pattern text =
contains_s (lowercase_ascii text) (lowercase_ascii pattern)
contains_s (case_fold text) (case_fold pattern)

(* ripped off stringext, itself ripping it off from one of dbuenzli's libs *)
let cut s ~on =
Expand Down
4 changes: 2 additions & 2 deletions src/ocamlorg_data/data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module Opam_user = struct
{ name; email; github_username; avatar }

let find_by_name s =
let pattern = String.lowercase_ascii s in
let pattern = Ocamlorg.Import.String.case_fold s in
let contains s1 s2 =
try
let len = String.length s2 in
Expand All @@ -236,7 +236,7 @@ module Opam_user = struct
in
all
|> List.find_opt (fun { name; _ } ->
contains pattern (String.lowercase_ascii name))
contains pattern (Ocamlorg.Import.String.case_fold name))
end

module Outreachy = struct
Expand Down
3 changes: 3 additions & 0 deletions src/ocamlorg_package/lib/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module String = struct
done;
false
with Exit -> true

let case_fold = Ocamlorg.Import.String.case_fold
let caseless_equal = Ocamlorg.Import.String.caseless_equal
end

module List = struct
Expand Down
4 changes: 2 additions & 2 deletions src/ocamlorg_package/lib/ocamlorg_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ end = struct
Re.compile atom

let to_request str =
let str = String.lowercase_ascii str in
let str = String.case_fold str in
let to_constraint = function
| [ _; s ] -> Any s
| [ _; "tag:"; s ] -> Tag s
Expand All @@ -329,7 +329,7 @@ end = struct
|> to_constraint)
g

let match_ f s pattern = f (String.lowercase_ascii @@ s) pattern
let match_ f s pattern = f (String.case_fold @@ s) pattern

let match_tag ?(f = String.contains_s) pattern package =
List.exists (fun tag -> match_ f tag pattern) package.info.tags
Expand Down
4 changes: 2 additions & 2 deletions src/ocamlorg_web/lib/handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ let academic_institutions req =
let resource_type = Dream.query req "resource_type" in
let search_user pattern t =
let open Data.Academic_institution in
let pattern = String.lowercase_ascii pattern in
let name_is_s { name; _ } = String.lowercase_ascii name = pattern in
let pattern = String.case_fold pattern in
let name_is_s { name; _ } = String.case_fold name = pattern in
let name_contains_s { name; _ } = String.is_sub_ignore_case pattern name in
let score user =
if name_is_s user then -1
Expand Down
4 changes: 3 additions & 1 deletion tool/data-packer/lib/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ module String = struct
with Exit -> true

let is_sub_ignore_case pattern text =
contains_s (lowercase_ascii text) (lowercase_ascii pattern)
contains_s
(Ocamlorg.Import.String.case_fold text)
(Ocamlorg.Import.String.case_fold pattern)

(* ripped off stringext, itself ripping it off from one of dbuenzli's libs *)
let cut s ~on =
Expand Down
6 changes: 3 additions & 3 deletions tool/data-scrape/lib/platform_release_scraper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ let group_releases_by_project all =
SMap.empty all

let is_prerelease github_tag =
let tag = String.lowercase_ascii github_tag in
let tag = Ocamlorg.Import.String.case_fold github_tag in
let has pattern =
try
let _ = Str.search_forward (Str.regexp pattern) tag 0 in
Expand All @@ -182,13 +182,13 @@ let is_prerelease github_tag =
has "alpha" || has "beta" || has "rc[0-9]" || has "preview"

let tag_matches_ignore_patterns ignore_patterns github_tag =
let tag = String.lowercase_ascii github_tag in
let tag = Ocamlorg.Import.String.case_fold github_tag in
List.exists
(fun pattern ->
try
let _ =
Str.search_forward
(Str.regexp_string (String.lowercase_ascii pattern))
(Str.regexp_string (Ocamlorg.Import.String.case_fold pattern))
tag 0
in
true
Expand Down