Lolly 1.4.28
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
url.hpp File Reference
#include "lolly/data/lolly_tree.hpp"
#include "string.hpp"
Include dependency graph for url.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  url_rep
 
class  url
 
class  file_url
 
class  ftp_url
 
class  blank_url
 
class  http_url
 
class  https_url
 

Macros

#define URL_SYSTEM   0
 
#define URL_UNIX   1
 
#define URL_STANDARD   2
 
#define URL_CLEAN_UNIX   3
 
#define URL_TUPLE   245
 

Typedefs

typedef lolly_tree< int > url_tree
 

Functions

 CONCRETE_CODE (url)
 
url as_url (url_tree t)
 
bool is_root (url u, string s)
 
bool is_root_web (url u)
 
bool is_root_blank (url u)
 
bool is_rooted (url u, string protocol)
 
bool is_rooted_web (url u)
 
bool is_rooted_blank (url u)
 
url url_none ()
 
url url_here ()
 
url url_parent ()
 
url url_ancestor ()
 
url url_root (string protocol)
 
url operator* (url u1, url u2)
 
url operator* (url u1, const char *name)
 
url operator* (url u1, string name)
 
url url_concat (url u1, url u2)
 
url url_parent (url u)
 
url operator| (url u1, url u2)
 
url url_or (url u1, url u2)
 
url url_wildcard ()
 
url url_wildcard (string name)
 
bool is_here (url u)
 
bool is_parent (url u)
 
bool is_ancestor (url u)
 
bool is_none (url u)
 
bool is_root (url u)
 
bool is_concat (url u)
 
bool is_or (url u)
 
bool is_wildcard (url u)
 
url url_path (string s, int type=URL_SYSTEM)
 
url url_general (string name, int type)
 
url url_unix (string name)
 
url url_unix (string dir, string name)
 
url url_system (string name)
 
url url_system (string dir, string name)
 
url url_standard (string name)
 
url url_standard (string dir, string name)
 
url url_pwd ()
 
url url_ramdisc (string contents)
 
url head (url u)
 
url tail (url u)
 
string suffix (url u)
 
string suffix (url u, bool use_locase)
 
string basename (url u, string suf)
 
string basename (url u)
 
url glue (url u, string s)
 
url unglue (url u, int nr)
 
url unblank (url u)
 
url relative (url base, url u)
 
url delta (url base, url u)
 
string get_root (url u)
 
url unroot (url u)
 
url reroot (url u, string s)
 
url expand (url u)
 
url sort (url u)
 
url factor (url u)
 
bool descends (url u, url base)
 
bool is_atomic (url u)
 
bool is_wildcard (url u, int n)
 
bool is_pseudo_atomic (url u)
 
bool is_rooted (url u)
 
bool is_name (url u)
 
bool is_rooted_name (url u)
 
bool is_ramdisc (url u)
 
void skip_ipv6 (string s, int &i)
 
string as_string (url u, int type=URL_SYSTEM)
 
tm_ostreamoperator<< (tm_ostream &out, url u)
 
string as_system_string (url u)
 
string as_unix_string (url u)
 
string as_standard_string (url u)
 
url url_get_name (string s, int type=URL_STANDARD, int i=0)
 

Macro Definition Documentation

◆ URL_SYSTEM

#define URL_SYSTEM   0

Definition at line 15 of file url.hpp.

◆ URL_UNIX

#define URL_UNIX   1

Definition at line 16 of file url.hpp.

◆ URL_STANDARD

#define URL_STANDARD   2

Definition at line 17 of file url.hpp.

◆ URL_CLEAN_UNIX

#define URL_CLEAN_UNIX   3

Definition at line 18 of file url.hpp.

◆ URL_TUPLE

#define URL_TUPLE   245

Definition at line 20 of file url.hpp.

Typedef Documentation

◆ url_tree

Definition at line 26 of file url.hpp.

Function Documentation

◆ CONCRETE_CODE()

CONCRETE_CODE ( url )

◆ as_url()

url as_url ( url_tree t)
inline

Definition at line 61 of file url.hpp.

