Skip to content

Commit

Permalink
COMMON: Rename UString::sprintf() to UString::format()
Browse files Browse the repository at this point in the history
The name format() reflects the purpose of the function better, and
parallels String.format() in Java, boost::format, and others.
  • Loading branch information
DrMcCoy committed Jun 8, 2015
1 parent 1de9c61 commit 3d58943
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/aurora/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Common::MemoryReadStream *preParseColorCodes(Common::SeekableReadStream &stream)

if (state == 5) {
if (b == '>') {
Common::UString c = Common::UString::sprintf("<c%02X%02X%02X%02X>",
Common::UString c = Common::UString::format("<c%02X%02X%02X%02X>",
(uint8) color[0], (uint8) color[1], (uint8) color[2], (uint8) 0xFF);

output.writeString(c);
Expand Down
72 changes: 36 additions & 36 deletions src/cline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,49 +58,49 @@ Job parseCommandLine(int argc, char **argv) {
Common::UString createVersionText() {
Common::UString text;

text += Common::UString::sprintf("%s\n", PHAETHON_NAMEVERSIONFULL);
text += Common::UString::sprintf("%s\n", PHAETHON_URL);
text += Common::UString::sprintf("\n");
text += Common::UString::sprintf("Copyright (c) %s by the following:\n", PHAETHON_COPYRIGHTYEAR);
text += Common::UString::sprintf("\n");
text += Common::UString::sprintf("%s\n", PHAETHON_COPYRIGHTAUTHOR);
text += Common::UString::sprintf("\n");
text += Common::UString::sprintf("%s is free software; you can redistribute it and/or\n", PHAETHON_NAME);
text += Common::UString::sprintf("modify it under the terms of the GNU General Public License\n");
text += Common::UString::sprintf("as published by the Free Software Foundation; either version 3\n");
text += Common::UString::sprintf("of the License, or (at your option) any later version.\n");
text += Common::UString::sprintf("\n");
text += Common::UString::sprintf("%s is distributed in the hope that it will be useful,\n", PHAETHON_NAME);
text += Common::UString::sprintf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
text += Common::UString::sprintf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
text += Common::UString::sprintf("GNU General Public License for more details.\n");
text += Common::UString::sprintf("\n");
text += Common::UString::sprintf("You should have received a copy of the GNU General Public License\n");
text += Common::UString::sprintf("along with %s. If not, see <http://www.gnu.org/licenses/>.\n", PHAETHON_NAME);
text += Common::UString::sprintf("\n");
text += Common::UString::sprintf("The Infinity engine, Aurora engine, Odyssey engine and Eclipse engine are\n");
text += Common::UString::sprintf("registered trademarks of BioWare Corp., a subsidiary of Electronic Arts, Inc.\n");
text += Common::UString::sprintf("The Electron engine and Lycium engine are trademarks of BioWare Corp., a\n");
text += Common::UString::sprintf("subsidiary of Electronic Arts, Inc. Bink is a registered trademark of RAD Game\n");
text += Common::UString::sprintf("Tools, Inc. Neverwinter Nights is a registered trademark of Wizards of the\n");
text += Common::UString::sprintf("Coast, a subsidiary of Hasbro Inc. Star Wars, Knights of the Old Republic and\n");
text += Common::UString::sprintf("The Sith Lords are registered trademarks of Lucasfilm Entertainment Company\n");
text += Common::UString::sprintf("Ltd., a subsidiary of The Walt Disney Company. Jade Empire is a registered\n");
text += Common::UString::sprintf("trademark of BioWare Corp., a subsidiary of Electronic Arts, Inc. Sonic the\n");
text += Common::UString::sprintf("Hedgehog is a registered trademark of Sega Corporation. The Witcher is a\n");
text += Common::UString::sprintf("registered trademark of CD Projekt S.A. Dragon Age is a registered trademark\n");
text += Common::UString::sprintf("of Electronic Arts, Inc. All rights reserved.");
text += Common::UString::format("%s\n", PHAETHON_NAMEVERSIONFULL);
text += Common::UString::format("%s\n", PHAETHON_URL);
text += Common::UString::format("\n");
text += Common::UString::format("Copyright (c) %s by the following:\n", PHAETHON_COPYRIGHTYEAR);
text += Common::UString::format("\n");
text += Common::UString::format("%s\n", PHAETHON_COPYRIGHTAUTHOR);
text += Common::UString::format("\n");
text += Common::UString::format("%s is free software; you can redistribute it and/or\n", PHAETHON_NAME);
text += Common::UString::format("modify it under the terms of the GNU General Public License\n");
text += Common::UString::format("as published by the Free Software Foundation; either version 3\n");
text += Common::UString::format("of the License, or (at your option) any later version.\n");
text += Common::UString::format("\n");
text += Common::UString::format("%s is distributed in the hope that it will be useful,\n", PHAETHON_NAME);
text += Common::UString::format("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
text += Common::UString::format("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
text += Common::UString::format("GNU General Public License for more details.\n");
text += Common::UString::format("\n");
text += Common::UString::format("You should have received a copy of the GNU General Public License\n");
text += Common::UString::format("along with %s. If not, see <http://www.gnu.org/licenses/>.\n", PHAETHON_NAME);
text += Common::UString::format("\n");
text += Common::UString::format("The Infinity engine, Aurora engine, Odyssey engine and Eclipse engine are\n");
text += Common::UString::format("registered trademarks of BioWare Corp., a subsidiary of Electronic Arts, Inc.\n");
text += Common::UString::format("The Electron engine and Lycium engine are trademarks of BioWare Corp., a\n");
text += Common::UString::format("subsidiary of Electronic Arts, Inc. Bink is a registered trademark of RAD Game\n");
text += Common::UString::format("Tools, Inc. Neverwinter Nights is a registered trademark of Wizards of the\n");
text += Common::UString::format("Coast, a subsidiary of Hasbro Inc. Star Wars, Knights of the Old Republic and\n");
text += Common::UString::format("The Sith Lords are registered trademarks of Lucasfilm Entertainment Company\n");
text += Common::UString::format("Ltd., a subsidiary of The Walt Disney Company. Jade Empire is a registered\n");
text += Common::UString::format("trademark of BioWare Corp., a subsidiary of Electronic Arts, Inc. Sonic the\n");
text += Common::UString::format("Hedgehog is a registered trademark of Sega Corporation. The Witcher is a\n");
text += Common::UString::format("registered trademark of CD Projekt S.A. Dragon Age is a registered trademark\n");
text += Common::UString::format("of Electronic Arts, Inc. All rights reserved.");

return text;
}

Common::UString createHelpText(const char *name) {
Common::UString text;

text += Common::UString::sprintf("%s - A FLOSS resource explorer for BioWare's Aurora engine games\n", PHAETHON_NAME);
text += Common::UString::sprintf("Usage: %s [options] [<path>]\n", name);
text += Common::UString::sprintf(" -h --help Display this text and exit.\n");
text += Common::UString::sprintf(" -v --version Display version information and exit.");
text += Common::UString::format("%s - A FLOSS resource explorer for BioWare's Aurora engine games\n", PHAETHON_NAME);
text += Common::UString::format("Usage: %s [options] [<path>]\n", name);
text += Common::UString::format(" -h --help Display this text and exit.\n");
text += Common::UString::format(" -v --version Display version information and exit.");

return text;
}
2 changes: 1 addition & 1 deletion src/common/filepath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ UString FilePath::getHumanReadableSize(uint32 size) {
s /= 1024;
}

return UString::sprintf("%.2lf%s", s, sizes[n]);
return UString::format("%.2lf%s", s, sizes[n]);
}

} // End of namespace Common
2 changes: 1 addition & 1 deletion src/common/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static inline uint64 hashString(const UString &string, HashAlgo algo, Encoding e
}

static inline UString formatHash(uint64 hash) {
return UString::sprintf("0x%04X%04X%04X%04X",
return UString::format("0x%04X%04X%04X%04X",
(uint) ((hash >> 48) & 0xFFFF),
(uint) ((hash >> 32) & 0xFFFF),
(uint) ((hash >> 16) & 0xFFFF),
Expand Down
2 changes: 1 addition & 1 deletion src/common/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ UString UString::substr(iterator from, iterator to) const {
return sub;
}

UString UString::sprintf(const char *s, ...) {
UString UString::format(const char *s, ...) {
char buf[STRINGBUFLEN];
va_list va;

Expand Down
4 changes: 2 additions & 2 deletions src/common/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ class UString {

UString substr(iterator from, iterator to) const;

/** Formatted printer, works like sprintf(). */
static UString sprintf(const char *s, ...);
/** Print formatted data into an UString object, similar to sprintf(). */
static UString format(const char *s, ...);

static uint32 split(const UString &text, uint32 delim, std::vector<UString> &texts);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/panelpreviewimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void PanelPreviewImage::zoomFit(bool onlyWidth, bool grow) {
}

void PanelPreviewImage::updateZoomLevelText() {
Common::UString percent = Common::UString::sprintf("%d%%", (int) (getCurrentZoomLevel() * 100));
Common::UString percent = Common::UString::format("%d%%", (int) (getCurrentZoomLevel() * 100));

_textZoomLevel->SetLabel(percent);
_textZoomLevel->Fit();
Expand Down
12 changes: 6 additions & 6 deletions src/gui/panelpreviewsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Common::UString PanelPreviewSound::formatTime(uint64 t) {

uint32 h = t;

return Common::UString::sprintf("%02u:%02u:%02u.%03u", h, m, s, ms);
return Common::UString::format("%02u:%02u:%02u.%03u", h, m, s, ms);
}

Common::UString PanelPreviewSound::formatPercent(uint64 total, uint64 t) {
Expand All @@ -167,7 +167,7 @@ Common::UString PanelPreviewSound::formatPercent(uint64 total, uint64 t) {

uint percent = CLIP<uint>((t * 100) / total, 0, 100);

return Common::UString::sprintf("%3u%%", percent);
return Common::UString::format("%3u%%", percent);
}

int PanelPreviewSound::getSliderPos(uint64 total, uint64 t) {
Expand All @@ -188,9 +188,9 @@ void PanelPreviewSound::update() {
Common::UString total = formatTime(_duration);
Common::UString percent = formatPercent(_duration, t);

_textPosition->SetLabelMarkup(Common::UString::sprintf("<tt>%s</tt>", played.c_str()));
_textPercent->SetLabelMarkup(Common::UString::sprintf("<tt>%s</tt>", percent.c_str()));
_textDuration->SetLabelMarkup(Common::UString::sprintf("<tt>%s</tt>", total.c_str()));
_textPosition->SetLabelMarkup(Common::UString::format("<tt>%s</tt>", played.c_str()));
_textPercent->SetLabelMarkup(Common::UString::format("<tt>%s</tt>", percent.c_str()));
_textDuration->SetLabelMarkup(Common::UString::format("<tt>%s</tt>", total.c_str()));

_sliderPosition->SetValue(getSliderPos(_duration, t));

Expand All @@ -203,7 +203,7 @@ void PanelPreviewSound::update() {
void PanelPreviewSound::setVolume() {
double volume = _sliderVolume->GetValue() / (double)_sliderVolume->GetMax();

Common::UString label = Common::UString::sprintf("<tt>%3d%%</tt>", (int) (volume * 100));
Common::UString label = Common::UString::format("<tt>%3d%%</tt>", (int) (volume * 100));
_textVolume->SetLabelMarkup(label);

SoundMan.setListenerGain(volume);
Expand Down
12 changes: 6 additions & 6 deletions src/gui/panelresourceinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,25 @@ Common::UString PanelResourceInfo::getSizeLabel(uint32 size) {
return "-";

if (size < 1024)
return Common::UString::sprintf("%u", size);
return Common::UString::format("%u", size);

Common::UString humanRead = Common::FilePath::getHumanReadableSize(size);

return Common::UString::sprintf("%s (%u)", humanRead.c_str(), size);
return Common::UString::format("%s (%u)", humanRead.c_str(), size);
}

Common::UString PanelResourceInfo::getFileTypeLabel(Aurora::FileType type) {
Common::UString label = Common::UString::sprintf("%d", type);
Common::UString label = Common::UString::format("%d", type);
if (type != Aurora::kFileTypeNone)
label += Common::UString::sprintf(" (%s)", TypeMan.getExtension(type).c_str());
label += Common::UString::format(" (%s)", TypeMan.getExtension(type).c_str());

return label;
}

Common::UString PanelResourceInfo::getResTypeLabel(Aurora::ResourceType type) {
Common::UString label = Common::UString::sprintf("%d", type);
Common::UString label = Common::UString::format("%d", type);
if (type != Aurora::kResourceNone)
label += Common::UString::sprintf(" (%s)", getResourceTypeDescription(type).c_str());
label += Common::UString::format(" (%s)", getResourceTypeDescription(type).c_str());

return label;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sound/decoders/asf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ASFGUID {
}

Common::UString toString() const {
return Common::UString::sprintf("%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x",
return Common::UString::format("%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x",
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7], id[8], id[9], id[10], id[11], id[12], id[13], id[14], id[15]);
}

Expand Down

0 comments on commit 3d58943

Please sign in to comment.