Change the comment type into an enum

This commit is contained in:
Jean Pierre Cimalando 2020-04-20 22:54:04 +02:00
parent ea425f380c
commit 605e552a25
2 changed files with 20 additions and 10 deletions

View file

@ -7,6 +7,7 @@
#include "Parser.h" #include "Parser.h"
#include "ParserPrivate.h" #include "ParserPrivate.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include <cassert>
namespace sfz { namespace sfz {
@ -348,21 +349,21 @@ void Parser::flushCurrentHeader()
_currentOpcodes.clear(); _currentOpcodes.clear();
} }
int Parser::hasComment(Reader& reader) Parser::CommentType Parser::getCommentType(Reader& reader)
{ {
if (reader.peekChar() != '/') if (reader.peekChar() != '/')
return false; return CommentType::None;
reader.getChar(); reader.getChar();
int ret = 0; CommentType ret = CommentType::None;
switch (reader.peekChar()) { switch (reader.peekChar()) {
case '/': case '/':
ret = 1; ret = CommentType::Line;
break; break;
case '*': case '*':
ret = 2; ret = CommentType::Block;
break; break;
} }
@ -374,8 +375,8 @@ size_t Parser::skipComment()
{ {
Reader& reader = *_included.back(); Reader& reader = *_included.back();
int commentType = hasComment(reader); const CommentType commentType = getCommentType(reader);
if (!commentType) if (commentType == CommentType::None)
return 0; return 0;
SourceLocation start = reader.location(); SourceLocation start = reader.location();
@ -387,7 +388,7 @@ size_t Parser::skipComment()
bool terminated = false; bool terminated = false;
switch (commentType) { switch (commentType) {
case 1: // line comment case CommentType::Line:
{ {
int c; int c;
while ((c = reader.getChar()) != Reader::kEof && c != '\r' && c != '\n') while ((c = reader.getChar()) != Reader::kEof && c != '\r' && c != '\n')
@ -395,7 +396,7 @@ size_t Parser::skipComment()
terminated = true; terminated = true;
} }
break; break;
case 2: // block comment case CommentType::Block:
{ {
int c1 = 0; int c1 = 0;
int c2 = reader.getChar(); int c2 = reader.getChar();
@ -406,6 +407,9 @@ size_t Parser::skipComment()
} }
} }
break; break;
default:
assert(false);
break;
} }
if (!terminated) { if (!terminated) {

View file

@ -84,7 +84,13 @@ private:
void flushCurrentHeader(); void flushCurrentHeader();
// helpers // helpers
static int hasComment(Reader& reader); // 0=None 1=Line 2=Block enum class CommentType {
None,
Line,
Block,
};
static CommentType getCommentType(Reader& reader);
size_t skipComment(); size_t skipComment();
static void trimRight(std::string& text); static void trimRight(std::string& text);
static size_t extractToEol(Reader& reader, std::string* dst); // ignores comment static size_t extractToEol(Reader& reader, std::string* dst); // ignores comment