1 /** Algorithms operating on URIs including URLs. 2 * 3 * See_Also: https://en.wikipedia.org/wiki/URL 4 */ 5 module nxt.uri_algorithm; 6 7 @safe pure nothrow @nogc: 8 9 /** Try skip over leading protocol prefix part of an URL `url`. 10 * 11 * Currently only skips either of the prefixes `http://` and `https://`. 12 * 13 * Returns: `true` iff skip was performed, `false` otherwise. 14 * 15 * See_Also: https://en.wikipedia.org/wiki/URL 16 */ 17 bool skipOverURLProtocolPrefix(scope ref inout(char)[] url) 18 { 19 import nxt.array_algorithm : skipOver; 20 const(char)[] tmp = url; 21 if (tmp.skipOver(`http`)) 22 { 23 tmp.skipOver('s'); // optional s 24 if (tmp.skipOver(`://`)) 25 { 26 url = url[$ - tmp.length .. $]; // do it 27 return true; 28 } 29 } 30 return false; 31 } 32 33 /// 34 @safe pure nothrow @nogc unittest 35 { 36 auto url = "http://www.sunet.se"; 37 assert(url.skipOverURLProtocolPrefix()); 38 assert(url == "www.sunet.se"); 39 } 40 41 /// 42 @safe pure nothrow @nogc unittest 43 { 44 auto url = "https://www.sunet.se"; 45 assert(url.skipOverURLProtocolPrefix()); 46 assert(url == "www.sunet.se"); 47 }