aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/course.ml46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/course.ml b/src/course.ml
index 6109a3e..aede83e 100644
--- a/src/course.ml
+++ b/src/course.ml
@@ -46,32 +46,42 @@ let replace_entities str =
| _ -> None)
|> Stringext.replace_all_assoc str
+type loc_and_sum =
+ | Nothing
+ | Groups
+ | Location of string
+ | Summary of string * string
+
+let loc_and_sum_to_str category = function
+ | Nothing | Groups -> "", category
+ | Location location -> location, category
+ | Summary (location, summary) ->
+ let summary = match Astring.String.cut ~sep:" - " summary with
+ | None -> summary
+ | Some (_, str) -> str in
+ location, summary ^ " (" ^ category ^ ")"
+
let check_groups str =
let group_affixes = ["L1 "; "L2 "; "L3 "; "L3P "; "M1 "; "M2 "; "DEUST ";
"MAG1 "; "1ERE ANNEE "; "2EME ANNEE "; "3EME ANNEE ";
"MAT-Agreg Interne "] in
- List.fold_left
- (fun res affix ->
- res || Astring.String.is_prefix ~affix str) false group_affixes
+ if List.fold_left
+ (fun res affix ->
+ res || Astring.String.is_prefix ~affix str) false group_affixes then
+ Groups
+ else
+ Nothing
let location_and_summary str category =
let sep = "\r\n\r\n<br />\r\n\r\n" in
let parts = Astring.String.cuts ~empty:false ~sep str in
- let _, location, summary =
- List.fold_right
- (fun str -> function
- | false, _, _ -> check_groups str, "", ""
- | true, "", _ -> true, replace_entities str, ""
- | true, summary, "" -> true, replace_entities str, summary
- | true, location, summary -> true, location, summary)
- parts (false, "", "") in
- if summary = "" then
- location, category
- else
- let summary = match Astring.String.cut ~sep:" - " summary with
- | None -> summary
- | Some (_, str) -> str in
- location, summary ^ " (" ^ category ^ ")"
+ List.fold_right (fun str -> function
+ | Nothing -> check_groups str
+ | Groups -> Location (replace_entities str)
+ | Location summary -> Summary (replace_entities str, summary)
+ | Summary _ as res -> res)
+ parts Nothing
+ |> loc_and_sum_to_str category
let date =
let date_format = "%FT%T" in