61 {
62 return url (t);
63}
blackbox t[13]
Definition url.hpp:37

◆ is_root() [1/2]

bool is_root ( url u,
string s )

Definition at line 668 of file url.cpp.

668 {
669 return is_root (u) && (u[1]->t->label == s);
670}
The list class represents a linked list.
Definition list.hpp:48
bool is_root(url u, string s)
Definition url.cpp:668

◆ is_root_web()

bool is_root_web ( url u)

Definition at line 672 of file url.cpp.

672 {
673 return is_root (u, "http") || is_root (u, "https") || is_root (u, "ftp") ||
674 is_root (u, "blank");
675}

◆ is_root_blank()

bool is_root_blank ( url u)

Definition at line 22 of file blank_url.cpp.

22 {
23 return is_root (u, "blank");
24}

◆ is_rooted() [1/2]

bool is_rooted ( url u,
string protocol )

Definition at line 692 of file url.cpp.

692 {
693 return is_root (u, protocol) ||
694 (is_concat (u) && is_rooted (u[1], protocol)) ||
695 (is_or (u) && is_rooted (u[1], protocol) &&
696 is_rooted (u[2], protocol));
697}
bool is_rooted(url u)
Definition url.cpp:686
bool is_or(url u)
Definition url.hpp:178
bool is_concat(url u)
Definition url.hpp:174

◆ is_rooted_web()

bool is_rooted_web ( url u)

Definition at line 700 of file url.cpp.

700 {
701 return is_root_web (u) || (is_concat (u) && is_rooted_web (u[1])) ||
702 (is_or (u) && is_rooted_web (u[1]) && is_rooted_web (u[2]));
703}
bool is_root_web(url u)
Definition url.cpp:672
bool is_rooted_web(url u)
Definition url.cpp:700

◆ is_rooted_blank()

bool is_rooted_blank ( url u)

Definition at line 27 of file blank_url.cpp.

27 {
28 return is_root_blank (u) || (is_concat (u) && is_rooted_blank (u[1])) ||
29 (is_or (u) && is_rooted_blank (u[1]) && is_rooted_blank (u[2]));
30}
bool is_rooted_blank(url u)
Definition blank_url.cpp:27
bool is_root_blank(url u)
Definition blank_url.cpp:22

◆ url_none()

url url_none ( )

Definition at line 91 of file url.cpp.

91 {
92 return as_url (url_tuple ("none"));
93}
static url_tree url_tuple(string label)
Definition url.cpp:23
url as_url(url_tree t)
Definition url.hpp:61

◆ url_here()

url url_here ( )
inline

Definition at line 122 of file url.hpp.

122 {
123 return as_url (url_tree ("."));
124}

◆ url_parent() [1/2]

url url_parent ( )
inline

Definition at line 127 of file url.hpp.

127 {
128 return as_url (url_tree (".."));
129}

◆ url_ancestor()

url url_ancestor ( )
inline

Definition at line 132 of file url.hpp.

132 {
133 return as_url (url_tree ("..."));
134}

◆ url_root()

url url_root ( string protocol)

Definition at line 96 of file url.cpp.

96 {
97 return as_url (url_tuple ("root", protocol));
98}

◆ operator*() [1/3]

url operator* ( url u1,
url u2 )

Definition at line 596 of file url.cpp.

596 {
597 if (is_root (u2) || (is_concat (u2) && is_root (u2[1]))) {
598 if (is_concat (u1) && is_root_web (u1[1])) {
599 if (is_root (u2, "default") ||
600 (is_concat (u2) && is_root (u2[1], "default"))) {
601 url v= u1[2];
602 while (is_concat (v))
603 v= v[1];
604 if (is_root (u2)) return u1[1] * v;
605 return u1[1] * v * u2[2];
606 }
607 if (is_root (u2, "blank") || (is_concat (u2) && is_root (u2[1], "blank")))
608 return reroot (u2, u1[1][1]->t->label);
609 }
610 if (is_root (u1) && is_rooted (u1, "file")) {
611 return u1 * u2[2];
612 }
613 return u2;
614 }
615 if (is_here (u1) || (u1->t == "")) return u2;
616 if (is_here (u2)) return u1;
617 if (is_none (u1)) return url_none ();
618 if (is_none (u2)) return url_none ();
619 if (u2 == url_parent ()) {
620 if (is_root (u1)) return u1;
621 if (is_pseudo_atomic (u1) && (!is_parent (u1))) return url_here ();
622 if (is_semi_root (u1)) return u1;
623 }
624 if (is_concat (u2) && (u2[1] == url_parent ())) {
625 if (is_root (u1)) return u1 * u2[2];
626 if (is_pseudo_atomic (u1) && (!is_parent (u1))) return u2[2];
627 if (is_semi_root (u1)) return u1 * u2[2];
628 }
629 if (is_concat (u1)) return u1[1] * (u1[2] * u2);
630 return as_url (url_tuple ("concat", u1->t, u2->t));
631}
url url_none()
Definition url.cpp:91
bool is_pseudo_atomic(url u)
Definition url.cpp:681
url reroot(url u, string protocol)
Definition url.cpp:490
static bool is_semi_root(url u)
Definition url.cpp:359
bool is_parent(url u)
Definition url.hpp:158
bool is_here(url u)
Definition url.hpp:154
url url_here()
Definition url.hpp:122
bool is_none(url u)
Definition url.hpp:166
url url_parent()
Definition url.hpp:127

◆ operator*() [2/3]

url operator* ( url u1,
const char * name )

Definition at line 634 of file url.cpp.

634 {
635 return u1 * url (name);
636}

◆ operator*() [3/3]

url operator* ( url u1,
string name )

Definition at line 639 of file url.cpp.

639 {
640 return u1 * url (name);
641}

◆ url_concat()

url url_concat ( url u1,
url u2 )

Definition at line 644 of file url.cpp.

644 {
645 return u1 * u2;
646}

◆ url_parent() [2/2]

url url_parent ( url u)
inline

Definition at line 143 of file url.hpp.

143 {
144 return u * url_parent ();
145}

◆ operator|()

url operator| ( url u1,
url u2 )

Definition at line 649 of file url.cpp.

649 {
650 if (is_none (u1)) return u2;
651 if (is_none (u2)) return u1;
652 if (is_or (u1)) return u1[1] | (u1[2] | u2);
653 if (u1 == u2) return u2;
654 if (is_or (u2) && (u1 == u2[1])) return u2;
655 return as_url (url_tuple ("or", u1->t, u2->t));
656}

◆ url_or()

url url_or ( url u1,
url u2 )

Definition at line 659 of file url.cpp.

659 {
660 return u1 | u2;
661}

◆ url_wildcard() [1/2]

url url_wildcard ( )

Definition at line 101 of file url.cpp.

101 { // any url
102 return as_url (url_tuple ("wildcard"));
103}

◆ url_wildcard() [2/2]

url url_wildcard ( string name)

Definition at line 106 of file url.cpp.

106 { // string with * wildcards
107 return as_url (url_tuple ("wildcard", name));
108}

◆ is_here()

bool is_here ( url u)
inline

Definition at line 154 of file url.hpp.

154 {
155 return u->t == ".";
156};

◆ is_parent()

bool is_parent ( url u)
inline

Definition at line 158 of file url.hpp.

158 {
159 return u->t == "..";
160};

◆ is_ancestor()

bool is_ancestor ( url u)
inline

Definition at line 162 of file url.hpp.

162 {
163 return u->t == "...";
164};

◆ is_none()

bool is_none ( url u)
inline

Definition at line 166 of file url.hpp.

166 {
167 return u.label () == "none";
168};

◆ is_root() [2/2]

bool is_root ( url u)
inline

Definition at line 170 of file url.hpp.

170 {
171 return u.label () == "root";
172};

◆ is_concat()

bool is_concat ( url u)
inline

Definition at line 174 of file url.hpp.

174 {
175 return u.label () == "concat";
176};

◆ is_or()

bool is_or ( url u)
inline

Definition at line 178 of file url.hpp.

