mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
Refactor skippable BOM detection.
This commit is contained in:
parent
0d44b0b456
commit
60c0a0bf15
@ -52,7 +52,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "../dispatchkit/exception_specification.hpp"
|
#include "../dispatchkit/exception_specification.hpp"
|
||||||
#include "chaiscript_parser.hpp"
|
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
{
|
{
|
||||||
@ -213,7 +212,11 @@ namespace chaiscript
|
|||||||
infile.read(&v[0], static_cast<std::streamsize>(bytes_needed));
|
infile.read(&v[0], static_cast<std::streamsize>(bytes_needed));
|
||||||
std::string buffer_string(v.begin(), v.end());
|
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);
|
infile.seekg(3);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -114,12 +114,6 @@ namespace chaiscript
|
|||||||
// little SFINAE trick to avoid base class
|
// little SFINAE trick to avoid base class
|
||||||
return Char_Parser_Helper<std::true_type>::u8str_from_ll(val);
|
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'));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user