private static string FixSlashes(string path, OsPathKind kind) { switch (kind) { case OsPathKind.Windows: return(path.Replace('/', '\\')); case OsPathKind.Unix: return(path.Replace('\\', '/')); } return(path); }
public OsPath(string path, OsPathKind kind) { if (path == null) { _kind = kind; _path = string.Empty; } else { _kind = kind; _path = FixSlashes(path, kind); } }
public OsPath(string path) { if (path == null) { _kind = OsPathKind.Unknown; _path = string.Empty; } else { _kind = DetectPathKind(path); _path = FixSlashes(path, _kind); } }
private static string FixSlashes(string path, OsPathKind kind) { switch (kind) { case OsPathKind.Windows: return(path.Replace('/', '\\')); case OsPathKind.Unix: path = path.Replace('\\', '/'); while (path.Contains("//")) { path = path.Replace("//", "/"); } return(path); } return(path); }
public void should_auto_detect_kind(string path, OsPathKind kind) { var result = new OsPath(path); result.Kind.Should().Be(kind); if (kind == OsPathKind.Windows) { result.IsWindowsPath.Should().BeTrue(); result.IsUnixPath.Should().BeFalse(); } else if (kind == OsPathKind.Unix) { result.IsWindowsPath.Should().BeFalse(); result.IsUnixPath.Should().BeTrue(); } else { result.IsWindowsPath.Should().BeFalse(); result.IsUnixPath.Should().BeFalse(); } }
public void should_auto_detect_kind(String path, OsPathKind kind) { var result = new OsPath(path); result.Kind.Should().Be(kind); if (kind == OsPathKind.Windows) { result.IsWindowsPath.Should().BeTrue(); result.IsUnixPath.Should().BeFalse(); } else if (kind == OsPathKind.Unix) { result.IsWindowsPath.Should().BeFalse(); result.IsUnixPath.Should().BeTrue(); } else { result.IsWindowsPath.Should().BeFalse(); result.IsUnixPath.Should().BeFalse(); } }