in
patch_include (patch_import line)
-let patch_entity ?(via_http = true) () =
- if via_http then
- fun line ->
- List.fold_left
- (fun url s ->
- Pcre.replace
- ~pat:(sprintf "ENTITY (.*) SYSTEM\\s+\"(%s/)?" url)
- ~templ:(sprintf "ENTITY $1 SYSTEM \"%s/getdtd?uri="
- (Lazy.force Http_getter_env.my_own_url))
- s)
- line
- (Lazy.force Http_getter_env.dtd_base_urls)
- else
- fun line ->
- List.fold_left
- (fun url s ->
- Pcre.replace
- ~pat:(sprintf "ENTITY (.*) SYSTEM\\s+\"(%s/)?" url)
- ~templ:(sprintf "ENTITY $1 SYSTEM \"file://%s/"
- (Lazy.force Http_getter_env.dtd_dir))
- s)
- line
- (Lazy.force Http_getter_env.dtd_base_urls)
+let patch_system kind ?(via_http = true) () =
+ let rex =
+ Pcre.regexp (sprintf "%s (.*) SYSTEM\\s+\"((%s)/)?" kind
+ (String.concat "|" (Lazy.force Http_getter_env.dtd_base_urls)))
+ in
+ let templ =
+ if via_http then
+ sprintf "%s $1 SYSTEM \"%s/getdtd?uri=" kind
+ (Lazy.force Http_getter_env.my_own_url)
+ else
+ sprintf "%s $1 SYSTEM \"file://%s/" kind
+ (Lazy.force Http_getter_env.dtd_dir)
+ in
+ fun line -> Pcre.replace ~rex ~templ line
-let patch_doctype ?(via_http = true) () =
- if via_http then
- fun line ->
- List.fold_left
- (fun url s ->
- Pcre.replace
- ~pat:(sprintf "DOCTYPE (.*) SYSTEM\\s+\"%s/" url)
- ~templ:(sprintf "DOCTYPE $1 SYSTEM \"%s/getdtd?uri="
- (Lazy.force Http_getter_env.my_own_url))
- s)
- line
- (Lazy.force Http_getter_env.dtd_base_urls)
- else
- fun line ->
- List.fold_left
- (fun url s ->
- Pcre.replace
- ~pat:(sprintf "DOCTYPE (.*) SYSTEM\\s+\"%s/" url)
- ~templ:(sprintf "DOCTYPE $1 SYSTEM \"file://%s/"
- (Lazy.force Http_getter_env.my_own_url))
- s)
- line
- (Lazy.force Http_getter_env.dtd_base_urls)
+let patch_entity = patch_system "ENTITY"
+let patch_doctype = patch_system "DOCTYPE"
let patch_dtd = patch_entity
-
let patch_xml ?via_http () line =
patch_doctype ?via_http () (patch_entity ?via_http () line)