Lolly 1.4.28
Loading...
Searching...
No Matches
url.hpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : url.hpp
4 * DESCRIPTION: unified resource location handling
5 * COPYRIGHT : (C) 1999 Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#ifndef LOLLY_URL_H
13#define LOLLY_URL_H
14
15#define URL_SYSTEM 0
16#define URL_UNIX 1
17#define URL_STANDARD 2
18#define URL_CLEAN_UNIX 3
19
20#define URL_TUPLE 245
21
23#include "string.hpp"
24
27
28/******************************************************************************
29 * The url data type
30 ******************************************************************************/
31
34 inline url_rep (url_tree t2) : t (t2) {}
35};
36
37class url {
39
40private:
42
43public:
44 url ();
45 url (const char* name);
46 url (string name);
47 url (string dir, string name);
48 inline bool operator== (url u) { return rep->t == u->t; }
49 inline bool operator!= (url u) { return rep->t != u->t; }
50 inline url operator[] (int i) { return url (rep->t[i]); }
51 inline string label () {
52 if (is_atomic (rep->t)) return string ("");
53 else return to_string (rep->t[0]);
54 };
55 string protocol ();
56 friend url as_url (url_tree t);
57};
59
60inline url
62 return url (t);
63}
64
65/******************************************************************************
66 * url subclasses by protocol
67 ******************************************************************************/
68class file_url : public url {
69public:
70 file_url (const char* name);
71 file_url (string name);
72 string concretize ();
73};
74
75class ftp_url : public url {
76public:
77 ftp_url (const char* name);
78 ftp_url (string name);
79};
80
81class blank_url : public url {
82public:
83 blank_url (const char* name);
84 blank_url (string name);
85};
86
87class http_url : public url {
88public:
89 http_url (const char* name);
90 http_url (string name);
91};
92
93class https_url : public url {
94public:
95 https_url (const char* name);
96 https_url (string name);
97};
98
99bool is_root (url u, string s);
100bool is_root_web (url u);
101bool is_root_blank (url u);
102
103bool is_rooted (url u, string protocol);
104bool is_rooted_web (url u);
105bool is_rooted_blank (url u);
106
107/******************************************************************************
108 * url routines by label
109 * + "" (empty string): ., .., ..., /, /tmp
110 * + none: invalid url
111 * + root: the url http://gnu.org yields (concat (root "http") "gnu.org");
112 * + concat: a/b/c is represented as (concat "a" (concat "b" "c"));
113 * + or: the path a:b/c is represented as (or "a" (concat "b" "c"));
114 * + wildcard: (wildcard) corresponds to any url
115 * (wildcard "*.tm") is
116 * - to all strings which end with .tm and (wildcard "*.tm" "file")
117 * - to all TeXmacs files (i.e. discarding directories ending with .tm).
118 ******************************************************************************/
119url url_none ();
120
121inline url
123 return as_url (url_tree ("."));
124}
125
126inline url
128 return as_url (url_tree (".."));
129}
130
131inline url
133 return as_url (url_tree ("..."));
134}
135
136url url_root (string protocol);
137
138url operator* (url u1, url u2); // concatenation of url with rootless url
139url operator* (url u1, const char* name);
140url operator* (url u1, string name);
142inline url
144 return u * url_parent ();
145}
146
147url operator| (url u1, url u2); // disjunction of urls like in file paths
148url url_or (url u1, url u2);
149
151url url_wildcard (string name);
152
153inline bool
155 return u->t == ".";
156};
157inline bool
159 return u->t == "..";
160};
161inline bool
163 return u->t == "...";
164};
165inline bool
167 return u.label () == "none";
168};
169inline bool
171 return u.label () == "root";
172};
173inline bool
175 return u.label () == "concat";
176};
177inline bool
179 return u.label () == "or";
180};
181inline bool
183 return u.label () == "wildcard";
184};
185
186/******************************************************************************
187 * url routines by type
188 ******************************************************************************/
189url url_path (string s, int type= URL_SYSTEM);
190url url_general (string name, int type);
191url url_unix (string name);
192url url_unix (string dir, string name);
193url url_system (string name);
194url url_system (string dir, string name);
195url url_standard (string name);
196url url_standard (string dir, string name);
197
198url url_pwd ();
199
200url url_ramdisc (string contents); // ramdisc with contents contents
201
202/******************************************************************************
203 * operations on urls
204 ******************************************************************************/
205url head (url u); // keep only the directory of the file
206url tail (url u); // keep only the file name without path
207string suffix (url u); // get suffix of file in lower case
208string suffix (url u, bool use_locase); // get suffix of file
209string basename (url u, string suf); // get basename of file with given suffix
210string basename (url u); // get basename of file
211url glue (url u, string s); // glue suffix to url tail
212url unglue (url u, int nr); // remove nr chars from suffix
213url unblank (url u); // a/b/ -> a/b
214url relative (url base, url u); // a/b, c -> a/c
215url delta (url base, url u); // relative (a, delta (a, b)) == b
216string get_root (url u); // get root
217url unroot (url u); // remove root
218url reroot (url u, string s); // reroot using new protocol
219url expand (url u); // rewrite a/{b:c} -> a/b:a/c
220url sort (url u); // order items in ors
221url factor (url u); // inverse of expand; also sorts
222bool descends (url u, url base); // does u descend from base?
223
224/******************************************************************************
225 * predicates
226 ******************************************************************************/
227bool is_atomic (url u);
228bool is_wildcard (url u, int n);
229bool is_pseudo_atomic (url u);
230
231bool is_rooted (url u);
232bool is_name (url u);
233bool is_rooted_name (url u);
234bool is_ramdisc (url u);
235
236void skip_ipv6 (string s, int& i);
237
238/******************************************************************************
239 * conversions
240 ******************************************************************************/
241string as_string (url u, int type= URL_SYSTEM);
243
244inline string
246 return as_string (u, URL_SYSTEM);
247}
248inline string
250 return as_string (u, URL_UNIX);
251}
252inline string
256
257/******************************************************************************
258 * utilities
259 ******************************************************************************/
260url url_get_name (string s, int type= URL_STANDARD, int i= 0);
261
262#endif
blackbox t2
blackbox t[13]
blank_url(const char *name)
Definition blank_url.cpp:18
#define CONCRETE_CODE(PTR)
Macro used to define the implementation of a concrete smart pointer.
Definition classdef.hpp:159
string concretize()
Definition file_url.cpp:22
file_url(const char *name)
Definition file_url.cpp:18
ftp_url(const char *name)
Definition ftp_url.cpp:17
http_url(const char *name)
Definition http_url.cpp:18
https_url(const char *name)
Definition https_url.cpp:18
The list class represents a linked list.
Definition list.hpp:48
Definition url.hpp:37
string label()
Definition url.hpp:51
url()
Definition url.cpp:60
bool operator!=(url u)
Definition url.hpp:49
bool operator==(url u)
Definition url.hpp:48
string protocol()
Definition url.cpp:67
CONCRETE(url)
url operator[](int i)
Definition url.hpp:50
url(url_tree t)
Definition url.hpp:41
friend url as_url(url_tree t)
Definition url.hpp:61
C * tm_new()
Structure representing a concrete object with a reference count.
Definition classdef.hpp:24
base class of resources
Definition resource.hpp:23
url_tree t
Definition url.hpp:33
url_rep(url_tree t2)
Definition url.hpp:34
bool is_root_web(url u)
Definition url.cpp:672
url tail(url u)
Definition url.cpp:370
url url_or(url u1, url u2)
Definition url.cpp:659
url url_none()
Definition url.cpp:91
bool is_atomic(url u)
Definition url.cpp:664
string suffix(url u)
Definition url.cpp:401
bool is_rooted_name(url u)
Definition url.cpp:713
#define URL_STANDARD
Definition url.hpp:17
bool is_parent(url u)
Definition url.hpp:158
url url_system(string name)
Definition url.cpp:306
url url_general(string name, int type)
Definition url.cpp:273
url expand(url u)
Definition url.cpp:512
url url_concat(url u1, url u2)
Definition url.cpp:644
url url_standard(string name)
Definition url.cpp:316
url url_path(string s, int type=URL_SYSTEM)
Definition url.cpp:247
url reroot(url u, string s)
Definition url.cpp:490
url operator*(url u1, url u2)
Definition url.cpp:596
string basename(url u, string suf)
Definition url.cpp:406
url url_ancestor()
Definition url.hpp:132
tm_ostream & operator<<(tm_ostream &out, url u)
Definition url.cpp:806
bool is_or(url u)
Definition url.hpp:178
url operator|(url u1, url u2)
Definition url.cpp:649
bool is_here(url u)
Definition url.hpp:154
url url_root(string protocol)
Definition url.cpp:96
bool is_rooted(url u, string protocol)
Definition url.cpp:692
string as_string(url u, int type=URL_SYSTEM)
Definition url.cpp:729
url head(url u)
Definition url.cpp:365
url relative(url base, url u)
Definition url.cpp:450
bool is_pseudo_atomic(url u)
Definition url.cpp:681
bool descends(url u, url base)
Definition url.cpp:573
url url_here()
Definition url.hpp:122
bool is_ramdisc(url u)
Definition url.cpp:724
#define URL_SYSTEM
Definition url.hpp:15
bool is_none(url u)
Definition url.hpp:166
string as_standard_string(url u)
Definition url.hpp:253
url factor(url u)
Definition url.cpp:568
lolly_tree< int > url_tree
Definition url.hpp:26
bool is_name(url u)
Definition url.cpp:706
bool is_ancestor(url u)
Definition url.hpp:162
url url_ramdisc(string contents)
Definition url.cpp:341
url url_unix(string name)
Definition file_url.cpp:31
url unroot(url u)
Definition url.cpp:482
bool is_wildcard(url u)
Definition url.hpp:182
string as_system_string(url u)
Definition url.hpp:245
string get_root(url u)
Definition url.cpp:477
url delta(url base, url u)
Definition url.cpp:469
url url_parent()
Definition url.hpp:127
url sort(url u)
Definition url.cpp:543
string as_unix_string(url u)
Definition url.hpp:249
#define URL_UNIX
Definition url.hpp:16
url url_wildcard()
Definition url.cpp:101
bool is_rooted_blank(url u)
Definition blank_url.cpp:27
bool is_concat(url u)
Definition url.hpp:174
url unblank(url u)
Definition url.cpp:442
bool is_rooted_web(url u)
Definition url.cpp:700
url unglue(url u, int nr)
Definition url.cpp:431
url as_url(url_tree t)
Definition url.hpp:61
url url_pwd()
Definition url.cpp:326
bool is_root_blank(url u)
Definition blank_url.cpp:22
url glue(url u, string s)
Definition url.cpp:421
void skip_ipv6(string s, int &i)
Definition url.cpp:114
bool is_root(url u, string s)
Definition url.cpp:668
url url_get_name(string s, int type=URL_STANDARD, int i=0)
Definition url.cpp:190