mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-24 00:05:25 +00:00
@@ -9,7 +9,7 @@ export osseps
|
||||
import std/envvars
|
||||
import std/private/osappdirs
|
||||
|
||||
import std/pathnorm
|
||||
import std/[pathnorm, hashes, sugar, strutils]
|
||||
|
||||
from std/private/ospaths2 import joinPath, splitPath,
|
||||
ReadDirEffect, WriteDirEffect,
|
||||
@@ -25,6 +25,13 @@ export ReadDirEffect, WriteDirEffect
|
||||
type
|
||||
Path* = distinct string
|
||||
|
||||
func hash*(x: Path): Hash =
|
||||
let x = x.string.dup(normalizePath)
|
||||
if FileSystemCaseSensitive:
|
||||
result = x.hash
|
||||
else:
|
||||
result = x.toLowerAscii.hash
|
||||
|
||||
template `$`*(x: Path): string =
|
||||
string(x)
|
||||
|
||||
|
||||
@@ -6,15 +6,12 @@ import std/paths
|
||||
import std/assertions
|
||||
import pathnorm
|
||||
from std/private/ospaths2 {.all.} import joinPathImpl
|
||||
import std/sugar
|
||||
import std/[sugar, sets]
|
||||
|
||||
|
||||
proc normalizePath*(path: Path; dirSep = DirSep): Path =
|
||||
result = Path(pathnorm.normalizePath(path.string, dirSep))
|
||||
|
||||
func `==`(x, y: Path): bool =
|
||||
x.string == y.string
|
||||
|
||||
func joinPath*(parts: varargs[Path]): Path =
|
||||
var estimatedLen = 0
|
||||
var state = 0
|
||||
@@ -231,4 +228,11 @@ block ospaths:
|
||||
when doslikeFileSystem:
|
||||
doAssert joinPath(Path"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\", Path"..\\..\\VC\\vcvarsall.bat") == r"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat".Path
|
||||
doAssert joinPath(Path"C:\\foo", Path"..\\a") == r"C:\a".Path
|
||||
doAssert joinPath(Path"C:\\foo\\", Path"..\\a") == r"C:\a".Path
|
||||
doAssert joinPath(Path"C:\\foo\\", Path"..\\a") == r"C:\a".Path
|
||||
|
||||
|
||||
block: # bug #23663
|
||||
var s: HashSet[Path]
|
||||
s.incl("/a/b/c/..".Path)
|
||||
doAssert "/a/b/".Path in s
|
||||
doAssert "/a/b/c".Path notin s
|
||||
|
||||
Reference in New Issue
Block a user