英語版
このページの英語版を見る

std.uri

Uniform Resource Identifiers (URI)をエンコードおよびデコードする。 URIはインターネット転送プロトコルで使用される。 有効なURI文字は文字と数字からなる、 および文字で構成される。;/?:@&=+$,-.!~*'() 予約されたURI文字は以下の通りである。;/?:@&=+$, エスケープシーケンスは、% に続く2桁の16進数で構成される。
Authors:

出典 std/uri.d

class URIException: object.Exception;
この例外は、URIのエンコードまたはデコード時に何か問題が発生した場合にスローされる。 例外がスローされる。
Examples:
import std.exception : assertThrown;
assertThrown!URIException("%ab".decode);
string decode(Char)(scope const(Char)[] encodedURI)
if (isSomeChar!Char);
URI文字列encodedURIをUTF-8文字列にデコードして返す。 予約済みURI文字に解決するエスケープシーケンスは置き換えられない。 文字に解決されるエスケープシーケンスは置き換えられない。
Examples:
writeln("foo%20bar".decode); // "foo bar"
writeln("%3C%3E.@.%E2%84%A2".decode); // "<>.@.™"
writeln("foo&/".decode); // "foo&/"
writeln("!@#$&*(".decode); // "!@#$&*("
string decodeComponent(Char)(scope const(Char)[] encodedURIComponent)
if (isSomeChar!Char);
URI文字列encodedURIをUTF-8文字列にデコードして返す。すべての エスケープシーケンスはすべてデコードされる。
Examples:
writeln("foo%2F%26".decodeComponent); // "foo/&"
writeln("dl%C3%A4ng%20r%C3%B6cks".decodeComponent); // "dläng röcks"
writeln("!%40%23%24%25%5E%26*(".decodeComponent); // "!@#$%^&*("
string encode(Char)(scope const(Char)[] uri)
if (isSomeChar!Char);
UTF-8の文字列uriをURIにエンコードし、そのURIを返す。URIとして有効でない文字 はエスケープされる。文字はエスケープされない。
Examples:
writeln("foo bar".encode); // "foo%20bar"
writeln("<>.@.™".encode); // "%3C%3E.@.%E2%84%A2"
writeln("foo/#?a=1&b=2".encode); // "foo/#?a=1&b=2"
writeln("dlang+rocks!".encode); // "dlang+rocks!"
writeln("!@#$%^&*(".encode); // "!@#$%25%5E&*("
string encodeComponent(Char)(scope const(Char)[] uriComponent)
if (isSomeChar!Char);
UTF-8文字列uriComponentをURIにエンコードし、そのURIを返す。 文字、数字、または -.!~*'() のいずれかでない文字はエスケープされる。
Examples:
writeln("!@#$%^&*(".encodeComponent); // "!%40%23%24%25%5E%26*("
writeln("<>.@.™".encodeComponent); // "%3C%3E.%40.%E2%84%A2"
writeln("foo/&".encodeComponent); // "foo%2F%26"
writeln("dläng röcks".encodeComponent); // "dl%C3%A4ng%20r%C3%B6cks"
writeln("dlang+rocks!".encodeComponent); // "dlang%2Brocks!"
ptrdiff_t uriLength(Char)(scope const(Char)[] s)
if (isSomeChar!Char);
文字列s[]はURLで始まるか?
Returns:
-1 それはない s[0 ... len]はそのURLであるs[]のスライスである。
Examples:
string s1 = "http://www.digitalmars.com/~fred/fredsRX.html#foo end!";
writeln(uriLength(s1)); // 49
string s2 = "no uri here";
writeln(uriLength(s2)); // -1
assert(uriLength("issue 14924") < 0);
ptrdiff_t emailLength(Char)(scope const(Char)[] s)
if (isSomeChar!Char);
文字列s[]はメールアドレスで始まるか?
Returns:
-1 それはない s[0 ... i]はそのメールアドレスであるs[]のスライスである。

参考文献 RFC2822

Examples:
string s1 = "my.e-mail@www.example-domain.com with garbage added";
writeln(emailLength(s1)); // 32
string s2 = "no email address here";
writeln(emailLength(s2)); // -1
assert(emailLength("issue 14924") < 0);