178 {
179 return u.label () == "or";
180};

◆ is_wildcard() [1/2]

bool is_wildcard ( url u)
inline

Definition at line 182 of file url.hpp.

182 {
183 return u.label () == "wildcard";
184};

◆ url_path()

url url_path ( string s,
int type = URL_SYSTEM )

Definition at line 247 of file url.cpp.

247 {
248 url u= url_get_path (s, type);
249 return u;
250}
static url url_get_path(string s, int type=URL_STANDARD, int i=0)
Definition url.cpp:232

◆ url_general()

url url_general ( string name,
int type )

Definition at line 273 of file url.cpp.

273 {
274 if (contains (name, "://")) {
276 string protocol= tokens[0];
277 string path = tokens[1];
278 if (N (tokens) == 2 && is_alphanum (protocol) && N (protocol) >= 2) {
279 if (protocol == "file") return file_url (path);
280 if (protocol == "http") return http_url (path);
281 if (protocol == "https") return https_url (path);
282 if (protocol == "ftp") return ftp_url (path);
283 return url_root (tokens[0]) * url_get_name (tokens[1], type);
284 }
285 }
286 if (starts (name, "local:")) {
287 return file_url (name (6, N (name)));
288 }
289 if (starts (name, "//")) {
290 return blank_url (name (2, N (name)));
291 }
292 if (heuristic_is_path (name, type)) {
293 return url_path (name, type);
294 }
297 return url_mingw_default (name, type);
298 if (type != URL_CLEAN_UNIX) {
299 if (heuristic_is_http (name)) return http_url (name);
300 if (heuristic_is_ftp (name)) return ftp_url (name);
301 }
302 return url_get_name (name, type);
303}
bool starts(string s, const char *what)
Definition analyze.cpp:566
bool is_alphanum(string s)
Definition analyze.cpp:55
array< string > tokenize(string s, string sep)
Definition analyze.cpp:948
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
bool contains(T a, array< T > b)
Check if an array contains a specified element.
bool os_mingw()
static bool heuristic_is_ftp(string name)
Definition url.cpp:155
static bool heuristic_is_path(string name, int type)
Definition url.cpp:124
static bool heuristic_is_default(string name, int type)
Definition url.cpp:135
static url url_mingw_default(string name, int type)
Definition url.cpp:253
url url_root(string protocol)
Definition url.cpp:96
static url url_default(string name, int type=URL_SYSTEM)
Definition url.cpp:259
url url_get_name(string s, int type, int i)
Definition url.cpp:190
static bool heuristic_is_http(string name)
Definition url.cpp:149
url url_path(string s, int type)
Definition url.cpp:247
static bool heuristic_is_mingw_default(string name, int type)
Definition url.cpp:160
#define URL_CLEAN_UNIX
Definition url.hpp:18

◆ url_unix() [1/2]

url url_unix ( string name)

Definition at line 31 of file file_url.cpp.

31 {
32 return url_general (name, URL_UNIX);
33}
url url_general(string name, int type=URL_SYSTEM)
Definition url.cpp:273
#define URL_UNIX
Definition url.hpp:16

◆ url_unix() [2/2]

url url_unix ( string dir,
string name )

Definition at line 36 of file file_url.cpp.

36 {
37 return url_unix (dir) * url_unix (name);
38}
url url_unix(string name)
Definition file_url.cpp:31

◆ url_system() [1/2]

url url_system ( string name)

Definition at line 306 of file url.cpp.

306 {
307 return url_general (name, URL_SYSTEM);
308}
#define URL_SYSTEM
Definition url.hpp:15

◆ url_system() [2/2]

url url_system ( string dir,
string name )

Definition at line 311 of file url.cpp.

311 {
312 return url_system (dir) * url_system (name);
313}
url url_system(string name)
Definition url.cpp:306

◆ url_standard() [1/2]

url url_standard ( string name)

Definition at line 316 of file url.cpp.

316 {
317 return url_general (name, URL_STANDARD);
318}
#define URL_STANDARD
Definition url.hpp:17

