Update JSBaker.cpp

This commit is contained in:
utkarshgautamnyu 2017-09-26 11:01:56 -07:00 committed by GitHub
parent a9aab67a06
commit 0b387f5b38

View file

@ -34,7 +34,7 @@ void JSBaker::importJS() {
// Import the file to be processed from _jsURL // Import the file to be processed from _jsURL
QFile jsFile(_jsURL.toLocalFile()); QFile jsFile(_jsURL.toLocalFile());
if (!jsFile.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!jsFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
handleError("Error opening " + _originalJSFilePath + " for reading"); handleError("Error opening " + _jsURL.fileName() + " for reading");
return; return;
} }
@ -85,18 +85,16 @@ void JSBaker::bakeJS(QFile* inputFile) {
// If '/' is not followed by '/' or '*' print '/' // If '/' is not followed by '/' or '*' print '/'
out << currentCharacter; out << currentCharacter;
} }
} else if (isControlCharacter(currentCharacter)) { } else if (isSpaceOrTab(currentCharacter)) {
// Check if white space or tab // Check if white space or tab
// Skip multiple spaces or tabs // Skip multiple spaces or tabs
if (isControlCharacter(nextCharacter)) { while (isSpaceOrTab(nextCharacter)) {
while (isControlCharacter(nextCharacter)) {
in >> nextCharacter; in >> nextCharacter;
if (nextCharacter == '\n') { if (nextCharacter == '\n') {
break; break;
} }
} }
}
// check if space can be omitted // check if space can be omitted
if (!canOmitSpace(previousCharacter, nextCharacter)) { if (!canOmitSpace(previousCharacter, nextCharacter)) {
@ -107,7 +105,7 @@ void JSBaker::bakeJS(QFile* inputFile) {
//Skip multiple new lines //Skip multiple new lines
//Skip new line followed by space or tab //Skip new line followed by space or tab
while (nextCharacter == '\n' || isControlCharacter(nextCharacter)) { while (nextCharacter == '\n' || isSpaceOrTab(nextCharacter)) {
in >> nextCharacter; in >> nextCharacter;
} }
@ -246,7 +244,7 @@ bool JSBaker::isSpecialCharacterNext(QChar c) {
} }
// Check if white space or tab // Check if white space or tab
bool JSBaker::isControlCharacter(QChar c) { bool JSBaker::isSpaceOrTab(QChar c) {
return (c == ' ' || c == '\t'); return (c == ' ' || c == '\t');
} }