Skip to content

Commit

Permalink
IdTech1Converter|HexLex: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Sep 15, 2014
1 parent e2e5be1 commit d395af6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
19 changes: 14 additions & 5 deletions doomsday/plugins/idtech1converter/include/hexlex.h
Expand Up @@ -61,9 +61,23 @@ class HexLex
* Change the source path used to identify the script in log messages.
*
* @param sourcePath New source path to apply. A copy is made.
*
* @see sourcePath()
*/
void setSourcePath(de::String const &sourcePath);

/**
* Returns the currently configured source path.
*
* @see setSourcePath()
*/
de::String const &sourcePath() const;

/**
* Returns the line number at the current position in the script.
*/
int lineNumber() const;

/**
* Attempt to read the next token from the script. @c true is returned if a
* token was parsed (or the previously parsed token was @em unread); otherwise
Expand All @@ -86,11 +100,6 @@ class HexLex
Str const *readString();
de::Uri readUri(de::String const &defaultScheme = "");

/**
* Returns the line number at the current position in the script.
*/
int lineNumber() const;

private:
DENG2_PRIVATE(d)
};
Expand Down
31 changes: 17 additions & 14 deletions doomsday/plugins/idtech1converter/src/hexlex.cpp
Expand Up @@ -32,7 +32,6 @@ DENG2_PIMPL(HexLex)
{
String sourcePath; ///< Used to identify the source in error messages.
ddstring_s const *script = nullptr; ///< The start of the script being parsed.
int scriptLength = 0;
int readPos = 0; ///< Current read position.
int lineNumber = 0;
ddstring_s token;
Expand Down Expand Up @@ -63,7 +62,7 @@ DENG2_PIMPL(HexLex)
bool atEnd()
{
checkOpen();
return (readPos >= scriptLength);
return (readPos >= Str_Length(script));
}
};

Expand All @@ -81,11 +80,10 @@ void HexLex::parse(ddstring_s const *script)
{
LOG_AS("HexLex");

d->script = script;
d->scriptLength = (d->script? Str_Length(d->script) : 0);
d->readPos = 0;
d->lineNumber = 1;
d->alreadyGot = false;
d->script = script;
d->readPos = 0;
d->lineNumber = 1;
d->alreadyGot = false;
Str_Clear(&d->token);
}

Expand All @@ -94,6 +92,16 @@ void HexLex::setSourcePath(String const &sourcePath)
d->sourcePath = sourcePath;
}

String const &HexLex::sourcePath() const
{
return d->sourcePath;
}

int HexLex::lineNumber() const
{
return d->lineNumber;
}

/// @todo Revise with get/peek character mechanics.
bool HexLex::readToken()
{
Expand Down Expand Up @@ -137,7 +145,7 @@ bool HexLex::readToken()
ch = Str_At(d->script, d->readPos);

// A single line comment?
if(ch == ';' || (ch == '/' && d->readPos + 1 < d->scriptLength && Str_At(d->script, d->readPos + 1) == '/'))
if(ch == ';' || (ch == '/' && d->readPos + 1 < Str_Length(d->script) && Str_At(d->script, d->readPos + 1) == '/'))
{
while((ch = Str_At(d->script, d->readPos++)) != '\n')
{
Expand Down Expand Up @@ -184,7 +192,7 @@ bool HexLex::readToken()
while((ch = Str_At(d->script, d->readPos)) > ' ')
{
// A single line comment?
if(ch == ';'|| (ch == '/' && d->readPos + 1 < d->scriptLength && Str_At(d->script, d->readPos + 1) == '/'))
if(ch == ';'|| (ch == '/' && d->readPos + 1 < Str_Length(d->script) && Str_At(d->script, d->readPos + 1) == '/'))
break;

Str_AppendChar(&d->token, ch);
Expand Down Expand Up @@ -253,9 +261,4 @@ de::Uri HexLex::readUri(String const &defaultScheme)
return de::Uri(defaultScheme, Path(Str_Text(Str_PercentEncode(AutoStr_FromTextStd(Str_Text(&d->token))))));
}

int HexLex::lineNumber() const
{
return d->lineNumber;
}

} // namespace idtech1

0 comments on commit d395af6

Please sign in to comment.