Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

std.uri

Encode and decode Uniform Resource Identifiers (URIs). URIs are used in internet transfer protocols. Valid URI characters consist of letters, digits, and the characters;/?:@&=+$,-.!~*'() Reserved URI characters are;/?:@&=+$, Escape sequences consist of% followed by two hex digits.
See Also:
RFC 3986
Wikipedia
License:
Boost License 1.0.
Authors:
Walter Bright

Sourcestd/uri.d

classURIException:object.Exception;
This Exception is thrown if something goes wrong when encoding ordecoding a URI.
Examples:
import std.exception : assertThrown;assertThrown!URIException("%ab".decode);
stringdecode(Char)(scope const(Char)[]encodedURI)
if (isSomeChar!Char);
Decodes the URI string encodedURI into a UTF-8 string and returns it. Escape sequences that resolve to reserved URI characters are not replaced. Escape sequences that resolve to the '#' character are not replaced.
Examples:
writeln("foo%20bar".decode);// "foo bar"writeln("%3C%3E.@.%E2%84%A2".decode);// "<>.@.™"writeln("foo&/".decode);// "foo&/"writeln("!@#$&*(".decode);// "!@#$&*("
stringdecodeComponent(Char)(scope const(Char)[]encodedURIComponent)
if (isSomeChar!Char);
Decodes the URI string encodedURI into a UTF-8 string and returns it. All escape sequences are decoded.
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);// "!@#$%^&*("
stringencode(Char)(scope const(Char)[]uri)
if (isSomeChar!Char);
Encodes the UTF-8 string uri into a URI and returns that URI. Any character not a valid URI character is escaped. The '#' character is not escaped.
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&*("
stringencodeComponent(Char)(scope const(Char)[]uriComponent)
if (isSomeChar!Char);
Encodes the UTF-8 string uriComponent into a URI and returns that URI. Any character not a letter, digit, or one of -.!~*'() is escaped.
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_turiLength(Char)(scope const(Char)[]s)
if (isSomeChar!Char);
Does string s[] start with a URL?
Returns:
-1 it does not len it does, and s[0 .. len] is the slice of s[] that is that URL
Examples:
string s1 ="http://www.digitalmars.com/~fred/fredsRX.html#foo end!";writeln(uriLength(s1));// 49string s2 ="no uri here";writeln(uriLength(s2));// -1assert(uriLength("issue 14924") < 0);
ptrdiff_temailLength(Char)(scope const(Char)[]s)
if (isSomeChar!Char);
Does string s[] start with an email address?
Returns:
-1 it does not len it does, and s[0 .. i] is the slice of s[] that is that email address

ReferencesRFC2822

Examples:
string s1 ="my.e-mail@www.example-domain.com with garbage added";writeln(emailLength(s1));// 32string s2 ="no email address here";writeln(emailLength(s2));// -1assert(emailLength("issue 14924") < 0);
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 04:08:10 2026

[8]ページ先頭

©2009-2026 Movatter.jp