diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2015-07-08 14:10:28 +0300 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2015-07-08 14:10:28 +0300 |
commit | 136b58cadd81f97ce1916c2aac1b6f7fbfa828db (patch) | |
tree | aec9af9f4c25e852ff798772018d510309dd621a /main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text | |
parent | d94483ffe1679b7ed8e9d521e9b09f85351cd972 (diff) |
[TextEditor] Simplified encoding detection.
Diffstat (limited to 'main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text')
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/TextFileUtility.cs | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/TextFileUtility.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/TextFileUtility.cs index f6d81568c3..b03e655350 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/TextFileUtility.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/TextFileUtility.cs @@ -362,7 +362,8 @@ namespace MonoDevelop.Core.Text { if (bytes == null) throw new ArgumentNullException ("bytes"); - return IsBinary (new MemoryStream (bytes, false)); + var enc = AutoDetectEncoding (bytes, Math.Min (bytes.Length, maxBufferLength)); + return enc == Encoding.ASCII; } public static bool IsBinary (string fileName) @@ -408,55 +409,26 @@ namespace MonoDevelop.Core.Text { try { var readBuf = bytes; - var states = new byte[verifiers.Length]; - - // Store the dfa data from the verifiers in local variables. - int verifiersRunning = verifiers.Length; - - for (int i = 0; i < verifiers.Length; i++) - states [i] = verifiers [i].InitalState; // run the verifiers - fixed (byte* bBeginPtr = readBuf, stateBeginPtr = states) { - byte* bPtr = bBeginPtr; + fixed (byte* bBeginPtr = readBuf) { byte* bEndPtr = bBeginPtr + readLength; - byte* sEndPtr = stateBeginPtr + states.Length; - - while (bPtr != bEndPtr) { - byte* sPtr = stateBeginPtr; - int i = 0; - while (sPtr != sEndPtr) { - byte curState = *sPtr; + for (int i = 0; i < verifiers.Length; i++) { + byte curState = verifiers [i].InitalState; + byte* bPtr = bBeginPtr; + while (bPtr != bEndPtr) { if (curState != 0) { curState = stateTables [i] [curState] [*bPtr]; if (curState == 0) { - verifiersRunning--; - if (verifiersRunning == 0 || verifiersRunning == 1 && i >= 10 * 1024) - goto finishVerify; + break; } - *sPtr = curState; - } - sPtr++; - i++; - } - bPtr++; - } - finishVerify: - if (verifiersRunning > 0) { - // Console.WriteLine ("valid encodings:"); - // for (int i = 0; i < verifiers.Length; i++) { - // if (verifiers [i].IsEncodingValid (states [i])) - // Console.WriteLine (verifiers [i].Encoding.EncodingName); - // } - // Console.WriteLine ("---------------"); - for (int i = 0; i < verifiers.Length; i++) { - if (verifiers [i].IsEncodingValid (states [i])) { - return verifiers [i].Encoding; } + bPtr++; } + if (verifiers [i].IsEncodingValid (curState)) + return verifiers [i].Encoding; } } - } catch (Exception e) { Console.WriteLine (e); } |