본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    라이브러리 · std.url

    URL.path

    Returns the serialized path with its percent escapes preserved.

    path() -> string
    수신자
    URL
    최소 인자 수
    0
    최대 인자 수
    0

    Declaration and parameters

    링크

    사용 조건

    기본 포함 · 미정

    Import std.url in language mode 5.21.

    The current compiler selects std/url.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    수신자

    URL

    매개변수 제약

    URL.scheme returns the lowercase scheme without its delimiter. URL.host returns Some containing the serialized host without user information or a port. IPv6 hosts include their square brackets.

    A URL whose host is absent returns None() from URL.host. A present empty host returns Some containing an empty string. A local file URL can have that empty host.

    URL.path returns the serialized path without the query or fragment. A hierarchical path retains its leading slash. An opaque path has no implied slash. Percent escapes stay encoded so an escaped slash remains path data.

    URL.fragment returns None() when there is no fragment delimiter. An explicit empty fragment returns Some containing an empty string. A present fragment excludes its delimiter and retains percent encoding.

    Scheme, host, path, and fragment inspection cannot fail after construction. Each receiver is evaluated once. The returned strings are immutable and inspection has no external effects.

    Read URL.query for decoded query fields. URL.path and URL.fragment do not apply query decoding. In particular, a plus sign in those components remains a plus sign.

    결과

    The declared result type is string.

    효과

    실패

    Result and effects

    링크

    Returns the serialized path with its percent escapes preserved.

    Resolved contracts

    링크

    Related entries

    링크

    std.url →

    Read serialized URL components and their absence

    링크
    규칙topaz.stdlib.contract.url-components.rule

    Read serialized URL components and their absence

    URL.scheme returns the lowercase scheme without its delimiter. URL.host returns Some containing the serialized host without user information or a port. IPv6 hosts include their square brackets.

    A URL whose host is absent returns None() from URL.host. A present empty host returns Some containing an empty string. A local file URL can have that empty host.

    URL.path returns the serialized path without the query or fragment. A hierarchical path retains its leading slash. An opaque path has no implied slash. Percent escapes stay encoded so an escaped slash remains path data.

    URL.fragment returns None() when there is no fragment delimiter. An explicit empty fragment returns Some containing an empty string. A present fragment excludes its delimiter and retains percent encoding.

    Scheme, host, path, and fragment inspection cannot fail after construction. Each receiver is evaluated once. The returned strings are immutable and inspection has no external effects.

    Read URL.query for decoded query fields. URL.path and URL.fragment do not apply query decoding. In particular, a plus sign in those components remains a plus sign.

    이유

    Component access must preserve delimiters as data and distinguish absence from an empty component. Encoded path and fragment values can be placed back into a URL without turning an escaped separator into structure.

    Read encoded URL components without decoding delimiters

    링크
    main.tpzRead encoded URL components without decoding delimiters플레이그라운드 열기 →
    1. import std.url { URL }
    2. import std.io
    3. match (URL.parse("HTTPS://EXAMPLE.COM:8443/a%2Fb?q=a+b#x%20y")) {
    4. case Ok(value) => {
    5. io.writeLine(value.scheme())
    6. match (value.host()) {
    7. case Some(host) => io.writeLine(host)
    8. case None() => io.writeLine("no host")
    9. }
    10. io.writeLine(value.path())
    11. match (value.fragment()) {
    12. case Some(fragment) => io.writeLine(fragment)
    13. case None() => io.writeLine("no fragment")
    14. }
    15. io.writeLine(value.toString())
    16. }
    17. case Err(_) => io.writeLine("parse failed")
    18. }
    기대 출력종료 코드 0
    https
    example.com
    /a%2Fb
    x%20y
    https://example.com:8443/a%2Fb?q=a+b#x%20y
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. https
    2. example.com
    3. /a%2Fb
    4. x%20y
    5. https://example.com:8443/a%2Fb?q=a+b#x%20y

    Distinguish an absent fragment from an empty fragment

    링크
    main.tpzDistinguish an absent fragment from an empty fragment플레이그라운드 열기 →
    1. import std.url { URL }
    2. import std.io
    3. for text in (["mailto:reader@example.com", "mailto:reader@example.com#"]) {
    4. match (URL.parse(text)) {
    5. case Ok(value) => {
    6. io.writeLine(value.scheme())
    7. match (value.host()) {
    8. case None() => io.writeLine("no host")
    9. case Some(host) => io.writeLine("host={host}")
    10. }
    11. io.writeLine(value.path())
    12. match (value.fragment()) {
    13. case None() => io.writeLine("no fragment")
    14. case Some(fragment) => io.writeLine("fragment={fragment}")
    15. }
    16. io.writeLine("{value.query().length}")
    17. }
    18. case Err(_) => io.writeLine("parse failed")
    19. }
    20. }
    기대 출력종료 코드 0
    mailto
    no host
    reader@example.com
    no fragment
    0
    mailto
    no host
    reader@example.com
    fragment=
    0
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. mailto
    2. no host
    3. reader@example.com
    4. no fragment
    5. 0
    6. mailto
    7. no host
    8. reader@example.com
    9. fragment=
    10. 0

    Read IPv6 and file hosts without losing authority data

    링크
    main.tpzRead IPv6 and file hosts without losing authority data플레이그라운드 열기 →
    1. import std.url { URL }
    2. import std.io
    3. for text in (["https://u:p@[2001:DB8::1]:443/", "file:///tmp/a"]) {
    4. match (URL.parse(text)) {
    5. case Ok(value) => {
    6. match (value.host()) {
    7. case Some(host) => io.writeLine("host={host}")
    8. case None() => io.writeLine("no host")
    9. }
    10. io.writeLine(value.toString())
    11. }
    12. case Err(_) => io.writeLine("parse failed")
    13. }
    14. }
    기대 출력종료 코드 0
    host=[2001:db8::1]
    https://u:p@[2001:db8::1]/
    host=
    file:///tmp/a
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. host=[2001:db8::1]
    2. https://u:p@[2001:db8::1]/
    3. host=
    4. file:///tmp/a

    Serialize a Unicode domain, path, and fragment

    링크
    main.tpzSerialize a Unicode domain, path, and fragment플레이그라운드 열기 →
    1. import std.url { URL }
    2. import std.io
    3. match (URL.parse("https://bücher.example/한#α")) {
    4. case Ok(value) => {
    5. match (value.host()) {
    6. case Some(host) => io.writeLine(host)
    7. case None() => io.writeLine("no host")
    8. }
    9. io.writeLine(value.path())
    10. match (value.fragment()) {
    11. case Some(fragment) => io.writeLine(fragment)
    12. case None() => io.writeLine("no fragment")
    13. }
    14. io.writeLine(value.toString())
    15. }
    16. case Err(_) => io.writeLine("parse failed")
    17. }
    기대 출력종료 코드 0
    xn--bcher-kva.example
    /%ED%95%9C
    %CE%B1
    https://xn--bcher-kva.example/%ED%95%9C#%CE%B1
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. xn--bcher-kva.example
    2. /%ED%95%9C
    3. %CE%B1
    4. https://xn--bcher-kva.example/%ED%95%9C#%CE%B1

    메뉴

    다운로드 →