mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-24 22:34:54 +02:00
Enhance bash auto-detection.
This commit is contained in:
parent
46e810aa53
commit
37c4eb123c
@ -1257,7 +1257,8 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data,
|
|||||||
// it detectes xml, php and bash script file
|
// it detectes xml, php and bash script file
|
||||||
std::string xmlHeader = "<?xml "; // length : 6
|
std::string xmlHeader = "<?xml "; // length : 6
|
||||||
std::string phpHeader = "<?php "; // length : 6
|
std::string phpHeader = "<?php "; // length : 6
|
||||||
std::string bashHeader = "#!/bin/sh"; // length : 9
|
std::string shebang1 = "#!/bin/sh"; // length : 9
|
||||||
|
std::string shebang2 = "#!/bin/bash"; // length : 11
|
||||||
std::string htmlHeader2 = "<html>"; // length : 6
|
std::string htmlHeader2 = "<html>"; // length : 6
|
||||||
std::string htmlHeader1 = "<!DOCTYPE html>"; // length : 15
|
std::string htmlHeader1 = "<!DOCTYPE html>"; // length : 15
|
||||||
|
|
||||||
@ -1272,8 +1273,13 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data,
|
|||||||
|
|
||||||
std::string buf2Test = std::string((const char *)data + i, longestLength);
|
std::string buf2Test = std::string((const char *)data + i, longestLength);
|
||||||
|
|
||||||
auto res = std::mismatch(bashHeader.begin(), bashHeader.end(), buf2Test.begin());
|
auto res = std::mismatch(shebang1.begin(), shebang1.end(), buf2Test.begin());
|
||||||
if (res.first == bashHeader.end())
|
if (res.first == shebang1.end())
|
||||||
|
{
|
||||||
|
return L_BASH;
|
||||||
|
}
|
||||||
|
res = std::mismatch(shebang2.begin(), shebang2.end(), buf2Test.begin());
|
||||||
|
if (res.first == shebang2.end())
|
||||||
{
|
{
|
||||||
return L_BASH;
|
return L_BASH;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user