blob: 3d547aab20563f4baeb70f2929c212a830f76186 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
using System;
using System.IO;
namespace LibGit2Sharp.Core
{
internal class FilePath : IEquatable<FilePath>
{
internal static FilePath Empty = new FilePath(string.Empty);
private const char posixDirectorySeparatorChar = '/';
private readonly string native;
private readonly string posix;
private FilePath(string path)
{
native = Replace(path, posixDirectorySeparatorChar, Path.DirectorySeparatorChar);
posix = Replace(path, Path.DirectorySeparatorChar, posixDirectorySeparatorChar);
}
public string Native
{
get { return native; }
}
public string Posix
{
get { return posix; }
}
public override string ToString()
{
return Native;
}
public static implicit operator FilePath(string path)
{
switch (path)
{
case null:
return null;
case "":
return Empty;
default:
return new FilePath(path);
}
}
private static string Replace(string path, char oldChar, char newChar)
{
if (oldChar == newChar)
{
return path;
}
return path == null ? null : path.Replace(oldChar, newChar);
}
public bool Equals(FilePath other)
{
return other == null ? posix == null : string.Equals(posix, other.posix, StringComparison.Ordinal);
}
public override bool Equals(object obj)
{
return Equals(obj as FilePath);
}
public override int GetHashCode()
{
return posix == null ? 0 : posix.GetHashCode();
}
}
}
|