◆ url_standard() [2/2]

url url_standard ( string dir,
string name )

Definition at line 321 of file url.cpp.

321 {
322 return url_standard (dir) * url_standard (name);
323}
url url_standard(string name)
Definition url.cpp:316

◆ url_pwd()

url url_pwd ( )

Definition at line 326 of file url.cpp.

326 {
327 char path[TB_PATH_MAXN];
329 return url_system (path);
330 }
331 else {
332 TM_FAILED ("FAILED to get pwd");
333 return url_none ();
334 }
335}
#define TM_FAILED(msg)
Macro used to throw an exception with a specified error message.
Definition basic.hpp:93

◆ url_ramdisc()

url url_ramdisc ( string contents)

Definition at line 341 of file url.cpp.

341 {
342 return as_url (url_tuple ("root", "ramdisc", contents));
343}

◆ head()

url head ( url u)

Definition at line 365 of file url.cpp.

365 {
366 return u * url_parent ();
367}

◆ tail()

url tail ( url u)

Definition at line 370 of file url.cpp.

370 {
371 if (is_concat (u)) {
372 if (is_root_web (u[1]) && is_atomic (u[2])) return url_here ();
373 return tail (u[2]);
374 }
375 if (is_or (u)) return tail (u[1]) | tail (u[2]);
376 if (is_root (u)) return url_here ();
377 return u;
378}
url tail(url u)
Definition url.cpp:370
bool is_atomic(url u)
Definition url.cpp:664

◆ suffix() [1/2]

string suffix ( url u)

Definition at line 401 of file url.cpp.

401 {
402 return suffix (u, true);
403}
string suffix(url u, bool use_locase)
Definition url.cpp:381

◆ suffix() [2/2]

string suffix ( url u,
bool use_locase )

Definition at line 381 of file url.cpp.

381 {
382 u= tail (u);
383 if (!is_atomic (u)) return "";
384 string s= as_string (u);
385 int i, n= N (s);
386 for (i= n - 1; i >= 0; i--)
387 if (s[i] == '.') break;
388 if ((i > 0) && (i < n - 1)) {
389 string r= s (i + 1, n);
390 while ((N (r) > 0) && (r[N (r) - 1] == '~' || r[N (r) - 1] == '#'))
391 r= r (0, N (r) - 1);
392 int found= index_of (r, '?');
393 if (found != -1) r= r (0, found);
394 if (use_locase) return locase_all (r);
395 else return r;
396 }
397 return "";
398}
string locase_all(string s)
Converts all uppercase characters in a string to lowercase.
Definition analyze.cpp:137
int index_of(string s, char c)
Definition analyze.cpp:800
string as_string(url u, int type)
Definition url.cpp:729

◆ basename() [1/2]

string basename ( url u,
string suf )

Definition at line 406 of file url.cpp.

406 {
407 string s = as_string (tail (u));
408 int found= index_of (s, '?');
409 if (found != -1) s= s (0, found);
410 return remove_suffix (s, suf);
411}
string remove_suffix(string s, string suffix)
Remove the suffix from s if matches.
Definition analyze.cpp:175

◆ basename() [2/2]

string basename ( url u)

Definition at line 414 of file url.cpp.

414 {
415 string s= suffix (u, false);
416 if (!is_empty (s)) s= "." * s;
417 return basename (u, s);
418}
bool is_empty(string s)
Definition string.cpp:316
string basename(url u, string suf)
Definition url.cpp:406

◆ glue()

url glue ( url u,
string s )

Definition at line 421 of file url.cpp.

421 {
422 if (is_atomic (u)) return as_url (url_tree (u->t->label * s));
423 if (is_concat (u)) return u[1] * glue (u[2], s);
424 if (is_or (u)) return glue (u[1], s) | glue (u[2], s);
425 if (is_none (u)) return u;
426 TM_FAILED ("can't glue string to url");
427 return u;
428}
url glue(url u, string s)
Definition url.cpp:421

◆ unglue()

url unglue ( url u,
int nr )

Definition at line 431 of file url.cpp.

