uri
URI를 빌드하고 파싱하기 위한 유틸리티로, RFC 6570에서 정의한 URI 템플릿을 분석하는 기능도 포함합니다.
Dart에서 URI를 다루는 데 사용하는 유틸리티
^3.0.0^1.16.6아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Utilities for working with URIs in Dart, mostly parsing and generating URIs.
UriPattern is an interface for classes that match and parse URIs, much like the Pattern is for Strings. It defines the methods bool matches(Uri uri) and UriMatch match(Uri uri).
UriMatch is the result of UriPattern.match(). It contains the parameters parsed out of a URI and the "rest" of the URI left over after parsing, which is useful for parsing a single URI with multiple relative URI patterns that form a hierarchy.
UriTemplate is an implementation of RFC 6570 URI Templates. URI Templates are useful for generating URIs from data. UriTemplates are created from a template string, and then expanded with data to generate a URI:
var template = UriTemplate("http://example.com/~{user}/");
String fredUri = template.expand({'user': 'fred'});
print(fredUri); // prints: http://example.com/~fred/
URI templates are strings made up of fixed and variable parts. The variable parts are described with expressions, which are places within single curly-braces: { and }.
Expressions consist of an optional operator and a comma-separated list of variable specifications_. Variable specifications consist of a variable name and an optional modifier. The operator applies to the whole expression and controls how reserved characters are expanded, the prefix and separator, if any, applied to the expansion, and whether to expand the variable as a key/value pair. Modifiers apply to each variable in the expression and allow truncating the value, or "exploding" list and maps into multiple key/value pairs.
http://example.com/~{username}/http://example.com/dictionary/{term:1}/{term}http://example.com/search{?q,lang}URI template expansions does more than simple variable replacement, it has facilities for generating paths, fragments, query strings and more. To control the expansion, expressions can use one of the supported operators:
| Operator | Description |
|---|---|
| none | Simple string expansion |
| + | Reserved string expansion |
| # | Fragment expansion |
| . | Label expansion, dot-prefixed |
| / | Path segments, slash-prefixed |
| ; | Path-style parameters, semicolon-prefixed |
| ? | Form-style query, ampersand-separated |
| & | Form-style query continuation |
Modifiers control
| Modifier | Description |
|---|---|
| none | Default expansion |
| :n | Prefix: use only the first n characters of the value |
| * | "Explode" the lists and maps into key/value pairs |
UriParser parses URIs according to a UriTemplate, extracting parameters based on the variables defined in the template.
Since URI Templates are not designed to be parsable, only a restricted subset of templates can be used for parsing.
Parsable templates have the following restrictions over expandable templates:
UriBuilder is mutable container of URI components for incrementally building Uris.