Skip to content

Commit

Permalink
Refactor ResourceRecord_SearchPathsAsStringList output to remove term…
Browse files Browse the repository at this point in the history
…inator

We no longer require that path lists are terminated with a semicolon so
do not add one by default ResourceRecord_SearchPathsAsStringList.
  • Loading branch information
danij-deng committed Oct 21, 2011
1 parent b13bfee commit 12bed46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/resourcerecord.h
Expand Up @@ -84,7 +84,7 @@ const ddstring_t* ResourceRecord_ResolvedPath(resourcerecord_t* rec, boolean can
void ResourceRecord_Print(resourcerecord_t* rec, boolean printStatus);

/**
* @return String list of paths separated (and terminated) with semicolons ';'.
* @return String list of paths delimited with semicolons.
*/
ddstring_t* ResourceRecord_SearchPathsAsStringList(resourcerecord_t* rec);

Expand Down
21 changes: 12 additions & 9 deletions doomsday/engine/portable/src/resourcerecord.c
Expand Up @@ -39,26 +39,29 @@ static ddstring_t* buildSearchPathList(resourcerecord_t* rec)
{
assert(rec);
{
int requiredLength = 0;
int i, requiredLength = 0;
ddstring_t* pathList;

{ int i;
if(!rec->_namesCount)
return 0;

for(i = 0; i < rec->_namesCount; ++i)
requiredLength += Str_Length(rec->_names[i]);
}
requiredLength += rec->_namesCount;
requiredLength += rec->_namesCount - 1;

if(requiredLength == 0)
if(!requiredLength)
return 0;

// Build path list in reverse; newer paths have precedence.
pathList = Str_New();
Str_Reserve(pathList, requiredLength);
Str_Clear(pathList);
{ int i;
for(i = rec->_namesCount-1; i >= 0; i--)
Str_Appendf(pathList, "%s;", Str_Text(rec->_names[i]));
}

i = rec->_namesCount-1;
Str_Set(pathList, Str_Text(rec->_names[i--]));
for(; i >= 0; i--)
Str_Appendf(pathList, ";%s", Str_Text(rec->_names[i]));

return pathList;
}
}
Expand Down

0 comments on commit 12bed46

Please sign in to comment.