| 1 |
abate |
907 |
type url = Filename of string | Url of string
|
| 2 |
|
|
|
| 3 |
abate |
1228 |
let start_with s p =
|
| 4 |
|
|
let l = String.length p in
|
| 5 |
|
|
let n = String.length s in
|
| 6 |
|
|
if (n >= l) && (String.sub s 0 l = p)
|
| 7 |
|
|
then Some (String.sub s l (n - l))
|
| 8 |
|
|
else None
|
| 9 |
|
|
|
| 10 |
abate |
907 |
let is_url s =
|
| 11 |
|
|
try let _ = Neturl.extract_url_scheme s in true
|
| 12 |
|
|
with Neturl.Malformed_URL -> false
|
| 13 |
|
|
|
| 14 |
abate |
1187 |
let no_load_url s =
|
| 15 |
|
|
let msg =
|
| 16 |
|
|
Printf.sprintf
|
| 17 |
|
|
"Error \"%s\": \nTo fetch external URLs, you need to compile CDuce with curl and/or netclient" s
|
| 18 |
|
|
in
|
| 19 |
|
|
raise (Location.Generic msg)
|
| 20 |
abate |
907 |
|
| 21 |
abate |
1187 |
let load_url = ref no_load_url
|
| 22 |
|
|
|
| 23 |
abate |
907 |
let process s =
|
| 24 |
abate |
1228 |
match start_with s "string://" with
|
| 25 |
|
|
| None ->
|
| 26 |
|
|
if is_url s then Url (!load_url s)
|
| 27 |
|
|
else Filename s
|
| 28 |
|
|
| Some s ->
|
| 29 |
|
|
Url s
|