431 {
432 if (is_atomic (u))
433 return as_url (url_tree (u->t->label (0, max (N (u->t->label) - nr, 0))));
434 if (is_concat (u)) return u[1] * unglue (u[2], nr);
435 if (is_or (u)) return unglue (u[1], nr) | unglue (u[2], nr);
436 if (is_none (u)) return u;
437 TM_FAILED ("can't unglue from url");
438 return u;
439}
SI max(SI i, SI j)
Returns the maximum of two signed integers.
Definition minmax.hpp:40
url unglue(url u, int nr)
Definition url.cpp:431

◆ unblank()

url unblank ( url u)

Definition at line 442 of file url.cpp.

442 {
443 if (is_concat (u) && (u[2]->t == "")) return u[1];
444 if (is_concat (u)) return u[1] * unblank (u[2]);
445 if (is_or (u)) return unblank (u[1]) | unblank (u[2]);
446 return u;
447}
url unblank(url u)
Definition url.cpp:442

◆ relative()

url relative ( url base,
url u )

Definition at line 450 of file url.cpp.

450 {
451 return head (base) * u;
452}
url head(url u)
Definition url.cpp:365

◆ delta()

url delta ( url base,
url u )

Definition at line 469 of file url.cpp.

469 {
470 if (is_or (u)) return delta (base, u[1]) | delta (base, u[2]);
471 url res= delta_sub (base, u);
472 if (is_none (res)) return u;
473 return res;
474}
url delta_sub(url base, url u)
Definition url.cpp:455
url delta(url base, url u)
Definition url.cpp:469

◆ get_root()

string get_root ( url u)

Definition at line 477 of file url.cpp.

477 {
478 return u.protocol ();
479}

◆ unroot()

url unroot ( url u)

Definition at line 482 of file url.cpp.

482 {
483 if (is_concat (u)) return unroot (u[1]) * u[2];
484 if (is_or (u)) return unroot (u[1]) | unroot (u[2]);
485 if (is_root (u)) return url_here ();
486 return u;
487}
url unroot(url u)
Definition url.cpp:482

◆ reroot()

url reroot ( url u,
string s )

Definition at line 490 of file url.cpp.

490 {
491 if (is_concat (u)) return reroot (u[1], protocol) * u[2];
492 if (is_or (u)) return reroot (u[1], protocol) | reroot (u[2], protocol);
493 if (is_root (u)) return url_root (protocol);
494 return u;
495}

◆ expand()

url expand ( url u)

Definition at line 512 of file url.cpp.

512 {
513 if (is_or (u)) return expand (u[1]) | expand (u[2]);
514 if (is_concat (u)) return expand (expand (u[1]), expand (u[2]));
515 return u;
516}
static url expand(url u1, url u2)
Definition url.cpp:498

◆ sort()

url sort ( url u)

Definition at line 543 of file url.cpp.

543 {
544 if (is_or (u)) return sort_sub (u[1], sort (u[2]));
545 else return u;
546}
static url sort_sub(url add, url to)
Definition url.cpp:533
url sort(url u)
Definition url.cpp:543

◆ factor()

url factor ( url u)

Definition at line 568 of file url.cpp.

568 {
569 return factor_sub (factor_sorted (sort (u)));
570}
static url factor_sorted(url u)
Definition url.cpp:549
static url factor_sub(url u)
Definition url.cpp:561

◆ descends()

bool descends ( url u,
url base )

Definition at line 573 of file url.cpp.

573 {
574 if (u == base) return true;
575 if (is_concat (u) && is_atomic (base)) return u[1] == base;
576 if (is_concat (u) && is_concat (base)) {
578 while (iter_u[1] == iter_base[1]) {
579 iter_u = iter_u[2];
581 if (is_concat (iter_u) && is_concat (iter_base)) {
582 continue;
583 }
584 else {
585 return descends (iter_u, iter_base);
586 }
587 }
588 return false;
589 }
590 if (is_or (u)) return descends (u[1], base) && descends (u[2], base);
591 if (is_or (base)) return descends (u, base[1]) || descends (u, base[2]);
592 return false;
593}
bool descends(url u, url base)
Definition url.cpp:573

