From b212d77b7ce4790b541b0dcf940cc214a06386bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 10 Oct 2009 09:29:06 +0200 Subject: [PATCH] minor refactoring --- src/preprocessor.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index 2bbe19d0e..9a216c3db 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -327,6 +327,13 @@ std::string Preprocessor::read(std::istream &istr) 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) @@ -340,17 +347,9 @@ std::string Preprocessor::removeComments(const std::string &str) unsigned int newlines = 0; std::ostringstream code; 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]; - 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) throw std::runtime_error("The code contains characters that are unhandled");