mirror of
https://github.com/dlang/phobos.git
synced 2025-04-26 21:22:20 +03:00
removed most global imports from std.uri
This commit is contained in:
parent
385bd4d682
commit
ada176f9a6
1 changed files with 19 additions and 12 deletions
31
std/uri.d
31
std/uri.d
|
@ -25,21 +25,14 @@ module std.uri;
|
||||||
|
|
||||||
//debug=uri; // uncomment to turn on debugging writefln's
|
//debug=uri; // uncomment to turn on debugging writefln's
|
||||||
debug(uri) private import std.stdio;
|
debug(uri) private import std.stdio;
|
||||||
|
|
||||||
/* ====================== URI Functions ================ */
|
|
||||||
|
|
||||||
private import std.ascii;
|
|
||||||
private import core.stdc.stdlib;
|
|
||||||
private import std.utf;
|
|
||||||
private import std.traits : isSomeChar;
|
private import std.traits : isSomeChar;
|
||||||
import core.exception : OutOfMemoryError;
|
|
||||||
import std.exception;
|
|
||||||
|
|
||||||
/** This Exception is thrown if something goes wrong when encoding or
|
/** This Exception is thrown if something goes wrong when encoding or
|
||||||
decoding a URI.
|
decoding a URI.
|
||||||
*/
|
*/
|
||||||
class URIException : Exception
|
class URIException : Exception
|
||||||
{
|
{
|
||||||
|
import std.exception : basicExceptionCtors;
|
||||||
mixin basicExceptionCtors;
|
mixin basicExceptionCtors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +67,9 @@ private immutable ubyte[128] uri_flags = // indexed by character
|
||||||
|
|
||||||
private string URI_Encode(dstring string, uint unescapedSet)
|
private string URI_Encode(dstring string, uint unescapedSet)
|
||||||
{
|
{
|
||||||
|
import core.exception : OutOfMemoryError;
|
||||||
|
import core.stdc.stdlib : alloca;
|
||||||
|
|
||||||
uint j;
|
uint j;
|
||||||
uint k;
|
uint k;
|
||||||
dchar V;
|
dchar V;
|
||||||
|
@ -199,6 +195,10 @@ private uint ascii2hex(dchar c) @nogc @safe pure nothrow
|
||||||
|
|
||||||
private dstring URI_Decode(Char)(in Char[] uri, uint reservedSet) if (isSomeChar!Char)
|
private dstring URI_Decode(Char)(in Char[] uri, uint reservedSet) if (isSomeChar!Char)
|
||||||
{
|
{
|
||||||
|
import core.exception : OutOfMemoryError;
|
||||||
|
import core.stdc.stdlib : alloca;
|
||||||
|
import std.ascii : isHexDigit;
|
||||||
|
|
||||||
uint j;
|
uint j;
|
||||||
uint k;
|
uint k;
|
||||||
uint V;
|
uint V;
|
||||||
|
@ -314,8 +314,9 @@ private dstring URI_Decode(Char)(in Char[] uri, uint reservedSet) if (isSomeChar
|
||||||
|
|
||||||
string decode(Char)(in Char[] encodedURI) if (isSomeChar!Char)
|
string decode(Char)(in Char[] encodedURI) if (isSomeChar!Char)
|
||||||
{
|
{
|
||||||
|
import std.utf : toUTF8;
|
||||||
auto s = URI_Decode(encodedURI, URI_Reserved | URI_Hash);
|
auto s = URI_Decode(encodedURI, URI_Reserved | URI_Hash);
|
||||||
return std.utf.toUTF8(s);
|
return toUTF8(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
|
@ -325,8 +326,9 @@ string decode(Char)(in Char[] encodedURI) if (isSomeChar!Char)
|
||||||
|
|
||||||
string decodeComponent(Char)(in Char[] encodedURIComponent) if (isSomeChar!Char)
|
string decodeComponent(Char)(in Char[] encodedURIComponent) if (isSomeChar!Char)
|
||||||
{
|
{
|
||||||
|
import std.utf : toUTF8;
|
||||||
auto s = URI_Decode(encodedURIComponent, 0);
|
auto s = URI_Decode(encodedURIComponent, 0);
|
||||||
return std.utf.toUTF8(s);
|
return toUTF8(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************
|
/*****************************
|
||||||
|
@ -336,7 +338,8 @@ string decodeComponent(Char)(in Char[] encodedURIComponent) if (isSomeChar!Char)
|
||||||
|
|
||||||
string encode(Char)(in Char[] uri) if (isSomeChar!Char)
|
string encode(Char)(in Char[] uri) if (isSomeChar!Char)
|
||||||
{
|
{
|
||||||
auto s = std.utf.toUTF32(uri);
|
import std.utf : toUTF32;
|
||||||
|
auto s = toUTF32(uri);
|
||||||
return URI_Encode(s, URI_Reserved | URI_Hash | URI_Alpha | URI_Digit | URI_Mark);
|
return URI_Encode(s, URI_Reserved | URI_Hash | URI_Alpha | URI_Digit | URI_Mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +350,8 @@ string encode(Char)(in Char[] uri) if (isSomeChar!Char)
|
||||||
|
|
||||||
string encodeComponent(Char)(in Char[] uriComponent) if (isSomeChar!Char)
|
string encodeComponent(Char)(in Char[] uriComponent) if (isSomeChar!Char)
|
||||||
{
|
{
|
||||||
auto s = std.utf.toUTF32(uriComponent);
|
import std.utf : toUTF32;
|
||||||
|
auto s = toUTF32(uriComponent);
|
||||||
return URI_Encode(s, URI_Alpha | URI_Digit | URI_Mark);
|
return URI_Encode(s, URI_Alpha | URI_Digit | URI_Mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,6 +409,7 @@ ptrdiff_t uriLength(Char)(in Char[] s) if (isSomeChar!Char)
|
||||||
* https://
|
* https://
|
||||||
* www.
|
* www.
|
||||||
*/
|
*/
|
||||||
|
import std.ascii : isAlphaNum;
|
||||||
import std.uni : icmp;
|
import std.uni : icmp;
|
||||||
|
|
||||||
ptrdiff_t i;
|
ptrdiff_t i;
|
||||||
|
@ -469,6 +474,8 @@ ptrdiff_t uriLength(Char)(in Char[] s) if (isSomeChar!Char)
|
||||||
*/
|
*/
|
||||||
ptrdiff_t emailLength(Char)(in Char[] s) if (isSomeChar!Char)
|
ptrdiff_t emailLength(Char)(in Char[] s) if (isSomeChar!Char)
|
||||||
{
|
{
|
||||||
|
import std.ascii : isAlpha, isAlphaNum;
|
||||||
|
|
||||||
ptrdiff_t i;
|
ptrdiff_t i;
|
||||||
|
|
||||||
if (!isAlpha(s[0]))
|
if (!isAlpha(s[0]))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue