minor refactoring
This commit is contained in:
parent
1445090f29
commit
b212d77b7c
|
@ -327,6 +327,13 @@ std::string Preprocessor::read(std::istream &istr)
|
||||||
return removeParantheses(removeComments(code.str()));
|
return removeParantheses(removeComments(code.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool hasbom(const std::string &str)
|
||||||
|
{
|
||||||
|
return bool(str.size() > 3 &&
|
||||||
|
(char)str[0] == (char)0xef &&
|
||||||
|
(char)str[1] == (char)0xbb &&
|
||||||
|
(char)str[2] == (char)0xbf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Preprocessor::removeComments(const std::string &str)
|
std::string Preprocessor::removeComments(const std::string &str)
|
||||||
|
@ -340,17 +347,9 @@ std::string Preprocessor::removeComments(const std::string &str)
|
||||||
unsigned int newlines = 0;
|
unsigned int newlines = 0;
|
||||||
std::ostringstream code;
|
std::ostringstream code;
|
||||||
char previous = 0;
|
char previous = 0;
|
||||||
for (std::string::size_type i = 0; i < str.length(); ++i)
|
for (std::string::size_type i = hasbom(str) ? 3 : 0; i < str.length(); ++i)
|
||||||
{
|
{
|
||||||
char ch = str[i];
|
char ch = str[i];
|
||||||
if (i == 0 && str.size() > 3 &&
|
|
||||||
(char)str[0] == (char)0xef &&
|
|
||||||
(char)str[1] == (char)0xbb &&
|
|
||||||
(char)str[2] == (char)0xbf)
|
|
||||||
{
|
|
||||||
i = 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (ch < 0)
|
if (ch < 0)
|
||||||
throw std::runtime_error("The code contains characters that are unhandled");
|
throw std::runtime_error("The code contains characters that are unhandled");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue