Skip to content

Commit

Permalink
Mark StringUtils::format deprecated, use fmt::format instead
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Jul 13, 2024
1 parent 01d223a commit e1da1d3
Show file tree
Hide file tree
Showing 45 changed files with 141 additions and 140 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Rename all AXLOG/printf to AXLOGD (without .\core, .\3rdparty) by @aismann in https://github.com/axmolengine/axmol/pull/2020
- Set several log messages to verbose level by @rh101 in https://github.com/axmolengine/axmol/pull/2021
- Change AXLOGI to more appropriate AXLOGD for several log calls by @rh101 in https://github.com/axmolengine/axmol/pull/2028
- `StringUtils::format`, use `fmt::format` instead.

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion core/2d/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Action::~Action()

std::string Action::description() const
{
return StringUtils::format("<Action | Tag = %d", _tag);
return fmt::format("<Action | Tag = {}", _tag);
}

void Action::startWithTarget(Node* aTarget)
Expand Down
2 changes: 1 addition & 1 deletion core/2d/FastTMXLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ void FastTMXLayer::setupTileSprite(Sprite* sprite, const Vec2& pos, uint32_t gid

std::string FastTMXLayer::getDescription() const
{
return StringUtils::format("<FastTMXLayer | tag = %d, size = %d,%d>", _tag, (int)_mapTileSize.width,
return fmt::format("<FastTMXLayer | tag = {}, size = {},{}>", _tag, (int)_mapTileSize.width,
(int)_mapTileSize.height);
}

Expand Down
2 changes: 1 addition & 1 deletion core/2d/FastTMXTiledMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Value FastTMXTiledMap::getPropertiesForGID(int GID) const

std::string FastTMXTiledMap::getDescription() const
{
return StringUtils::format("<FastTMXTiledMap | Tag = %d, Layers = %d", _tag, static_cast<int>(_children.size()));
return fmt::format("<FastTMXTiledMap | Tag = {}, Layers = {}", _tag, static_cast<int>(_children.size()));
}

void FastTMXTiledMap::setTileAnimEnabled(bool enabled)
Expand Down
6 changes: 3 additions & 3 deletions core/2d/FontFNT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ BMFontConfiguration::~BMFontConfiguration()

std::string BMFontConfiguration::description() const
{
return StringUtils::format(
"<BMFontConfiguration = " AX_FORMAT_PRINTF_SIZE_T " | Glphys:%d Kernings:%d | Image = %s>", (size_t)this,
static_cast<int>(_fontDefDictionary.size()), static_cast<int>(_kerningDictionary.size()), _atlasName.c_str());
return fmt::format(
"<BMFontConfiguration = " AX_FORMAT_PRINTF_SIZE_T " | Glphys:{} Kernings:{} | Image = {}>", (size_t)this,
static_cast<int>(_fontDefDictionary.size()), static_cast<int>(_kerningDictionary.size()), _atlasName);
}

void BMFontConfiguration::purgeKerningDictionary()
Expand Down
2 changes: 1 addition & 1 deletion core/2d/LabelAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void LabelAtlas::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)

std::string LabelAtlas::getDescription() const
{
return StringUtils::format("<LabelAtlas | Tag = %d, Label = '%s'>", _tag, _string.c_str());
return fmt::format("<LabelAtlas | Tag = {}, Label = '{}'>", _tag, _string);
}

NS_AX_END
4 changes: 2 additions & 2 deletions core/2d/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void LayerGradient::setCompressedInterpolation(bool compress)

std::string LayerGradient::getDescription() const
{
return StringUtils::format("<LayerGradient | Tag = %d>", _tag);
return fmt::format("<LayerGradient | Tag = {}>", _tag);
}

/**
Expand Down Expand Up @@ -750,7 +750,7 @@ void LayerMultiplex::switchToAndReleaseMe(int n)

std::string LayerMultiplex::getDescription() const
{
return StringUtils::format("<LayerMultiplex | Tag = %d, Layers = %d", _tag, static_cast<int>(_children.size()));
return fmt::format("<LayerMultiplex | Tag = {}, Layers = {}", _tag, static_cast<int>(_children.size()));
}

NS_AX_END
2 changes: 1 addition & 1 deletion core/2d/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ bool Menu::isOpacityModifyRGB() const

std::string Menu::getDescription() const
{
return StringUtils::format("<Menu | Tag = %d>", _tag);
return fmt::format("<Menu | Tag = {}>", _tag);
}

NS_AX_END
2 changes: 1 addition & 1 deletion core/2d/MenuItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void MenuItem::setCallback(const ccMenuCallback& callback)

std::string MenuItem::getDescription() const
{
return StringUtils::format("<MenuItem | tag = %d>", _tag);
return fmt::format("<MenuItem | tag = {}>", _tag);
}

//
Expand Down
2 changes: 1 addition & 1 deletion core/2d/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void Node::cleanup()

std::string Node::getDescription() const
{
return StringUtils::format("<Node | Tag = %d", _tag);
return fmt::format("<Node | Tag = {}", _tag);
}

// MARK: getters / setters
Expand Down
2 changes: 1 addition & 1 deletion core/2d/ParticleSystemQuad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,6 @@ ParticleSystemQuad* ParticleSystemQuad::create()

std::string ParticleSystemQuad::getDescription() const
{
return StringUtils::format("<ParticleSystemQuad | Tag = %d, Total Particles = %d>", _tag, _totalParticles);
return fmt::format("<ParticleSystemQuad | Tag = {}, Total Particles = {}>", _tag, _totalParticles);
}
NS_AX_END
2 changes: 1 addition & 1 deletion core/2d/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Scene* Scene::createWithSize(const Vec2& size)

std::string Scene::getDescription() const
{
return StringUtils::format("<Scene | tag = %d>", _tag);
return fmt::format("<Scene | tag = {}>", _tag);
}

void Scene::onProjectionChanged(EventCustom* /*event*/)
Expand Down
2 changes: 1 addition & 1 deletion core/2d/SpriteBatchNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ SpriteBatchNode* SpriteBatchNode::addSpriteWithoutQuad(Sprite* child, int z, int

std::string SpriteBatchNode::getDescription() const
{
return StringUtils::format("<SpriteBatchNode | tag = %d>", _tag);
return fmt::format("<SpriteBatchNode | tag = {}>", _tag);
}

NS_AX_END
6 changes: 3 additions & 3 deletions core/base/SimpleTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TIMER_ID loop(unsigned int n, float interval, vcallback_t callback, bool bNative

auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId);

std::string key = StringUtils::format("STMR#%p", timerId);
std::string key = fmt::format("STMR#{}", fmt::ptr(timerId));

Director::getInstance()->getScheduler()->schedule(
[timerObj](float /*dt*/) { // lambda expression hold the reference of timerObj automatically.
Expand All @@ -69,7 +69,7 @@ TIMER_ID delay(float delay, vcallback_t callback, bool bNative)
yasio::ref_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)));
auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId);

