Refactor skippable BOM detection.

This commit is contained in:
Alek Mosingiewicz 2018-05-21 17:04:33 +02:00
parent 0d44b0b456
commit 60c0a0bf15
2 changed files with 5 additions and 8 deletions

View File

@ -52,7 +52,6 @@
#include "../dispatchkit/exception_specification.hpp"
#include "chaiscript_parser.hpp"
namespace chaiscript
{
@ -213,7 +212,11 @@ namespace chaiscript
infile.read(&v[0], static_cast<std::streamsize>(bytes_needed));
std::string buffer_string(v.begin(), v.end());
if (chaiscript::parser::detail::Char_Parser_Helper<std::string>::has_utf8_bom(buffer_string)) {
if ((buffer_string.size() > 2)
&& (buffer_string[0] == '\xef')
&& (buffer_string[1] == '\xbb')
&& (buffer_string[2] == '\xbf')) {
infile.seekg(3);
return true;
}

View File

@ -114,12 +114,6 @@ namespace chaiscript
// little SFINAE trick to avoid base class
return Char_Parser_Helper<std::true_type>::u8str_from_ll(val);
}
static bool has_utf8_bom(const std::string &t_input)
{
//skip UTF-8 BOM
return ((t_input.size() > 2) && (t_input[0] == '\xef') && (t_input[1] == '\xbb' && t_input[2] == '\xbf'));
}
};
}