From e1da1d375407336e5dcca63a99e5fb9f2d1464d1 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 13 Jul 2024 09:51:54 +0800 Subject: [PATCH] Mark StringUtils::format deprecated, use fmt::format instead --- CHANGELOG.md | 1 + core/2d/Action.cpp | 2 +- core/2d/FastTMXLayer.cpp | 2 +- core/2d/FastTMXTiledMap.cpp | 2 +- core/2d/FontFNT.cpp | 6 +-- core/2d/LabelAtlas.cpp | 2 +- core/2d/Layer.cpp | 4 +- core/2d/Menu.cpp | 2 +- core/2d/MenuItem.cpp | 2 +- core/2d/Node.cpp | 2 +- core/2d/ParticleSystemQuad.cpp | 2 +- core/2d/Scene.cpp | 2 +- core/2d/SpriteBatchNode.cpp | 2 +- core/base/SimpleTimer.cpp | 6 +-- core/network/Downloader-curl.cpp | 4 +- core/platform/GLViewImpl.cpp | 4 +- core/platform/PlatformMacros.h | 2 +- core/renderer/TextureAtlas.cpp | 2 +- core/renderer/TextureCache.cpp | 2 +- .../src/assets-manager/AssetsManagerEx.cpp | 8 +-- .../EventListenerAssetsManagerEx.cpp | 2 +- .../cocostudio/ActionTimeline/CSLoader.cpp | 20 +++---- .../GameMapReader/GameMapReader.cpp | 2 +- .../fairygui/src/fairygui/UIPackage.cpp | 4 +- .../Source/ActionsTest/ActionsTest.cpp | 10 ++-- tests/cpp-tests/Source/BaseTest.cpp | 6 +-- tests/cpp-tests/Source/CurlTest/CurlTest.cpp | 2 +- .../AssetsManagerExTest.cpp | 6 +-- .../TableViewTest/TableViewTestScene.cpp | 2 +- .../Source/LabelTest/LabelTestNew.cpp | 6 +-- .../MaterialSystemTest/MaterialSystemTest.cpp | 2 +- .../DownloaderTest/DownloaderTest.cpp | 2 +- .../WebSocketTest/WebSocketTest.cpp | 2 +- .../NewAudioEngineTest/NewAudioEngineTest.cpp | 12 ++--- .../Source/PhysicsTest/PhysicsTest.cpp | 2 +- .../SpriteFrameCacheTest.cpp | 4 +- .../UIButtonTest/UIButtonTest.cpp | 2 +- .../UIImageViewTest/UIImageViewTest.cpp | 2 +- .../UIListViewTest/UIListViewTest.cpp | 54 +++++++++---------- .../UIPageViewTest/UIPageViewTest.cpp | 42 +++++++-------- .../UIRadioButtonTest/UIRadioButtonTest.cpp | 10 ++-- .../UISliderTest/UISliderTest.cpp | 8 +-- .../UITextFieldTest/UITextFieldTest.cpp | 8 +-- .../Source/VibrateTest/VibrateTest.cpp | 4 +- .../Source/WindowTest/WindowTest.cpp | 8 +-- 45 files changed, 141 insertions(+), 140 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c474aab7e3cc..b78dc824fa6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/core/2d/Action.cpp b/core/2d/Action.cpp index 07dbc0f3d598..605e317a1c22 100644 --- a/core/2d/Action.cpp +++ b/core/2d/Action.cpp @@ -47,7 +47,7 @@ Action::~Action() std::string Action::description() const { - return StringUtils::format("", _tag, (int)_mapTileSize.width, + return fmt::format("", _tag, (int)_mapTileSize.width, (int)_mapTileSize.height); } diff --git a/core/2d/FastTMXTiledMap.cpp b/core/2d/FastTMXTiledMap.cpp index 2359d6912536..f6a51b15e9a0 100644 --- a/core/2d/FastTMXTiledMap.cpp +++ b/core/2d/FastTMXTiledMap.cpp @@ -260,7 +260,7 @@ Value FastTMXTiledMap::getPropertiesForGID(int GID) const std::string FastTMXTiledMap::getDescription() const { - return StringUtils::format("(_children.size())); + return fmt::format("(_children.size())); } void FastTMXTiledMap::setTileAnimEnabled(bool enabled) diff --git a/core/2d/FontFNT.cpp b/core/2d/FontFNT.cpp index 232324e5b8a6..755fdfc09ef1 100644 --- a/core/2d/FontFNT.cpp +++ b/core/2d/FontFNT.cpp @@ -126,9 +126,9 @@ BMFontConfiguration::~BMFontConfiguration() std::string BMFontConfiguration::description() const { - return StringUtils::format( - "", (size_t)this, - static_cast(_fontDefDictionary.size()), static_cast(_kerningDictionary.size()), _atlasName.c_str()); + return fmt::format( + "", (size_t)this, + static_cast(_fontDefDictionary.size()), static_cast(_kerningDictionary.size()), _atlasName); } void BMFontConfiguration::purgeKerningDictionary() diff --git a/core/2d/LabelAtlas.cpp b/core/2d/LabelAtlas.cpp index abe1f78fbd45..cdd6e6804b9d 100644 --- a/core/2d/LabelAtlas.cpp +++ b/core/2d/LabelAtlas.cpp @@ -283,7 +283,7 @@ void LabelAtlas::draw(Renderer* renderer, const Mat4& transform, uint32_t flags) std::string LabelAtlas::getDescription() const { - return StringUtils::format("", _tag, _string.c_str()); + return fmt::format("", _tag, _string); } NS_AX_END diff --git a/core/2d/Layer.cpp b/core/2d/Layer.cpp index cc18c16b0b32..a7a5a802fad3 100644 --- a/core/2d/Layer.cpp +++ b/core/2d/Layer.cpp @@ -336,7 +336,7 @@ void LayerGradient::setCompressedInterpolation(bool compress) std::string LayerGradient::getDescription() const { - return StringUtils::format("", _tag); + return fmt::format("", _tag); } /** @@ -750,7 +750,7 @@ void LayerMultiplex::switchToAndReleaseMe(int n) std::string LayerMultiplex::getDescription() const { - return StringUtils::format("(_children.size())); + return fmt::format("(_children.size())); } NS_AX_END diff --git a/core/2d/Menu.cpp b/core/2d/Menu.cpp index b2c10a5388fc..49b259760e0d 100644 --- a/core/2d/Menu.cpp +++ b/core/2d/Menu.cpp @@ -555,7 +555,7 @@ bool Menu::isOpacityModifyRGB() const std::string Menu::getDescription() const { - return StringUtils::format("", _tag); + return fmt::format("", _tag); } NS_AX_END diff --git a/core/2d/MenuItem.cpp b/core/2d/MenuItem.cpp index 92412406a638..6eb7b4d50f84 100644 --- a/core/2d/MenuItem.cpp +++ b/core/2d/MenuItem.cpp @@ -125,7 +125,7 @@ void MenuItem::setCallback(const ccMenuCallback& callback) std::string MenuItem::getDescription() const { - return StringUtils::format("", _tag); + return fmt::format("", _tag); } // diff --git a/core/2d/Node.cpp b/core/2d/Node.cpp index 33cd046cc445..2976a97357ef 100644 --- a/core/2d/Node.cpp +++ b/core/2d/Node.cpp @@ -240,7 +240,7 @@ void Node::cleanup() std::string Node::getDescription() const { - return StringUtils::format("", _tag, _totalParticles); + return fmt::format("", _tag, _totalParticles); } NS_AX_END diff --git a/core/2d/Scene.cpp b/core/2d/Scene.cpp index 3014f92c7d41..d916ec081e31 100644 --- a/core/2d/Scene.cpp +++ b/core/2d/Scene.cpp @@ -154,7 +154,7 @@ Scene* Scene::createWithSize(const Vec2& size) std::string Scene::getDescription() const { - return StringUtils::format("", _tag); + return fmt::format("", _tag); } void Scene::onProjectionChanged(EventCustom* /*event*/) diff --git a/core/2d/SpriteBatchNode.cpp b/core/2d/SpriteBatchNode.cpp index 53f7d8067700..9352bd51ae23 100644 --- a/core/2d/SpriteBatchNode.cpp +++ b/core/2d/SpriteBatchNode.cpp @@ -784,7 +784,7 @@ SpriteBatchNode* SpriteBatchNode::addSpriteWithoutQuad(Sprite* child, int z, int std::string SpriteBatchNode::getDescription() const { - return StringUtils::format("", _tag); + return fmt::format("", _tag); } NS_AX_END diff --git a/core/base/SimpleTimer.cpp b/core/base/SimpleTimer.cpp index 4dbf13d9c734..6bd673b182c5 100644 --- a/core/base/SimpleTimer.cpp +++ b/core/base/SimpleTimer.cpp @@ -49,7 +49,7 @@ TIMER_ID loop(unsigned int n, float interval, vcallback_t callback, bool bNative auto timerId = reinterpret_cast(++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. @@ -69,7 +69,7 @@ TIMER_ID delay(float delay, vcallback_t callback, bool bNative) yasio::ref_ptr timerObj(new TimerObject(std::move(callback))); auto timerId = reinterpret_cast(++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_(); @@ -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)); } diff --git a/core/network/Downloader-curl.cpp b/core/network/Downloader-curl.cpp index 3babb99047c8..5fa8416d1996 100644 --- a/core/network/Downloader-curl.cpp +++ b/core/network/Downloader-curl.cpp @@ -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); diff --git a/core/platform/GLViewImpl.cpp b/core/platform/GLViewImpl.cpp index 1b1bc94a6f16..ebd5cafdcb6e 100644 --- a/core/platform/GLViewImpl.cpp +++ b/core/platform/GLViewImpl.cpp @@ -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); } diff --git a/core/platform/PlatformMacros.h b/core/platform/PlatformMacros.h index 4a680a99208d..401193803702 100644 --- a/core/platform/PlatformMacros.h +++ b/core/platform/PlatformMacros.h @@ -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(...) \ diff --git a/core/renderer/TextureAtlas.cpp b/core/renderer/TextureAtlas.cpp index dbfbb798e852..fc7503c748e8 100644 --- a/core/renderer/TextureAtlas.cpp +++ b/core/renderer/TextureAtlas.cpp @@ -182,7 +182,7 @@ bool TextureAtlas::initWithTexture(Texture2D* texture, ssize_t capacity) std::string TextureAtlas::getDescription() const { - return StringUtils::format("", static_cast(_totalQuads)); + return fmt::format("", static_cast(_totalQuads)); } void TextureAtlas::setupIndices() diff --git a/core/renderer/TextureCache.cpp b/core/renderer/TextureCache.cpp index 8f25c56fa081..2e0abe92cd35 100644 --- a/core/renderer/TextureCache.cpp +++ b/core/renderer/TextureCache.cpp @@ -76,7 +76,7 @@ TextureCache::~TextureCache() std::string TextureCache::getDescription() const { - return StringUtils::format("", static_cast(_textures.size())); + return fmt::format("", static_cast(_textures.size())); } struct TextureCache::AsyncStruct diff --git a/extensions/assets-manager/src/assets-manager/AssetsManagerEx.cpp b/extensions/assets-manager/src/assets-manager/AssetsManagerEx.cpp index 0da7bbf5f128..efe053a47cd1 100644 --- a/extensions/assets-manager/src/assets-manager/AssetsManagerEx.cpp +++ b/extensions/assets-manager/src/assets-manager/AssetsManagerEx.cpp @@ -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(); @@ -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 @@ -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); } } diff --git a/extensions/assets-manager/src/assets-manager/EventListenerAssetsManagerEx.cpp b/extensions/assets-manager/src/assets-manager/EventListenerAssetsManagerEx.cpp index a7be26582f73..b1631c349b95 100644 --- a/extensions/assets-manager/src/assets-manager/EventListenerAssetsManagerEx.cpp +++ b/extensions/assets-manager/src/assets-manager/EventListenerAssetsManagerEx.cpp @@ -64,7 +64,7 @@ bool EventListenerAssetsManagerEx::init(const AssetsManagerEx* AssetsManagerEx, EventAssetsManagerEx* eventAssetsManagerEx = dynamic_cast(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; diff --git a/extensions/cocostudio/src/cocostudio/ActionTimeline/CSLoader.cpp b/extensions/cocostudio/src/cocostudio/ActionTimeline/CSLoader.cpp index e31b6aaa9fae..137742df050c 100644 --- a/extensions/cocostudio/src/cocostudio/ActionTimeline/CSLoader.cpp +++ b/extensions/cocostudio/src/cocostudio/ActionTimeline/CSLoader.cpp @@ -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"); @@ -1057,9 +1057,9 @@ 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()); @@ -1067,8 +1067,8 @@ Node* CSLoader::nodeWithFlatBuffersFile(std::string_view fileName, const ccNodeL 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; } @@ -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: - %s + {} )", - readername.c_str(), readername.c_str()); + readername, readername); throw std::logic_error(exceptionMsg.c_str()); } diff --git a/extensions/cocostudio/src/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp b/extensions/cocostudio/src/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp index 98ca5f7525f6..a177a6b890d8 100644 --- a/extensions/cocostudio/src/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp +++ b/extensions/cocostudio/src/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp @@ -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; diff --git a/extensions/fairygui/src/fairygui/UIPackage.cpp b/extensions/fairygui/src/fairygui/UIPackage.cpp index de6d6a21fa55..07ffbb6899dd 100644 --- a/extensions/fairygui/src/fairygui/UIPackage.cpp +++ b/extensions/fairygui/src/fairygui/UIPackage.cpp @@ -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); diff --git a/tests/cpp-tests/Source/ActionsTest/ActionsTest.cpp b/tests/cpp-tests/Source/ActionsTest/ActionsTest.cpp index bb0b2b9317f1..69f34216a07a 100644 --- a/tests/cpp-tests/Source/ActionsTest/ActionsTest.cpp +++ b/tests/cpp-tests/Source/ActionsTest/ActionsTest.cpp @@ -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); @@ -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 @@ -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); diff --git a/tests/cpp-tests/Source/BaseTest.cpp b/tests/cpp-tests/Source/BaseTest.cpp index 0f7ac5b29f6f..f9ccc5d257ee 100644 --- a/tests/cpp-tests/Source/BaseTest.cpp +++ b/tests/cpp-tests/Source/BaseTest.cpp @@ -148,7 +148,7 @@ void TestList::addTest(std::string_view testName, std::function cal if (!testName.empty()) { _childTestNames.emplace_back( - StringUtils::format("%d:%s", static_cast(_childTestNames.size() + 1), testName.data())); + fmt::format("{}:{}", static_cast(_childTestNames.size() + 1), testName)); _testCallbacks.emplace_back(callback); } } @@ -465,8 +465,8 @@ void TestCase::onEnter() if (_testSuite) { - _titleLabel->setString(StringUtils::format("%d", static_cast(_testSuite->getCurrTestIndex() + 1)) + ":" + - title()); + _titleLabel->setString(fmt::format("{}:{}", static_cast(_testSuite->getCurrTestIndex() + 1), + title())); } else { diff --git a/tests/cpp-tests/Source/CurlTest/CurlTest.cpp b/tests/cpp-tests/Source/CurlTest/CurlTest.cpp index 37fd876359f3..0b24cc9e0fa1 100644 --- a/tests/cpp-tests/Source/CurlTest/CurlTest.cpp +++ b/tests/cpp-tests/Source/CurlTest/CurlTest.cpp @@ -109,7 +109,7 @@ void CurlTest::onTouchesEnded(const std::vector& 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 { diff --git a/tests/cpp-tests/Source/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp b/tests/cpp-tests/Source/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp index 29f40643ae0c..a529008ea16b 100644 --- a/tests/cpp-tests/Source/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp +++ b/tests/cpp-tests/Source/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp @@ -144,15 +144,15 @@ void AssetsManagerExLoaderScene::startDownloadCallback(Object* sender) std::string str; if (assetId == AssetsManagerEx::VERSION_ID) { - str = StringUtils::format("Version file: %.2f", percent) + "%"; + str = fmt::format("Version file: {:.2}%", percent); } else if (assetId == AssetsManagerEx::MANIFEST_ID) { - str = StringUtils::format("Manifest file: %.2f", percent) + "%"; + str = fmt::format("Manifest file: {:.2}%", percent); } else { - str = StringUtils::format("%.2f", percent) + "%"; + str = fmt::format("{:.2}%", percent); AXLOGD("{:.2} Percent", percent); } if (this->_progress != nullptr) diff --git a/tests/cpp-tests/Source/ExtensionsTest/TableViewTest/TableViewTestScene.cpp b/tests/cpp-tests/Source/ExtensionsTest/TableViewTest/TableViewTestScene.cpp index 6f6c7f11cc66..23d8521528f4 100644 --- a/tests/cpp-tests/Source/ExtensionsTest/TableViewTest/TableViewTestScene.cpp +++ b/tests/cpp-tests/Source/ExtensionsTest/TableViewTest/TableViewTestScene.cpp @@ -84,7 +84,7 @@ Size TableViewTest::tableCellSizeForIndex(TableView* table, ssize_t idx) TableViewCell* TableViewTest::tableCellAtIndex(TableView* table, ssize_t idx) { - auto string = StringUtils::format("%d", static_cast(idx)); + auto string = fmt::format("{}", static_cast(idx)); TableViewCell* cell = table->dequeueCell(); if (!cell) { diff --git a/tests/cpp-tests/Source/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Source/LabelTest/LabelTestNew.cpp index f519ea242c39..8c75ded97405 100644 --- a/tests/cpp-tests/Source/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Source/LabelTest/LabelTestNew.cpp @@ -2501,7 +2501,7 @@ void LabelLayoutBaseTest::valueChanged(ax::Object* sender, ax::extension::Contro // Change value of label. auto fontSizeLabel = (Label*)this->getChildByName("fontSize"); float fontSize = (float)pControl->getValue(); - fontSizeLabel->setString(StringUtils::format("font size:%d", (int)fontSize)); + fontSizeLabel->setString(fmt::format("font size:{}", (int)fontSize)); if (_labelType == 0) { @@ -2590,8 +2590,8 @@ LabelWrapNoBreakSpaceTest::LabelWrapNoBreakSpaceTest() { _label->setLineBreakWithoutSpace(false); const char* no_break_space_utf8 = "\xC2\xA0"; // 0xA0 - no-break space - auto str = StringUtils::format( - "The price is $%s1.25. \n\nthe space between \"$\" and \"1.25\" is a no break space.", no_break_space_utf8); + auto str = fmt::format( + "The price is ${}1.25. \n\nthe space between \"$\" and \"1.25\" is a no break space.", no_break_space_utf8); _label->setString(str); _label->setVerticalAlignment(TextVAlignment::TOP); _label->setOverflow(Label::Overflow::CLAMP); diff --git a/tests/cpp-tests/Source/MaterialSystemTest/MaterialSystemTest.cpp b/tests/cpp-tests/Source/MaterialSystemTest/MaterialSystemTest.cpp index b840cc426644..48c567c76788 100644 --- a/tests/cpp-tests/Source/MaterialSystemTest/MaterialSystemTest.cpp +++ b/tests/cpp-tests/Source/MaterialSystemTest/MaterialSystemTest.cpp @@ -463,7 +463,7 @@ void Material_parsePerformance::parsingTesting(unsigned int count) Label* label = dynamic_cast(this->getChildByTag(SHOW_LEBAL_TAG)); if (label) { - std::string str = StringUtils::format("Testing completed! Took: %.3f seconds for parsing material %d times.", + std::string str = fmt::format("Testing completed! Took: {:.3} seconds for parsing material {} times.", elapsed_secs, count); label->setString(str); diff --git a/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp b/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp index 43c43d715c30..dd68c89fb3a4 100644 --- a/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp +++ b/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp @@ -288,7 +288,7 @@ struct DownloaderTest : public TestCase else { // download big file success - auto msg = StringUtils::format("Download [%s] success.", task.identifier.c_str()); + auto msg = fmt::format("Download [{}] success.", task.identifier); auto status = (Label*)view->getChildByTag(TAG_STATUS); status->setString(msg); } diff --git a/tests/cpp-tests/Source/NetworkTest/WebSocketTest/WebSocketTest.cpp b/tests/cpp-tests/Source/NetworkTest/WebSocketTest/WebSocketTest.cpp index f7160a267eaa..e54bcc9ecc25 100644 --- a/tests/cpp-tests/Source/NetworkTest/WebSocketTest/WebSocketTest.cpp +++ b/tests/cpp-tests/Source/NetworkTest/WebSocketTest/WebSocketTest.cpp @@ -320,7 +320,7 @@ void WebSocketTest::onMenuSendMultipleTextClicked(ax::Object* sender) _sendTextStatus->setString("Send Multiple Text WS is waiting..."); for (int index = 0; index < 15; ++index) { - _wsiSendText->send(StringUtils::format("Hello WebSocket, text message index:%d", index)); + _wsiSendText->send(fmt::format("Hello WebSocket, text message index:{}", index)); } } else diff --git a/tests/cpp-tests/Source/NewAudioEngineTest/NewAudioEngineTest.cpp b/tests/cpp-tests/Source/NewAudioEngineTest/NewAudioEngineTest.cpp index 7e60ae2fc7a9..c5d0a380b000 100644 --- a/tests/cpp-tests/Source/NewAudioEngineTest/NewAudioEngineTest.cpp +++ b/tests/cpp-tests/Source/NewAudioEngineTest/NewAudioEngineTest.cpp @@ -483,8 +483,8 @@ bool AudioWavTest::init() { AudioEngine::stop(_audioID); _audioID = AudioEngine::play2d(_wavFiles[--_curIndex]); - _stateLabel->setString(StringUtils::format("[index: %d] %s", _curIndex, - FileUtils::getFileShortName(_wavFiles[_curIndex]).c_str())); + _stateLabel->setString(fmt::format("[index: {}] {}", _curIndex, + FileUtils::getFileShortName(_wavFiles[_curIndex]))); } }); playPrev->setPosition(layerSize.width * 0.35f, layerSize.height * 0.5f); @@ -495,8 +495,8 @@ bool AudioWavTest::init() { AudioEngine::stop(_audioID); _audioID = AudioEngine::play2d(_wavFiles[++_curIndex]); - _stateLabel->setString(StringUtils::format("[index: %d] %s", _curIndex, - FileUtils::getFileShortName(_wavFiles[_curIndex]).c_str())); + _stateLabel->setString(fmt::format("[index: {}] {}", _curIndex, + FileUtils::getFileShortName(_wavFiles[_curIndex]))); } }); playNext->setPosition(layerSize.width * 0.65f, layerSize.height * 0.5f); @@ -516,8 +516,8 @@ void AudioWavTest::onEnter() { _curIndex = 0; _audioID = AudioEngine::play2d(_wavFiles[_curIndex]); - _stateLabel->setString(StringUtils::format("[index: %d] %s", _curIndex, - FileUtils::getFileShortName(_wavFiles[_curIndex]).c_str())); + _stateLabel->setString(fmt::format("[index: {}] {}", _curIndex, + FileUtils::getFileShortName(_wavFiles[_curIndex]))); } } diff --git a/tests/cpp-tests/Source/PhysicsTest/PhysicsTest.cpp b/tests/cpp-tests/Source/PhysicsTest/PhysicsTest.cpp index e3367ace9c09..5563af476041 100644 --- a/tests/cpp-tests/Source/PhysicsTest/PhysicsTest.cpp +++ b/tests/cpp-tests/Source/PhysicsTest/PhysicsTest.cpp @@ -1996,7 +1996,7 @@ void PhysicsDemoPyramidStackFixedUpdate::onEnter() auto sp = addGrossiniAtPosition(VisibleRect::bottom() + Vec2((i / 2 - j) * 11, (14 - i) * 23 + 100), 0.2f); sp->getPhysicsBody()->setTag(DRAG_BODYS_TAG); - auto label = Label::createWithTTF(StringUtils::format("%d", count++), "fonts/arial.ttf", 24); + auto label = Label::createWithTTF(fmt::format("{}", count++), "fonts/arial.ttf", 24); label->setPosition(sp->getContentSize().width * 0.5f, sp->getContentSize().height * 0.5f); sp->addChild(label, 1); } diff --git a/tests/cpp-tests/Source/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp b/tests/cpp-tests/Source/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp index 524cc4654614..61d556d7030a 100644 --- a/tests/cpp-tests/Source/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp +++ b/tests/cpp-tests/Source/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp @@ -85,7 +85,7 @@ void SpriteFrameCachePixelFormatTest::loadSpriteFrames(std::string_view file, const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB; - const std::string textureInfo = StringUtils::format("%s%s: %.2f KB\r\n", infoLabel->getString().data(), + const std::string textureInfo = fmt::format("{}{}: {:.2} KB\r\n", infoLabel->getString(), texture->getStringForFormat(), memorySize); infoLabel->setString(textureInfo); @@ -493,7 +493,7 @@ void SpriteFrameCacheJsonAtlasTest::loadSpriteFrames(std::string_view file, const ssize_t bitsPerKB = 8 * 1024; const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB; - const std::string textureInfo = StringUtils::format("%s%s: %.2f KB\r\n", infoLabel->getString().data(), + const std::string textureInfo = fmt::format("{}{}: {:.2} KB\r\n", infoLabel->getString(), texture->getStringForFormat(), memorySize); infoLabel->setString(textureInfo); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index ad517ad69631..3072a106d791 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -689,7 +689,7 @@ void UIButtonTestZoomScale::sliderEvent(Object* pSender, Slider::EventType type) Button* btn = (Button*)_uiLayer->getChildByName("button"); float zoomScale = percent * 0.01; btn->setZoomScale(zoomScale); - _displayValueLabel->setString(StringUtils::format("Zoom Scale: %f", zoomScale)); + _displayValueLabel->setString(fmt::format("Zoom Scale: {}", zoomScale)); } } diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index fa88618f8342..665d484b2668 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -208,7 +208,7 @@ bool UIImageViewTest_ContentSize::init() imageView->setContentSize(Size(width, height)); imageViewChild->setPositionPercent(Vec2(AXRANDOM_0_1(), AXRANDOM_0_1())); - status->setString(StringUtils::format("child ImageView position percent: %f, %f", + status->setString(fmt::format("child ImageView position percent: {}, {}", imageViewChild->getPositionPercent().x, imageViewChild->getPositionPercent().y)); } diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index 896b3aea7d20..b3e07071e076 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -78,7 +78,7 @@ bool UIListViewTest_Vertical::init() for (int i = 0; i < _totalCount; ++i) { - std::string ccstr = StringUtils::format("listview_item_%d", i); + std::string ccstr = fmt::format("listview_item_{}", i); _array.emplace_back(ccstr); } @@ -180,9 +180,9 @@ bool UIListViewTest_Vertical::init() auto center = listView->getCenterItemInCurrentView(); auto top = listView->getTopmostItemInCurrentView(); - _indexLabels[0]->setString(StringUtils::format("Top index=%zd", listView->getIndex(top))); - _indexLabels[1]->setString(StringUtils::format("Center\nindex=%zd", listView->getIndex(center))); - _indexLabels[2]->setString(StringUtils::format("Bottom index=%zd", listView->getIndex(bottom))); + _indexLabels[0]->setString(fmt::format("Top index={}", listView->getIndex(top))); + _indexLabels[1]->setString(fmt::format("Center\nindex={}", listView->getIndex(center))); + _indexLabels[2]->setString(fmt::format("Bottom index={}", listView->getIndex(bottom))); }); } @@ -262,14 +262,14 @@ void UIListViewTest_Vertical::selectedItemEvent(Object* pSender, ListView::Event { ListView* listView = static_cast(pSender); auto item = listView->getItem(listView->getCurSelectedIndex()); - ax::print("select child start index = %d", item->getTag()); + AXLOGD("select child start index = {}", item->getTag()); break; } case ax::ui::ListView::EventType::ON_SELECTED_ITEM_END: { ListView* listView = static_cast(pSender); auto item = listView->getItem(listView->getCurSelectedIndex()); - ax::print("select child end index = %d", item->getTag()); + AXLOGD("select child end index = {}", item->getTag()); break; } default: @@ -328,7 +328,7 @@ bool UIListViewTest_Horizontal::init() // The data is usually fetch from the server for (int i = 0; i < _totalCount; ++i) { - std::string ccstr = StringUtils::format("listview_item_%d", i); + std::string ccstr = fmt::format("listview_item_{}", i); _array.emplace_back(ccstr); } @@ -696,11 +696,11 @@ bool UIListViewTest_ScrollToItem::init() pButton->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); pButton->setScale(0.8f); pButton->setPosition(Vec2(layerSize / 2) + Vec2(120.0f, -60.0f)); - pButton->setTitleText(StringUtils::format("Go to '%d'", _nextIndex)); + pButton->setTitleText(fmt::format("Go to '{}'", _nextIndex)); pButton->addClickEventListener([this, pButton](Object*) { _listView->scrollToItem(_nextIndex, Vec2::ANCHOR_MIDDLE, Vec2::ANCHOR_MIDDLE); _nextIndex = (_nextIndex + (NUMBER_OF_ITEMS / 2)) % NUMBER_OF_ITEMS; - pButton->setTitleText(StringUtils::format("Go to '%d'", _nextIndex)); + pButton->setTitleText(fmt::format("Go to '{}'", _nextIndex)); }); _uiLayer->addChild(pButton); @@ -711,7 +711,7 @@ bool UIListViewTest_ScrollToItem::init() auto pButton = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); pButton->setContentSize(BUTTON_SIZE); pButton->setScale9Enabled(true); - pButton->setTitleText(StringUtils::format("Button-%d", i)); + pButton->setTitleText(fmt::format("Button-{}", i)); _listView->pushBackCustomItem(pButton); } return true; @@ -791,11 +791,11 @@ bool UIListViewTest_Magnetic::init() auto bottom = listView->getBottommostItemInCurrentView(); auto center = listView->getCenterItemInCurrentView(); - _indexLabels[0]->setString(StringUtils::format("Left\nindex=%zd", listView->getIndex(left))); - _indexLabels[1]->setString(StringUtils::format("RIght\nindex=%zd", listView->getIndex(right))); - _indexLabels[2]->setString(StringUtils::format("Top index=%zd", listView->getIndex(top))); - _indexLabels[3]->setString(StringUtils::format("Bottom index=%zd", listView->getIndex(bottom))); - _indexLabels[4]->setString(StringUtils::format("Center\nindex=%zd", listView->getIndex(center))); + _indexLabels[0]->setString(fmt::format("Left\nindex={}", listView->getIndex(left))); + _indexLabels[1]->setString(fmt::format("RIght\nindex={}", listView->getIndex(right))); + _indexLabels[2]->setString(fmt::format("Top index={}", listView->getIndex(top))); + _indexLabels[3]->setString(fmt::format("Bottom index={}", listView->getIndex(bottom))); + _indexLabels[4]->setString(fmt::format("Center\nindex={}", listView->getIndex(center))); }); } @@ -857,7 +857,7 @@ bool UIListViewTest_Magnetic::init() sString = "NONE"; } _listView->setMagneticType(eNextType); - _titleLabel->setString(StringUtils::format("MagneticType - %s", sString.c_str())); + _titleLabel->setString(fmt::format("MagneticType - {}", sString)); }); _uiLayer->addChild(pButton); @@ -868,7 +868,7 @@ bool UIListViewTest_Magnetic::init() auto pButton = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); pButton->setContentSize(BUTTON_SIZE); pButton->setScale9Enabled(true); - pButton->setTitleText(StringUtils::format("Button-%d", i)); + pButton->setTitleText(fmt::format("Button-{}", i)); _listView->pushBackCustomItem(pButton); } return true; @@ -998,11 +998,11 @@ bool UIListViewTest_Padding::init() auto bottom = listView->getBottommostItemInCurrentView(); auto center = listView->getCenterItemInCurrentView(); - _indexLabels[0]->setString(StringUtils::format("Left\nindex=%zd", listView->getIndex(left))); - _indexLabels[1]->setString(StringUtils::format("RIght\nindex=%zd", listView->getIndex(right))); - _indexLabels[2]->setString(StringUtils::format("Top index=%zd", listView->getIndex(top))); - _indexLabels[3]->setString(StringUtils::format("Bottom index=%zd", listView->getIndex(bottom))); - _indexLabels[4]->setString(StringUtils::format("Center\nindex=%zd", listView->getIndex(center))); + _indexLabels[0]->setString(fmt::format("Left\nindex={}", listView->getIndex(left))); + _indexLabels[1]->setString(fmt::format("RIght\nindex={}", listView->getIndex(right))); + _indexLabels[2]->setString(fmt::format("Top index={}", listView->getIndex(top))); + _indexLabels[3]->setString(fmt::format("Bottom index={}", listView->getIndex(bottom))); + _indexLabels[4]->setString(fmt::format("Center\nindex={}", listView->getIndex(center))); }); } @@ -1013,7 +1013,7 @@ bool UIListViewTest_Padding::init() auto pButton = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); pButton->setContentSize(BUTTON_SIZE); pButton->setScale9Enabled(true); - pButton->setTitleText(StringUtils::format("Button-%d", i)); + pButton->setTitleText(fmt::format("Button-{}", i)); _listView->pushBackCustomItem(pButton); } return true; @@ -1030,7 +1030,7 @@ void UIListViewTest_Padding::sliderEvent(Object* pSender, Slider::EventType type int left = slider->getPercent() / 100.f * 50.f; AXLOGD("Left Padding: {}", left); _listView->setLeftPadding(left); - _paddingLabels[0]->setString(StringUtils::format("Left\nPadding=%d", left)); + _paddingLabels[0]->setString(fmt::format("Left\nPadding={}", left)); } // top if (slider && slider->getTag() == 1) @@ -1038,7 +1038,7 @@ void UIListViewTest_Padding::sliderEvent(Object* pSender, Slider::EventType type int top = slider->getPercent() / 100.f * 50.f; AXLOGD("Top Padding: {}", top); _listView->setTopPadding(top); - _paddingLabels[1]->setString(StringUtils::format("Top\nPadding=%d", top)); + _paddingLabels[1]->setString(fmt::format("Top\nPadding={}", top)); } // right if (slider && slider->getTag() == 2) @@ -1046,7 +1046,7 @@ void UIListViewTest_Padding::sliderEvent(Object* pSender, Slider::EventType type int right = slider->getPercent() / 100.f * 50.f; AXLOGD("Right Padding: {}", right); _listView->setRightPadding(right); - _paddingLabels[2]->setString(StringUtils::format("Right\nPadding=%d", right)); + _paddingLabels[2]->setString(fmt::format("Right\nPadding={}", right)); } // bottom if (slider && slider->getTag() == 3) @@ -1054,7 +1054,7 @@ void UIListViewTest_Padding::sliderEvent(Object* pSender, Slider::EventType type int bottom = slider->getPercent() / 100.f * 50.f; AXLOGD("Bottom Padding: {}", bottom); _listView->setBottomPadding(bottom); - _paddingLabels[3]->setString(StringUtils::format("Bottom\nPadding=%d", bottom)); + _paddingLabels[3]->setString(fmt::format("Bottom\nPadding={}", bottom)); } } } diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index a522f542e3a8..3d8a4dcc7aef 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -93,7 +93,7 @@ bool UIPageViewTest::init() imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(imageView); - Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30); + Text* label = Text::create(fmt::format("page {}", (i + 1)), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(192, 192, 192)); label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(label); @@ -104,7 +104,7 @@ bool UIPageViewTest::init() pageView->removeItem(0); pageView->scrollToItem(pageCount - 2); - ax::print("TODO in %s %s %d", __FILE__, __FUNCTION__, __LINE__); + AXLOGD("TODO in {} {} {}", __FILE__, __FUNCTION__, __LINE__); pageView->setIndicatorIndexNodesOpacity(255); @@ -124,7 +124,7 @@ void UIPageViewTest::pageViewEvent(Object* pSender, PageView::EventType type) PageView* pageView = dynamic_cast(pSender); _displayValueLabel->setString( - StringUtils::format("page = %d", static_cast(pageView->getCurrentPageIndex() + 1))); + fmt::format("page = {}", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -187,7 +187,7 @@ bool UIPageViewButtonTest::init() { Button* btn = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - btn->setName(StringUtils::format("button %d", j)); + btn->setName(fmt::format("button {}", j)); btn->addTouchEventListener(AX_CALLBACK_2(UIPageViewButtonTest::onButtonClicked, this)); innerBox->addChild(btn); @@ -219,7 +219,7 @@ void UIPageViewButtonTest::onButtonClicked(Object* sender, Widget::TouchEventTyp { if (type == Widget::TouchEventType::ENDED) { - ax::print("button %s clicked", static_cast(sender)->getName().data()); + AXLOGD("button {} clicked", static_cast(sender)->getName().data()); } } @@ -232,7 +232,7 @@ void UIPageViewButtonTest::pageViewEvent(Object* pSender, PageView::EventType ty PageView* pageView = dynamic_cast(pSender); _displayValueLabel->setString( - StringUtils::format("page = %d", static_cast(pageView->getCurrentPageIndex() + 1))); + fmt::format("page = {}", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -293,7 +293,7 @@ bool UIPageViewTouchPropagationTest::init() { Button* btn = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - btn->setName(StringUtils::format("button %d", j)); + btn->setName(fmt::format("button {}", j)); btn->addTouchEventListener(AX_CALLBACK_2(UIPageViewTouchPropagationTest::onButtonClicked, this)); innerBox->addChild(btn); @@ -422,7 +422,7 @@ void UIPageViewTouchPropagationTest::pageViewEvent(Object* pSender, PageView::Ev PageView* pageView = dynamic_cast(pSender); _displayValueLabel->setString( - StringUtils::format("page = %d", static_cast(pageView->getCurrentPageIndex() + 1))); + fmt::format("page = {}", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -486,7 +486,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() { Button* btn = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - btn->setName(StringUtils::format("button %d", j)); + btn->setName(fmt::format("button {}", j)); innerBox->addChild(btn); } @@ -524,7 +524,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() { Button* btn = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - btn->setName(StringUtils::format("button %d", j)); + btn->setName(fmt::format("button {}", j)); innerBox->addChild(btn); } @@ -536,7 +536,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() pageView->pushBackCustomItem(outerBox); _displayValueLabel->setString( - StringUtils::format("page count = %d", static_cast(pageView->getItems().size()))); + fmt::format("page count = {}", static_cast(pageView->getItems().size()))); AXLOGD("current page index = {}", pageView->getCurrentPageIndex()); }); _uiLayer->addChild(button); @@ -557,7 +557,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() AXLOGD("There is no page to remove!"); } _displayValueLabel->setString( - StringUtils::format("page count = %d", static_cast(pageView->getItems().size()))); + fmt::format("page count = {}", static_cast(pageView->getItems().size()))); AXLOGD("current page index = {}", pageView->getCurrentPageIndex()); }); _uiLayer->addChild(button2); @@ -571,7 +571,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() button3->addClickEventListener([=](Object* sender) { pageView->removeAllItems(); _displayValueLabel->setString( - StringUtils::format("page count = %d", static_cast(pageView->getItems().size()))); + fmt::format("page count = {}", static_cast(pageView->getItems().size()))); AXLOGD("current page index = {}", pageView->getCurrentPageIndex()); }); _uiLayer->addChild(button3); @@ -599,7 +599,7 @@ void UIPageViewDynamicAddAndRemoveTest::pageViewEvent(Object* pSender, PageView: PageView* pageView = dynamic_cast(pSender); _displayValueLabel->setString( - StringUtils::format("page = %d", static_cast((pageView->getCurrentPageIndex() + 1)))); + fmt::format("page = {}", static_cast((pageView->getCurrentPageIndex() + 1)))); } break; @@ -660,7 +660,7 @@ bool UIPageViewJumpToPageTest::init() imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(imageView); - Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30); + Text* label = Text::create(fmt::format("page {}", (i + 1)), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(192, 192, 192)); label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(label); @@ -753,7 +753,7 @@ bool UIPageViewVerticalTest::init() imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(imageView); - Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30); + Text* label = Text::create(fmt::format("page {}", (i + 1)), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(192, 192, 192)); label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(label); @@ -780,7 +780,7 @@ void UIPageViewVerticalTest::pageViewEvent(Object* pSender, PageView::EventType PageView* pageView = dynamic_cast(pSender); _displayValueLabel->setString( - StringUtils::format("page = %d", static_cast(pageView->getCurrentPageIndex() + 1))); + fmt::format("page = {}", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -842,7 +842,7 @@ bool UIPageViewDisableTouchTest::init() imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(imageView); - Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30); + Text* label = Text::create(fmt::format("page {}", (i + 1)), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(192, 192, 192)); label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(label); @@ -902,7 +902,7 @@ bool UIPageViewChildSizeTest::init() ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png"); imageView->setScale9Enabled(true); - Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30); + Text* label = Text::create(fmt::format("page {}", (i + 1)), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(192, 192, 192)); label->setAnchorPoint(Vec2::ZERO); imageView->addChild(label); @@ -929,7 +929,7 @@ void UIPageViewChildSizeTest::pageViewEvent(Object* pSender, PageView::EventType PageView* pageView = dynamic_cast(pSender); _displayValueLabel->setString( - StringUtils::format("page = %d", static_cast(pageView->getCurrentPageIndex() + 1))); + fmt::format("page = {}", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -997,7 +997,7 @@ bool UIPageViewIndicatorTest::init() imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(imageView); - Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30); + Text* label = Text::create(fmt::format("page {}", (i + 1)), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(192, 192, 192)); label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(label); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp index dae73af172f3..3628a2ca6629 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp @@ -239,7 +239,7 @@ void UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup1(RadioButton* radioBu ax::ui::RadioButtonGroup::EventType type) { AXASSERT(index == _radioButtonGroups[0]->getSelectedButtonIndex(), "The two indexes must match!"); - auto text = StringUtils::format("RadioButtonGroup1 : %d", index); + auto text = fmt::format("RadioButtonGroup1 : {}", index); _groupEventLabel->setString(text); addLog(text); } @@ -249,7 +249,7 @@ void UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup2(RadioButton* radioBu ax::ui::RadioButtonGroup::EventType type) { AXASSERT(index == _radioButtonGroups[1]->getSelectedButtonIndex(), "The two indexes must match!"); - auto text = StringUtils::format("RadioButtonGroup2 : %d", index); + auto text = fmt::format("RadioButtonGroup2 : {}", index); _groupEventLabel->setString(text); addLog(text); } @@ -260,7 +260,7 @@ void UIRadioButtonTwoGroupsTest::onChangedRadioButtonSelect(RadioButton* radioBu { return; } - auto text = StringUtils::format("RadioButton %d : ", radioButton->getTag()); + auto text = fmt::format("RadioButton {} : ", radioButton->getTag()); switch (type) { case RadioButton::EventType::SELECTED: @@ -337,8 +337,8 @@ bool UIRadioButtonTabTest::init() float startPosX = widgetSize.width / 2.0f - ((NUMBER_OF_BUTTONS - 1) / 2.0f) * buttonWidth; for (int i = 0; i < NUMBER_OF_BUTTONS; ++i) { - auto filePathNormal = StringUtils::format("cocosui/btn_exercise%02d_n.png", i + 1); - auto filePathSelected = StringUtils::format("cocosui/btn_exercise%02d_p.png", i + 1); + auto filePathNormal = fmt::format("cocosui/btn_exercise{:02}_n.png", i + 1); + auto filePathSelected = fmt::format("cocosui/btn_exercise{:02}_p.png", i + 1); RadioButton* radioButton = RadioButton::create(filePathNormal, filePathSelected); float posX = startPosX + buttonWidth * i; radioButton->setPosition(Vec2(posX, widgetSize.height / 2.0f)); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp index ea3ca1ca4ed7..92d115e8e443 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp @@ -97,7 +97,7 @@ void UISliderTest::sliderEvent(Object* pSender, Slider::EventType type) Slider* slider = dynamic_cast(pSender); int percent = slider->getPercent(); int maxPercent = slider->getMaxPercent(); - _displayValueLabel->setString(StringUtils::format("Percent %f", 10000.0 * percent / maxPercent)); + _displayValueLabel->setString(fmt::format("Percent {}", 10000.0 * percent / maxPercent)); } } void UISliderTest::printWidgetResources(ax::Object* /*sender*/) @@ -167,7 +167,7 @@ void UISliderTest_Scale9::sliderEvent(Object* pSender, Slider::EventType type) { Slider* slider = dynamic_cast(pSender); int percent = slider->getPercent(); - _displayValueLabel->setString(StringUtils::format("Percent %d", percent)); + _displayValueLabel->setString(fmt::format("Percent {}", percent)); } } @@ -231,7 +231,7 @@ void UISliderTest_Scale9_State_Change::sliderEvent(Object* pSender, Slider::Even { Slider* slider = dynamic_cast(pSender); int percent = slider->getPercent(); - _displayValueLabel->setString(StringUtils::format("Percent %d", percent)); + _displayValueLabel->setString(fmt::format("Percent {}", percent)); } } @@ -426,6 +426,6 @@ void UISliderIssue12249Test::sliderEvent(Object* pSender, Slider::EventType type Slider* slider = dynamic_cast(pSender); int percent = slider->getPercent(); int maxPercent = slider->getMaxPercent(); - _displayValueLabel->setString(StringUtils::format("Percent %f", 10000.0 * percent / maxPercent)); + _displayValueLabel->setString(fmt::format("Percent {}", 10000.0 * percent / maxPercent)); } } diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp index 2f310b012e22..5a9fc5bfe94e 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp @@ -161,7 +161,7 @@ void UITextFieldTest_MaxLength::textFieldEvent(Object* pSender, TextField::Event textField->runAction(MoveTo::create( 0.225f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f))); - _displayValueLabel->setString(StringUtils::format("attach with IME max length %d", textField->getMaxLength())); + _displayValueLabel->setString(fmt::format("attach with IME max length {}", textField->getMaxLength())); } break; @@ -170,21 +170,21 @@ void UITextFieldTest_MaxLength::textFieldEvent(Object* pSender, TextField::Event TextField* textField = dynamic_cast(pSender); Size screenSize = Director::getInstance()->getWinSize(); textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f))); - _displayValueLabel->setString(StringUtils::format("detach with IME max length %d", textField->getMaxLength())); + _displayValueLabel->setString(fmt::format("detach with IME max length {}", textField->getMaxLength())); } break; case TextField::EventType::INSERT_TEXT: { TextField* textField = dynamic_cast(pSender); - _displayValueLabel->setString(StringUtils::format("insert words max length %d", textField->getMaxLength())); + _displayValueLabel->setString(fmt::format("insert words max length {}", textField->getMaxLength())); } break; case TextField::EventType::DELETE_BACKWARD: { TextField* textField = dynamic_cast(pSender); - _displayValueLabel->setString(StringUtils::format("delete word max length %d", textField->getMaxLength())); + _displayValueLabel->setString(fmt::format("delete word max length {}", textField->getMaxLength())); } break; diff --git a/tests/cpp-tests/Source/VibrateTest/VibrateTest.cpp b/tests/cpp-tests/Source/VibrateTest/VibrateTest.cpp index b8cbf593ef37..9d0c1ccffe85 100644 --- a/tests/cpp-tests/Source/VibrateTest/VibrateTest.cpp +++ b/tests/cpp-tests/Source/VibrateTest/VibrateTest.cpp @@ -291,7 +291,7 @@ bool VibrateControlTest::init() vibrateItem->setPosition(layerSize.width * 0.5f, layerSize.height * 0.7f); addChild(vibrateItem); - auto durationLabelValue = StringUtils::format("duration: %.3fs", _duration); + auto durationLabelValue = fmt::format("duration: {:.3}s", _duration); auto durationLabel = Label::createWithTTF(durationLabelValue, fontFilePath, 20); durationLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE); @@ -303,7 +303,7 @@ bool VibrateControlTest::init() durationSlider->setPercent(0); durationSlider->setCallBack([&](SliderEx* sender, float ratio, SliderEx::TouchEvent event) { _duration = ratio * 1.9f + 0.1f; // From 0.1s to 2s - auto durationLabelValue = StringUtils::format("duration: %.3fs", _duration); + auto durationLabelValue = fmt::format("duration: {:.3}s", _duration); (static_cast(_durationLabel))->setString(durationLabelValue); }); durationSlider->setPosition(Vec2(layerSize.width * 0.5f, layerSize.height * 0.35f)); diff --git a/tests/cpp-tests/Source/WindowTest/WindowTest.cpp b/tests/cpp-tests/Source/WindowTest/WindowTest.cpp index 7cb617f006d5..3f49bb891e38 100644 --- a/tests/cpp-tests/Source/WindowTest/WindowTest.cpp +++ b/tests/cpp-tests/Source/WindowTest/WindowTest.cpp @@ -120,11 +120,11 @@ void WindowTestResizedAndPositioned::onEnter() glView->getWindowPosition(&x, &y); glView->getWindowSize(&width, &height); - label1 = Label::createWithTTF(StringUtils::format("pos : %d, %d", x, y), "fonts/Marker Felt.ttf", 16.0f); + label1 = Label::createWithTTF(fmt::format("pos : {}, {}", x, y), "fonts/Marker Felt.ttf", 16.0f); label1->setPosition(s.width / 3 * 1, s.height / 2); addChild(label1); - label2 = Label::createWithTTF(StringUtils::format("size : %d, %d", width, height), "fonts/Marker Felt.ttf", 16.0f); + label2 = Label::createWithTTF(fmt::format("size : {}, {}", width, height), "fonts/Marker Felt.ttf", 16.0f); label2->setPosition(s.width / 3 * 2, s.height / 2); addChild(label2); @@ -154,7 +154,7 @@ void WindowTestResizedAndPositioned::onWindowPositioned(EventCustom* e) if (pos == nullptr) return; - label1->setString(StringUtils::format("pos : %d, %d", (int)pos->x, (int)pos->y)); + label1->setString(fmt::format("pos : {}, {}", (int)pos->x, (int)pos->y)); } void WindowTestResizedAndPositioned::onWindowResized(EventCustom* e) @@ -163,7 +163,7 @@ void WindowTestResizedAndPositioned::onWindowResized(EventCustom* e) if (size == nullptr) return; - label2->setString(StringUtils::format("size : %d, %d", (int)size->width, (int)size->height)); + label2->setString(fmt::format("size : {}, {}", (int)size->width, (int)size->height)); } void WindowTestClose::onEnter()