Sparkle can now handle files with special characters

This commit is contained in:
Matthias Dittrich 2012-06-30 23:26:16 +02:00 committed by Hylke Bons
parent aa87519cc6
commit 49fd14ebdb

View file

@ -778,6 +778,49 @@ namespace SparkleLib.Git {
return change_sets;
}
private string EnsureSpecialCharacters (string file_path)
{
if (file_path.StartsWith("\""))
{
System.Diagnostics.Debug.Assert(file_path.Length > 2 && file_path.EndsWith("\""), "unexpected path");
file_path = ResolveSpecialChars(file_path.Substring(1, file_path.Length - 2));
}
return file_path;
}
/// <summary>
/// Resolves special characters like \303\244 (ä) to their real character
/// </summary>
/// <param name="file_path"></param>
/// <returns></returns>
private string ResolveSpecialChars (string file_path)
{
var builder = new System.Text.StringBuilder(file_path.Length);
var codes = new List<byte>();
for (int i = 0; i < file_path.Length; i++)
{
while (file_path[i] == '\\'
&& file_path.Length - i > 3
&& char.IsNumber(file_path[i + 1])
&& char.IsNumber(file_path[i + 2])
&& char.IsNumber(file_path[i + 3]))
{
codes.Add (Convert.ToByte(file_path.Substring(i + 1, 3), 8));
i += 4;
}
if (codes.Count > 0)
{
builder.Append(System.Text.Encoding.UTF8.GetString (codes.ToArray ()));
codes.Clear ();
}
builder.Append(file_path[i]);
}
return builder.ToString();
//System.Text.Encoding.UTF8.
}
private string EnsureSpecialCharacters (string path)
{