Drop Batteries dependency

This commit is contained in:
Stavros Polymenis 2017-11-06 23:10:03 +00:00
parent 328e6da91e
commit f79803cdfd
2 changed files with 11 additions and 11 deletions

View File

@ -14,7 +14,6 @@ depends: [
"uuidm"
"omd"
"opium"
"batteries"
"lwt"
"ptime"
"re"

View File

@ -88,16 +88,17 @@ let string_alias t =
let is_reserved = function
| '!' | '*' | '\'' | '(' | ')' | ';' | ':' | '@' | '&' | '=' | '+' | '$'
| ',' | '/' | '?' | '#' | '[' | ']' | ' ' | '\t' | '\x00' -> true
| _ -> false in
let drop h t = t in
let dash h t = '-' :: t in
let rec filter fn = function
| [] -> []
| head :: tail ->
if is_reserved head
then fn head (filter drop tail)
else Char.lowercase_ascii head :: (filter dash tail) in
Batteries.String.of_list @@ filter drop (Batteries.String.to_list t)
| _ -> false
in
let b = Buffer.create (String.length t) in
let filter char =
let open Buffer in
if is_reserved char
then (try (if nth b (pred (length b)) <> '-' then add_char b '-') with Invalid_argument _ -> prerr_endline "reserved")
else add_char b char
in
String.iter filter t;
Buffer.contents b
type t = {
title: string;