|
|
|
@ -23,30 +23,28 @@ namespace ICSharpCode.TextEditor.Util
@@ -23,30 +23,28 @@ namespace ICSharpCode.TextEditor.Util
|
|
|
|
|
return codepage == 65001 || codepage == 65000 || codepage == 1200 || codepage == 1201; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static string ReadFileContent(Stream fs, ref Encoding encoding, Encoding defaultEncoding) |
|
|
|
|
public static string ReadFileContent(Stream fs, ref Encoding encoding) |
|
|
|
|
{ |
|
|
|
|
using (StreamReader reader = OpenStream(fs, encoding, defaultEncoding)) { |
|
|
|
|
using (StreamReader reader = OpenStream(fs, encoding)) { |
|
|
|
|
reader.Peek(); |
|
|
|
|
encoding = reader.CurrentEncoding; |
|
|
|
|
return reader.ReadToEnd(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static string ReadFileContent(string fileName, ref Encoding encoding, Encoding defaultEncoding) |
|
|
|
|
public static string ReadFileContent(string fileName, Encoding encoding) |
|
|
|
|
{ |
|
|
|
|
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { |
|
|
|
|
using (StreamReader reader = OpenStream(fs, encoding, defaultEncoding)) { |
|
|
|
|
encoding = reader.CurrentEncoding; |
|
|
|
|
return reader.ReadToEnd(); |
|
|
|
|
} |
|
|
|
|
return ReadFileContent(fs, ref encoding); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static StreamReader OpenStream(Stream fs, Encoding suggestedEncoding, Encoding defaultEncoding) |
|
|
|
|
public static StreamReader OpenStream(Stream fs, Encoding defaultEncoding) |
|
|
|
|
{ |
|
|
|
|
if (fs == null) |
|
|
|
|
throw new ArgumentNullException("fs"); |
|
|
|
|
|
|
|
|
|
if (fs.Length > 3) { |
|
|
|
|
if (fs.Length >= 2) { |
|
|
|
|
// the autodetection of StreamReader is not capable of detecting the difference
|
|
|
|
|
// between ISO-8859-1 and UTF-8 without BOM.
|
|
|
|
|
int firstByte = fs.ReadByte(); |
|
|
|
@ -63,8 +61,8 @@ namespace ICSharpCode.TextEditor.Util
@@ -63,8 +61,8 @@ namespace ICSharpCode.TextEditor.Util
|
|
|
|
|
return AutoDetect(fs, (byte)firstByte, (byte)secondByte, defaultEncoding); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (suggestedEncoding != null) { |
|
|
|
|
return new StreamReader(fs, suggestedEncoding); |
|
|
|
|
if (defaultEncoding != null) { |
|
|
|
|
return new StreamReader(fs, defaultEncoding); |
|
|
|
|
} else { |
|
|
|
|
return new StreamReader(fs); |
|
|
|
|
} |
|
|
|
|