◆ is_atomic()

bool is_atomic ( url u)

Definition at line 664 of file url.cpp.

664 {
665 return is_atomic (u->t);
666}

◆ is_wildcard() [2/2]

bool is_wildcard ( url u,
int n )

Definition at line 677 of file url.cpp.

677 {
678 return is_tuple (u->t, "wildcard", n);
679}
static bool is_tuple(url_tree t, string s)
Definition url.cpp:44

◆ is_pseudo_atomic()

bool is_pseudo_atomic ( url u)

Definition at line 681 of file url.cpp.

681 {
682 return is_atomic (u->t) || is_tuple (u->t, "wildcard", 1);
683}

◆ is_rooted() [2/2]

bool is_rooted ( url u)

Definition at line 686 of file url.cpp.

686 {
687 return is_root (u) || (is_concat (u) && is_rooted (u[1])) ||
688 (is_or (u) && is_rooted (u[1]) && is_rooted (u[2]));
689}

◆ is_name()

bool is_name ( url u)

Definition at line 706 of file url.cpp.

706 {
707 if (is_atomic (u)) return true;
708 if (!is_concat (u)) return false;
709 return is_name (u[1]) && is_name (u[2]);
710}
bool is_name(url u)
Definition url.cpp:706

◆ is_rooted_name()

bool is_rooted_name ( url u)

Definition at line 713 of file url.cpp.

713 {
714 return is_concat (u) && is_root (u[1]) && is_name (u[2]);
715}

◆ is_ramdisc()

bool is_ramdisc ( url u)

Definition at line 724 of file url.cpp.

724 {
725 return is_concat (u) && is_root (u[1], "ramdisc");
726}

◆ skip_ipv6()

void skip_ipv6 ( string s,
int & i )

Definition at line 114 of file url.cpp.

114 {
115 i++;
116 while (i < N (s) &&
117 (s[i] == ':' || (s[i] >= '0' && s[i] <= '9') ||
118 (s[i] >= 'a' && s[i] <= 'f') || (s[i] >= 'A' && s[i] <= 'F')))
119 i++;
120 if (i < N (s) && s[i] == ']') i++;
121}

◆ as_string()

string as_string ( url u,
int type = URL_SYSTEM )

Definition at line 729 of file url.cpp.

