Skip to content

Commit

Permalink
libcore: Minor improvements
Browse files Browse the repository at this point in the history
New utility method for Record, and cleaning escape sequences out of
fatal error messages.
  • Loading branch information
skyjake committed Jul 5, 2016
1 parent 030a6ea commit bf3e332
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions doomsday/sdk/libcore/include/de/data/record.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ class DENG2_PUBLIC Record

Variable &appendUniqueWord(String const &name, String const &word, String const &separator = " ");

Variable &appendToArray(String const &name, Value *value);

/**
* Looks up a variable in the record. Variables in subrecords can be accessed
* using the member notation: <code>subrecord-name.variable-name</code>
Expand Down
1 change: 1 addition & 0 deletions doomsday/sdk/libcore/include/de/filesys/package.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class DENG2_PUBLIC Package : public IObject
static String const VAR_PACKAGE;
static String const VAR_PACKAGE_ID;
static String const VAR_PACKAGE_ALIAS;
static String const VAR_PACKAGE_TITLE;
static String const VAR_TITLE;

private:
Expand Down
6 changes: 5 additions & 1 deletion doomsday/sdk/libcore/src/core/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "de/Config"
#include "de/DictionaryValue"
#include "de/DirectoryFeed"
#include "de/EscapeParser"
#include "de/FileLogSink"
#include "de/LibraryFile"
#include "de/Log"
Expand Down Expand Up @@ -409,7 +410,10 @@ void App::handleUncaughtException(String message)
{
LOG_CRITICAL(message);

if (d->terminateFunc) d->terminateFunc(message.toUtf8().constData());
EscapeParser esc;
esc.parse(message);

if (d->terminateFunc) d->terminateFunc(esc.plainText().toUtf8());
}

bool App::processEvent(Event const &ev)
Expand Down
13 changes: 13 additions & 0 deletions doomsday/sdk/libcore/src/data/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,19 @@ Variable &Record::appendUniqueWord(String const &name, String const &word, Strin
return (*this)[name];
}

Variable &Record::appendToArray(String const &name, Value *value)
{
if (!has(name))
{
return addArray(name, new ArrayValue({ value }));
}

Variable &var = (*this)[name];
DENG2_ASSERT(var.value().is<ArrayValue>());
var.value<ArrayValue>().add(value);
return var;
}

Variable &Record::operator [] (String const &name)
{
return const_cast<Variable &>((*const_cast<Record const *>(this))[name]);
Expand Down
12 changes: 2 additions & 10 deletions doomsday/sdk/libcore/src/filesys/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace de {
String const Package::VAR_PACKAGE ("package");
String const Package::VAR_PACKAGE_ID ("package.ID");
String const Package::VAR_PACKAGE_ALIAS("package.alias");
String const Package::VAR_PACKAGE_TITLE("package.title");
String const Package::VAR_TITLE ("title");

static String const PACKAGE_ORDER ("package.__order__");
Expand Down Expand Up @@ -361,16 +362,7 @@ StringList Package::requires(File const &packageFile)

void Package::addRequiredPackage(File &packageFile, String const &id)
{
Record &names = packageFile.objectNamespace();

if (!names.has(PACKAGE_REQUIRES))
{
names.addArray(PACKAGE_REQUIRES, new ArrayValue({ new TextValue(id) }));
}
else
{
names[PACKAGE_REQUIRES].value<ArrayValue>().add(new TextValue(id));
}
packageFile.objectNamespace().appendToArray(PACKAGE_REQUIRES, new TextValue(id));
}

static String stripAfterFirstUnderscore(String str)
Expand Down

0 comments on commit bf3e332

Please sign in to comment.