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

문서 검색

명세 6.0

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

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

    라이브러리 · std.path

    Path.from

    Validates and normalizes text into a logical project-relative Path.

    from(text: string) -> Result<Path, string>
    수신자
    해당 없음
    최소 인자 수
    1
    최대 인자 수
    1

    Declaration and parameters

    링크

    사용 조건

    기본 포함 · 미정

    Import std.path in language mode 5.21.

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

    수신자

    매개변수 제약

    Path.from(text) is the constructor for normalized relative paths and returns Result<Path, string>.

    Path.from normalizes path separators and removes empty and dot components. Parent components must stay within the relative root. A path reduced to no components is represented by a dot.

    Empty text, NUL, absolute paths, and parent traversal beyond the relative root return Err. These input failures are values that a caller can handle.

    A leading slash or backslash returns Err. Text that starts with one ASCII character followed immediately by a colon returns Err.

    Path.cwdRelative and Path.project are absent. A Path value already satisfies normalization and has no normalize member.

    Path operations inspect text without accessing the filesystem. Constructing a Path does not establish that its target exists or is accessible.

    결과

    The declared result type is Result<Path, string>.

    효과

    실패

    Result and effects

    링크

    Construct a normalized relative Path and return invalid path text as Err. Existing Path values already satisfy the normalization invariant.

    Why

    링크

    Normalizing at construction makes every Path operation use the same representation. A second constructor or an identity normalize call adds no path meaning.

    Related entries

    링크

    std.path →

    Construct normalized paths with Path.from

    링크
    규칙topaz.stdlib.contract.path-from.rule

    Construct normalized paths with Path.from

    Path.from(text) is the constructor for normalized relative paths and returns Result<Path, string>.

    Path.from normalizes path separators and removes empty and dot components. Parent components must stay within the relative root. A path reduced to no components is represented by a dot.

    Empty text, NUL, absolute paths, and parent traversal beyond the relative root return Err. These input failures are values that a caller can handle.

    A leading slash or backslash returns Err. Text that starts with one ASCII character followed immediately by a colon returns Err.

    Path.cwdRelative and Path.project are absent. A Path value already satisfies normalization and has no normalize member.

    Path operations inspect text without accessing the filesystem. Constructing a Path does not establish that its target exists or is accessible.

    이유

    One constructor gives relative path text one interpretation. Normalization is a Path invariant, so a separate identity operation gives the same value a second spelling.

    Construct a normalized path

    링크
    main.tpzConstruct a normalized path플레이그라운드 열기 →
    1. import std.path { Path }
    2. import std.test
    3. import std.io
    4. let chapter = test.assertOk(Path.from("chapters/./draft/../main.tpz"))
    5. io.writeLine(chapter.toString())
    기대 출력종료 코드 0
    chapters/main.tpz
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

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

    기대 표준 출력
    1. chapters/main.tpz

    Reject a path that escapes its relative root

    링크
    main.tpzReject a path that escapes its relative root플레이그라운드 열기 →
    1. import std.path { Path }
    2. import std.io
    3. match (Path.from("../chapter.tpz")) {
    4. case Err(_) => io.writeLine("outside root rejected")
    5. case Ok(_) => io.writeLine("accepted")
    6. }
    기대 출력종료 코드 0
    outside root rejected
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

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

    기대 표준 출력
    1. outside root rejected

    Reject Path.cwdRelative

    링크
    main.tpzReject Path.cwdRelative플레이그라운드 열기 →
    1. import std.path { Path }
    2. let value = Path.cwdRelative("chapter.tpz")
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check main.tpz --format json · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    Reject Path.project

    링크
    main.tpzReject Path.project플레이그라운드 열기 →
    1. import std.path { Path }
    2. let value = Path.project("chapter.tpz")
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check main.tpz --format json · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    Reject Path.normalize

    링크
    main.tpzReject Path.normalize플레이그라운드 열기 →
    1. import std.path { Path }
    2. function inspect(path: Path) -> () {
    3. let value = path.normalize()
    4. return ()
    5. }
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check main.tpz --format json · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    Distinguish rejected ASCII prefixes from relative path text

    링크
    main.tpzDistinguish rejected ASCII prefixes from relative path text플레이그라운드 열기 →
    1. import std.path { Path }
    2. import std.test
    3. import std.io
    4. test.assertErr(Path.from("a:"))
    5. test.assertErr(Path.from("1:"))
    6. test.assertErr(Path.from("!:"))
    7. io.writeLine(test.assertOk(Path.from("aa:")).toString())
    8. io.writeLine(test.assertOk(Path.from("é:")).toString())
    9. io.writeLine(test.assertOk(Path.from("가:")).toString())
    기대 출력종료 코드 0
    aa:
    é:
    가:
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

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

    기대 표준 출력
    1. aa:
    2. é:
    3. 가:

    Diagnostics

    링크

    Unknown member or field →

    메뉴

    다운로드 →