std::string key = StringUtils::format("STMR#%p", timerId);
std::string key = fmt::format("STMR#{}", fmt::ptr(timerId));
Director::getInstance()->getScheduler()->schedule(
[timerObj](float /*dt*/) { // lambda expression hold the reference of timerObj automatically.
timerObj->callback_();
Expand All @@ -83,7 +83,7 @@ TIMER_ID delay(float delay, vcallback_t callback, bool bNative)

void kill(TIMER_ID timerId, bool bNative)
{
std::string key = StringUtils::format("STMR#%p", timerId);
std::string key = fmt::format("STMR#{}", fmt::ptr(timerId));
Director::getInstance()->getScheduler()->unschedule(key, STIMER_TARGET(bNative));
}

Expand Down
4 changes: 2 additions & 2 deletions core/network/Downloader-curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,8 @@ void DownloaderCURL::_onDownloadFinished(DownloadTask& task, int checkState)
coTask._errCode = DownloadTask::ERROR_CHECK_SUM_FAILED;
coTask._errCodeInternal = 0;
coTask._errDescription =
StringUtils::format("Check file: %s md5 failed, required:%s, real:%s", coTask._fileName.c_str(),
task.checksum.c_str(), realMd5.c_str());
fmt::format("Check file: {} md5 failed, required:{}, real:{}", coTask._fileName,
task.checksum, realMd5);

pFileUtils->removeFile(coTask._checksumFileName);
pFileUtils->removeFile(coTask._tempFileName);
Expand Down
4 changes: 2 additions & 2 deletions core/platform/GLViewImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,11 @@ void GLViewImpl::onGLFWError(int errorID, const char* errorDesc)
{
if (_mainWindow)
{
_glfwError = StringUtils::format("GLFWError #%d Happen, %s", errorID, errorDesc);
_glfwError = fmt::format("GLFWError #{} Happen, {}", errorID, errorDesc);
}
else
{
_glfwError.append(StringUtils::format("GLFWError #%d Happen, %s\n", errorID, errorDesc));
_glfwError.append(fmt::format("GLFWError #{} Happen, {}\n", errorID, errorDesc));
}
AXLOGE("{}", _glfwError);
}
Expand Down
2 changes: 1 addition & 1 deletion core/platform/PlatformMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public: \
#define __AXLOGWITHFUNCTION(s, ...) \
ax::print("%s : %s", __FUNCTION__, ax::StringUtils::format(s, ##__VA_ARGS__).c_str())

/// @name Cocos2d debug, deprecated since axmol 2.1.4, use AXLOGD, AXLOGI, AXLOGW, ... instead
/// @name legacy log macros, deprecated since axmol 2.1.4, use AXLOGD, AXLOGI, AXLOGW, ... instead
/// @{
#if !defined(_AX_DEBUG) || _AX_DEBUG == 0
# define AXLOG(...) \
Expand Down
2 changes: 1 addition & 1 deletion core/renderer/TextureAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bool TextureAtlas::initWithTexture(Texture2D* texture, ssize_t capacity)

std::string TextureAtlas::getDescription() const
{
return StringUtils::format("<TextureAtlas | totalQuads = %d>", static_cast<int>(_totalQuads));
return fmt::format("<TextureAtlas | totalQuads = {}>", static_cast<int>(_totalQuads));
}

void TextureAtlas::setupIndices()
Expand Down
2 changes: 1 addition & 1 deletion core/renderer/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TextureCache::~TextureCache()

std::string TextureCache::getDescription() const
{
return StringUtils::format("<TextureCache | Number of textures = %d>", static_cast<int>(_textures.size()));
return fmt::format("<TextureCache | Number of textures = {}>", static_cast<int>(_textures.size()));
}

struct TextureCache::AsyncStruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ AssetsManagerEx::AssetsManagerEx(std::string_view manifestUrl, std::string_view
{
// Init variables
_eventDispatcher = Director::getInstance()->getEventDispatcher();
std::string pointer = StringUtils::format("%p", this);
std::string pointer = fmt::format("{}", fmt::ptr(this));
_eventName = EventListenerAssetsManagerEx::LISTENER_ID + pointer;
_fileUtils = FileUtils::getInstance();

Expand Down Expand Up @@ -765,8 +765,8 @@ void AssetsManagerEx::startUpdate()
_totalWaitToDownload = _totalToDownload = (int)_downloadUnits.size();
this->batchDownload();

std::string msg = StringUtils::format(
"Resuming from previous unfinished update, %d files remains to be finished.", _totalToDownload);
std::string msg = fmt::format(
"Resuming from previous unfinished update, {} files remains to be finished.", _totalToDownload);
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION, "", msg);
}
else
Expand Down Expand Up @@ -818,7 +818,7 @@ void AssetsManagerEx::startUpdate()
_totalWaitToDownload = _totalToDownload = (int)_downloadUnits.size();
this->batchDownload();

std::string msg = StringUtils::format("Start to update %d files from remote package.", _totalToDownload);
std::string msg = fmt::format("Start to update {} files from remote package.", _totalToDownload);
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION, "", msg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool EventListenerAssetsManagerEx::init(const AssetsManagerEx* AssetsManagerEx,
EventAssetsManagerEx* eventAssetsManagerEx = dynamic_cast<EventAssetsManagerEx*>(event);
_onAssetsManagerExEvent(eventAssetsManagerEx);
};
std::string pointer = StringUtils::format("%p", AssetsManagerEx);
std::string pointer = fmt::format("{}", fmt::ptr(AssetsManagerEx));
if (EventListenerCustom::init(LISTENER_ID + pointer, func))
{
ret = true;
Expand Down
20 changes: 10 additions & 10 deletions extensions/cocostudio/src/cocostudio/ActionTimeline/CSLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,8 @@ Node* CSLoader::createNode(const Data& data, const ccNodeLoadCallback& callback)
}
});
# if _AX_DEBUG > 0
auto prompt = StringUtils::format(
"%s%s%s%s%s%s%s%s%s%s", "The reader build id of your Cocos exported file(", csBuildId->c_str(),
std::string prompt = fmt::format(
"{}{}{}{}{}{}{}{}{}{}", "The reader build id of your Cocos exported file(", csBuildId->c_str(),
") and the reader build id in your axmol(", loader->_csBuildID.c_str(),
") are not match.\n", "Please get the correct reader(build id ", csBuildId->c_str(), ")from ",
"https://github.com/axmolengine/axmol", " and replace it in your axmol");
Expand Down Expand Up @@ -1057,18 +1057,18 @@ Node* CSLoader::nodeWithFlatBuffersFile(std::string_view fileName, const ccNodeL
}
});
# if _AX_DEBUG > 0
auto prompt = StringUtils::format(
auto prompt = fmt::format(
"%s%s%s%s%s%s%s%s%s%s", "The reader build id of your Cocos exported file(", csBuildId->c_str(),
") and the reader build id in your axmol(", _csBuildID.c_str(), ") are not match.\n",
") and the reader build id in your axmol(", _csBuildID, ") are not match.\n",
"Please get the correct reader(build id ", csBuildId->c_str(), ")from ",
"https://github.com/axmolengine/axmol", " and replace it in your axmol");
AXASSERT(readerVersion >= writterVersion, prompt.c_str());
#endif
if (readerVersion < writterVersion)
{
auto exceptionMsg =
StringUtils::format("error: The csloader version not match, require version is:%s, but %s provided!",
csBuildId->c_str(), _csBuildID.c_str());
fmt::format("error: The csloader version not match, require version is:{}, but {} provided!",
csBuildId->c_str(), _csBuildID);
throw std::logic_error(exceptionMsg.c_str());
return nullptr;
}
Expand Down Expand Up @@ -1169,17 +1169,17 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree, const
}
else
{
auto exceptionMsg = StringUtils::format(
R"(error: Missing custom reader class name:%s, please config at your project fiile xxx.xsxproj like follow:
auto exceptionMsg = fmt::format(
R"(error: Missing custom reader class name:{}, please config at your project fiile xxx.xsxproj like follow:
<Project>
<publish-opts>
<custom-readers>
<item>%s</item>
<item>{}</item>
</custom-readers>
</publish-opts>
</Project>
)",
readername.c_str(), readername.c_str());
readername, readername);
throw std::logic_error(exceptionMsg.c_str());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Node* GameMapReader::createNodeWithFlatBuffers(const flatbuffers::Table* gameMap
Node* node = Node::create();
setPropsWithFlatBuffers(node, (Table*)gameMapOptions);
auto label = Label::create();
label->setString(StringUtils::format("Some error of gid are in TMX Layer '%s'", layerName.c_str()));
label->setString(fmt::format("Some error of gid are in TMX Layer '{}'", layerName));
node->setScale(1.0f);
node->addChild(label);
return node;
Expand Down
4 changes: 2 additions & 2 deletions extensions/fairygui/src/fairygui/UIPackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ GObject* UIPackage::createObject(const string& resName)
{
PackageItem* pi = getItemByName(resName);
# if _AX_DEBUG > 0
auto msg = StringUtils::format("FairyGUI: resource not found - %s in %s",
resName.c_str(), _name.c_str());
auto msg = fmt::format("FairyGUI: resource not found - {} in {}",
resName, _name);
AXASSERT(pi, msg.c_str());
# endif
return createObject(pi);
Expand Down
10 changes: 5 additions & 5 deletions tests/cpp-tests/Source/ActionsTest/ActionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2433,7 +2433,7 @@ void ActionCoroutineTest::onEnter()

auto s = Director::getInstance()->getWinSize();
_label =
Label::createWithTTF(StringUtils::format("frame count : %" PRIu64 ")", _frameCount), "fonts/Marker Felt.ttf", 16.0f);
Label::createWithTTF(fmt::format("frame count : {}", _frameCount), "fonts/Marker Felt.ttf", 16.0f);
_label->setPosition(s.width / 2, s.height / 2 + 100);
addChild(_label, 1, 1);

Expand All @@ -2443,7 +2443,7 @@ void ActionCoroutineTest::onEnter()
void ActionCoroutineTest::update(float delta)
{
_frameCount++;
_label->setString(StringUtils::format("frame count : %" PRIu64 "", _frameCount));
_label->setString(fmt::format("frame count : {}", _frameCount));
}

std::string ActionCoroutineTest::title() const
Expand All @@ -2461,19 +2461,19 @@ Coroutine ActionCoroutineTest::coroutineCallback()
auto s = Director::getInstance()->getWinSize();

auto label1 =
Label::createWithTTF(StringUtils::format("First (%" PRIu64 ")", _frameCount), "fonts/Marker Felt.ttf", 16.0f);
Label::createWithTTF(fmt::format("First ({})", _frameCount), "fonts/Marker Felt.ttf", 16.0f);
label1->setPosition(s.width / 4 * 1, s.height / 2);
addChild(label1);
co_yield DelayTime::create(3.0f); // delay 3s

auto label2 =
Label::createWithTTF(StringUtils::format("after 3sec (%" PRIu64 ")", _frameCount), "fonts/Marker Felt.ttf", 16.0f);
Label::createWithTTF(fmt::format("after 3sec ({})", _frameCount), "fonts/Marker Felt.ttf", 16.0f);
label2->setPosition(s.width / 4 * 2, s.height / 2);
addChild(label2);
co_yield nullptr; // next frame

auto label3 =
Label::createWithTTF(StringUtils::format("next frame (%" PRIu64 ")", _frameCount), "fonts/Marker Felt.ttf", 16.0f);
Label::createWithTTF(fmt::format("next frame ({})", _frameCount), "fonts/Marker Felt.ttf", 16.0f);
label3->setPosition(s.width / 4 * 3, s.height / 2);
addChild(label3);

Expand Down
6 changes: 3 additions & 3 deletions tests/cpp-tests/Source/BaseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void TestList::addTest(std::string_view testName, std::function<TestBase*()> cal
if (!testName.empty())
{
_childTestNames.emplace_back(
StringUtils::format("%d:%s", static_cast<int>(_childTestNames.size() + 1), testName.data()));
fmt::format("{}:{}", static_cast<int>(_childTestNames.size() + 1), testName));
_testCallbacks.emplace_back(callback);
}
}
Expand Down Expand Up @@ -465,8 +465,8 @@ void TestCase::onEnter()

if (_testSuite)
{
_titleLabel->setString(StringUtils::format("%d", static_cast<int>(_testSuite->getCurrTestIndex() + 1)) + ":" +
title());
_titleLabel->setString(fmt::format("{}:{}", static_cast<int>(_testSuite->getCurrTestIndex() + 1),
title()));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp-tests/Source/CurlTest/CurlTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void CurlTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
curl_easy_cleanup(curl);
if (res == 0)
{
_label->setString(StringUtils::format("Connect successfully!\n%s", chunk.memory));
_label->setString(fmt::format("Connect successfully!\n{}", chunk.memory));
}
else
{
Expand Down
Loading

0 comments on commit e1da1d3

Please sign in to comment.