From 2c80fc3018da7126b8f4cf1bee35753481e54896 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 13 Oct 2015 21:15:50 +0200 Subject: [PATCH] Fix file content detection for xml/html/php/bash Add the ability of take into account Unicode BOM for file content detection (xml/html/php/bash). --- PowerEditor/src/ScitillaComponent/Buffer.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 133e3ffe4..9a0e61fb1 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -1261,8 +1261,19 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data, std::string htmlHeader2 = ""; // length : 6 std::string htmlHeader1 = ""; // length : 15 - const size_t longestLength = htmlHeader1.length(); // longest length - html header Length + const size_t longestLength = htmlHeader1.length(); // longest length : html header Length + const size_t shortestLength = xmlHeader.length(); + size_t i = 0; + + if (dataLen <= shortestLength) + return L_TEXT; + + // Eliminate BOM if present + if ((data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF) || // UTF8 BOM + (data[0] == 0xFE && data[1] == 0xFF && data[2] == 0x00) || // UTF16 BE BOM + (data[0] == 0xFF && data[1] == 0xFE && data[2] == 0x00)) // UTF16 LE BOM + i += 3; for (; i < dataLen; ++i) {