729 {
730 // This routine pretty prints an url as a string.
731 // FIXME: the current algorithm is quadratic in time.
732 if (is_none (u)) return "{}";
733 if (is_atomic (u)) return u->t->label;
734 if (is_concat (u)) {
735 int stype= type;
736 if (is_root (u[1]) &&
737 !(is_root (u[1], "default") || is_root (u[1], "file"))) {
739 }
740 string sep= (stype == URL_SYSTEM ? string (URL_CONCATER) : string ("/"));
741 string s1 = as_string (u[1], type);
742 string s2 = as_string (u[2], stype);
743 if (is_root (u[1], "default")) s1= "";
744 if ((!is_name (u[1])) && (!is_root (u[1]))) s1= "{" * s1 * "}";
745 if ((!is_concat (u[2])) && (!is_atomic (u[2])) && (!is_wildcard (u[2], 1)))
746 s2= "{" * s2 * "}";
747 if (os_win () && // have to return the windows format
748 ((is_root (u[1], "default") && type == URL_SYSTEM) ||
749 is_root (u[1], "file"))) {
750 string root, remain;
751 if (is_concat (u[2])) {
752 root= as_string (u[2][1], type);
753 // root might be unit letter or hostname. It depends on the length
754 remain= as_string (u[2][2], type);
755 }
756 else {
757 root = s2;
758 remain= "";
759 }
760 if (is_root (u[1], "default")) {
761 if (N (root) == 1) return root * ":" * sep * remain; // drive letter
762 else return "\\\\" * root * "\\" * remain;
763 }
764 else {
765 if (N (root) == 1)
766 return s1 * "/" * root * ":" * sep * remain; // local file
767 else return s1 * root * "/" * remain; // remote
768 }
769 }
770 return s1 * sep * s2;
771 }
772 if (is_or (u)) {
773 string s1= as_string (u[1], type);
774 string s2= as_string (u[2], type);
775 if (!is_name_in_path (u[1])) s1= "{" * s1 * "}";
776 if ((!is_or (u[2])) && (!is_name_in_path (u[2]))) s2= "{" * s2 * "}";
777 if (os_win ()) {
778 if (type == URL_STANDARD) return s1 * ":" * s2;
779 else return s1 * string (URL_SEPARATOR) * s2;
780 }
781 else {
782 return s1 * string (URL_SEPARATOR) * s2;
783 }
784 }
785 if (os_win ()) {
786 if (is_root (u, "default")) {
787 int stype= type;
788 if (is_root (u[1]) && (!is_root (u[1], "default"))) stype= URL_STANDARD;
789 if (stype == URL_SYSTEM) return "";
790 else return "/";
791 }
792 }
793 else {
794 if (is_root (u, "default")) return "/";
795 }
796 if (is_root (u, "blank")) return "/";
797 if (is_root (u, "file")) return u[1]->t->label * "://";
798 if (is_root (u)) return u[1]->t->label * ":/";
799 if (is_wildcard (u, 0)) return "**";
800 if (is_wildcard (u, 1)) return u->t[1]->label;
801 TM_FAILED ("bad url");
802 return "";
803}
bool os_win()
Definition sys_utils.cpp:94
#define URL_SEPARATOR
Definition sys_utils.hpp:23
#define URL_CONCATER
Definition sys_utils.hpp:22
bool is_name_in_path(url u)
Definition url.cpp:718
bool is_wildcard(url u, int n)
Definition url.cpp:677

◆ operator<<()

tm_ostream & operator<< ( tm_ostream & out,
url u )

Definition at line 805 of file url.cpp.

806 {
807 return out << as_string (u, URL_SYSTEM);
808}

◆ as_system_string()

string as_system_string ( url u)
inline

Definition at line 245 of file url.hpp.

245 {
246 return as_string (u, URL_SYSTEM);
247}
string as_string(url u, int type=URL_SYSTEM)
Definition url.cpp:729

◆ as_unix_string()

string as_unix_string ( url u)
inline

Definition at line 249 of file url.hpp.

249 {
250 return as_string (u, URL_UNIX);
251}

◆ as_standard_string()

string as_standard_string ( url u)
inline

Definition at line 253 of file url.hpp.

253 {
254 return as_string (u, URL_STANDARD);
255}

◆ url_get_name()

url url_get_name ( string s,
int type = URL_STANDARD,
int i = 0 )

Definition at line 190 of file url.cpp.

190 {
191 char sep = (type == URL_SYSTEM) ? URL_CONCATER : '/';
192 int n = N (s);
194 while (i < n) {
195 int start= i;
196 while ((i < n) && (s[i] != sep) && (s[i] != '/')) {
197 if (s[i] == '[') skip_ipv6 (s, i);
198 else i++;
199 }
200 if (i > start) {
201 url u = url_get_atom (s (start, i), type);
202 u_list= list (u, u_list);
203 }
204 else if (i == start) {
205 i++;
206 if (i == n) {
207 u_list= list (as_url (url_tree ("")), u_list);
208 }
209 }
210 }
211
212 if (is_nil (u_list)) return as_url (url_tree (""));
213 url ret= u_list->item;
214 u_list = u_list->next;
215 while (!is_nil (u_list)) {
216 url u= u_list->item;
217 if (is_here (u) || (u->t == "")) {
218 // do nothing
219 }
220 else if (is_atomic (u)) {
221 ret= as_url (url_tuple ("concat", u->t, ret->t));
222 }
223 else {
224 ret= u * ret;
225 }
226 u_list= u_list->next;
227 }
228 return ret;
229}
bool is_nil(blackbox x)
Definition blackbox.hpp:29
static url url_get_atom(string s, int type)
Definition url.cpp:172
void skip_ipv6(string s, int &i)
Definition url.cpp:114