Browse Source
Fixed a bug that could cause a file to be registered multiple times in the project content, showing all class members twice in the "quick class browser". git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2724 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
6 changed files with 119 additions and 91 deletions
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <summary>
|
||||
/// A minimal version of FileUtility. Is used by ICSharpCode.SharpDevelop.Dom (which doesn't reference
|
||||
/// ICSharpCode.Core)
|
||||
/// </summary>
|
||||
static partial class FileUtility |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the normalized version of fileName.
|
||||
/// Slashes are replaced with backslashes, backreferences "." and ".." are 'evaluated'.
|
||||
/// </summary>
|
||||
public static string NormalizePath(string fileName) |
||||
{ |
||||
if (string.IsNullOrEmpty(fileName)) return fileName; |
||||
|
||||
int i; |
||||
|
||||
bool isWeb = false; |
||||
for (i = 0; i < fileName.Length; i++) { |
||||
if (fileName[i] == '/' || fileName[i] == '\\') |
||||
break; |
||||
if (fileName[i] == ':') { |
||||
if (i > 1) |
||||
isWeb = true; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
char outputSeparator = isWeb ? '/' : '\\'; |
||||
|
||||
StringBuilder result = new StringBuilder(); |
||||
if (isWeb == false && fileName.StartsWith(@"\\") || fileName.StartsWith("//")) { |
||||
i = 2; |
||||
result.Append(outputSeparator); |
||||
} else { |
||||
i = 0; |
||||
} |
||||
int segmentStartPos = i; |
||||
for (; i <= fileName.Length; i++) { |
||||
if (i == fileName.Length || fileName[i] == '/' || fileName[i] == '\\') { |
||||
int segmentLength = i - segmentStartPos; |
||||
switch (segmentLength) { |
||||
case 0: |
||||
// ignore empty segment (if not in web mode)
|
||||
if (isWeb) { |
||||
result.Append(outputSeparator); |
||||
} |
||||
break; |
||||
case 1: |
||||
// ignore /./ segment, but append other one-letter segments
|
||||
if (fileName[segmentStartPos] != '.') { |
||||
if (result.Length > 0) result.Append(outputSeparator); |
||||
result.Append(fileName[segmentStartPos]); |
||||
} |
||||
break; |
||||
case 2: |
||||
if (fileName[segmentStartPos] == '.' && fileName[segmentStartPos + 1] == '.') { |
||||
// remove previous segment
|
||||
int j; |
||||
for (j = result.Length - 1; j >= 0 && result[j] != outputSeparator; j--); |
||||
if (j > 0) { |
||||
result.Length = j; |
||||
} |
||||
break; |
||||
} else { |
||||
// append normal segment
|
||||
goto default; |
||||
} |
||||
default: |
||||
if (result.Length > 0) result.Append(outputSeparator); |
||||
result.Append(fileName, segmentStartPos, segmentLength); |
||||
break; |
||||
} |
||||
segmentStartPos = i + 1; // remember start position for next segment
|
||||
} |
||||
} |
||||
if (isWeb == false) { |
||||
if (result.Length > 0 && result[result.Length - 1] == outputSeparator) { |
||||
result.Length -= 1; |
||||
} |
||||
if (result.Length == 2 && result[1] == ':') { |
||||
result.Append(outputSeparator); |
||||
} |
||||
} |
||||
return result.ToString(); |
||||
} |
||||
|
||||
public static bool IsEqualFileName(string fileName1, string fileName2) |
||||
{ |
||||
return string.Equals(NormalizePath(fileName1), |
||||
NormalizePath(fileName2), |
||||
StringComparison.OrdinalIgnoreCase); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue