From b11b1a6f7249648b81814d5f300ee02c3720be94 Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Tue, 11 Mar 2025 10:08:04 +0000
Subject: [PATCH] Ease in a bit more fmt::format().

---
 common/dsnlexer.cpp             | 15 +++++----------
 common/lib_id.cpp               |  9 +++++----
 common/widgets/kistatusbar.cpp  |  5 ++---
 common/widgets/number_badge.cpp |  8 ++++----
 pcbnew/netinfo_item.cpp         |  7 ++++---
 pcbnew/pcb_draw_panel_gal.cpp   | 11 ++++++-----
 pcbnew/pcb_track.cpp            | 12 ++++--------
 7 files changed, 30 insertions(+), 37 deletions(-)

diff --git a/common/dsnlexer.cpp b/common/dsnlexer.cpp
index 734c83e390..0e73c13053 100644
--- a/common/dsnlexer.cpp
+++ b/common/dsnlexer.cpp
@@ -327,40 +327,35 @@ bool DSNLEXER::IsSymbol( int aTok )
 
 void DSNLEXER::Expecting( int aTok ) const
 {
-    wxString errText = wxString::Format(
-        _( "Expecting %s" ), GetTokenString( aTok ) );
+    wxString errText = wxString::Format( _( "Expecting %s" ), GetTokenString( aTok ) );
     THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
 }
 
 
 void DSNLEXER::Expecting( const char* text ) const
 {
-    wxString errText = wxString::Format(
-        _( "Expecting '%s'" ), wxString::FromUTF8( text ) );
+    wxString errText = wxString::Format( _( "Expecting '%s'" ), wxString::FromUTF8( text ) );
     THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
 }
 
 
 void DSNLEXER::Unexpected( int aTok ) const
 {
-    wxString errText = wxString::Format(
-        _( "Unexpected %s" ), GetTokenString( aTok ) );
+    wxString errText = wxString::Format( _( "Unexpected %s" ), GetTokenString( aTok ) );
     THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
 }
 
 
 void DSNLEXER::Duplicate( int aTok )
 {
-    wxString errText = wxString::Format(
-        _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
+    wxString errText = wxString::Format( _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
     THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
 }
 
 
 void DSNLEXER::Unexpected( const char* text ) const
 {
-    wxString errText = wxString::Format(
-        _( "Unexpected '%s'" ), wxString::FromUTF8( text ) );
+    wxString errText = wxString::Format( _( "Unexpected '%s'" ), wxString::FromUTF8( text ) );
     THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
 }
 
diff --git a/common/lib_id.cpp b/common/lib_id.cpp
index a4e1ad604a..6cf8d584c4 100644
--- a/common/lib_id.cpp
+++ b/common/lib_id.cpp
@@ -26,6 +26,7 @@
 #include <cstring>
 #include <memory>
 #include <wx/translation.h>
+#include <fmt/format.h>
 
 #include <ki_exception.h>
 #include <macros.h>     // TO_UTF8()
@@ -276,8 +277,8 @@ bool LIB_ID::isLegalLibraryNameChar( unsigned aUniChar )
 
 const wxString LIB_ID::GetFullLibraryName() const
 {
-    wxString suffix = m_subLibraryName.wx_str().IsEmpty()
-                              ? wxString( wxS( "" ) )
-                              : wxString::Format( wxT( " - %s" ), m_subLibraryName.wx_str() );
-    return wxString::Format( wxT( "%s%s" ), m_libraryName.wx_str(), suffix );
+    if( m_subLibraryName.empty() )
+        return m_libraryName.c_str();
+
+    return fmt::format( "{} - {}", m_libraryName.c_str(), m_subLibraryName.c_str() );
 }
diff --git a/common/widgets/kistatusbar.cpp b/common/widgets/kistatusbar.cpp
index b172200135..fbc1d28320 100644
--- a/common/widgets/kistatusbar.cpp
+++ b/common/widgets/kistatusbar.cpp
@@ -26,6 +26,7 @@
 #include <wx/statusbr.h>
 #include <wx/gauge.h>
 #include <wx/stattext.h>
+#include <fmt/format.h>
 #include <array>
 #include <widgets/kistatusbar.h>
 #include <widgets/bitmap_button.h>
@@ -214,9 +215,7 @@ void KISTATUSBAR::SetNotificationCount(int aCount)
     wxString cnt = "";
 
     if( aCount > 0 )
-    {
-        cnt = wxString::Format( "%d", aCount );
-    }
+        cnt = fmt::format( "{}", aCount );
 
     m_notificationsButton->SetBadgeText( cnt );
 
diff --git a/common/widgets/number_badge.cpp b/common/widgets/number_badge.cpp
index 629b693ba4..8da3995b35 100644
--- a/common/widgets/number_badge.cpp
+++ b/common/widgets/number_badge.cpp
@@ -23,7 +23,7 @@
 
 #include <gal/color4d.h>
 #include <widgets/number_badge.h>
-
+#include <fmt/format.h>
 #include <algorithm>
 #include <kiplatform/ui.h>
 
@@ -127,7 +127,7 @@ void NUMBER_BADGE::computeSize()
 {
     wxClientDC dc( this );
 
-    wxString test = wxString::Format( wxT( "%d" ), m_currentNumber );
+    wxString test = fmt::format( "{}", m_currentNumber );
     int      len  = test.length();
 
     // Determine the size using the string "m999{+}" where the 'm' on the front serves as a margin
@@ -177,9 +177,9 @@ void NUMBER_BADGE::onPaint( wxPaintEvent& aEvt )
 
     // Cap the number displayed and add the "+" to the end if required
     if( m_currentNumber > m_maxNumber )
-        text = wxString::Format( wxT( "%d+" ), m_maxNumber );
+        text = fmt::format( "{}+", m_maxNumber );
     else
-        text = wxString::Format( wxT( "%d" ), m_currentNumber );
+        text = fmt::format( "{}", m_currentNumber );
 
     dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, BADGE_FONTWEIGHT ) );
     dc.SetTextForeground( m_textColour );
diff --git a/pcbnew/netinfo_item.cpp b/pcbnew/netinfo_item.cpp
index ab432e9022..2aa583a7d7 100644
--- a/pcbnew/netinfo_item.cpp
+++ b/pcbnew/netinfo_item.cpp
@@ -27,6 +27,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include <fmt/format.h>
 #include <pcb_base_frame.h>
 #include <string_utils.h>
 #include <widgets/msgpanel.h>
@@ -86,7 +87,7 @@ void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANE
 
     aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
 
-    aList.emplace_back( _( "Net Code" ), wxString::Format( wxT( "%d" ), GetNetCode() ) );
+    aList.emplace_back( _( "Net Code" ), fmt::format( "{}", GetNetCode() ) );
 
     // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
     BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
@@ -105,7 +106,7 @@ void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANE
             }
         }
 
-        aList.emplace_back( _( "Pads" ), wxString::Format( wxT( "%d" ), count ) );
+        aList.emplace_back( _( "Pads" ), fmt::format( "{}", count ) );
 
         count = 0;
 
@@ -120,7 +121,7 @@ void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANE
             }
         }
 
-        aList.emplace_back( _( "Vias" ), wxString::Format( wxT( "%d" ), count ) );
+        aList.emplace_back( _( "Vias" ), fmt::format( "{}", count ) );
 
         if( startTrack )
         {
diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp
index d7abddac28..bdae3c7be0 100644
--- a/pcbnew/pcb_draw_panel_gal.cpp
+++ b/pcbnew/pcb_draw_panel_gal.cpp
@@ -52,6 +52,7 @@
 #include <functional>
 #include <memory>
 #include <thread>
+#include <fmt/format.h>
 
 using namespace std::placeholders;
 
@@ -712,11 +713,11 @@ void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
         }
     }
 
-    aList.emplace_back( _( "Pads" ), wxString::Format( wxT( "%d" ), padCount ) );
-    aList.emplace_back( _( "Vias" ), wxString::Format( wxT( "%d" ), viaCount ) );
-    aList.emplace_back( _( "Track Segments" ), wxString::Format( wxT( "%d" ), trackSegmentCount ) );
-    aList.emplace_back( _( "Nets" ), wxString::Format( wxT( "%d" ), (int) netCodes.size() ) );
-    aList.emplace_back( _( "Unrouted" ), wxString::Format( wxT( "%d" ), unconnected ) );
+    aList.emplace_back( _( "Pads" ), fmt::format( "{}", padCount ) );
+    aList.emplace_back( _( "Vias" ), fmt::format( "{}", viaCount ) );
+    aList.emplace_back( _( "Track Segments" ), fmt::format( "{}", trackSegmentCount ) );
+    aList.emplace_back( _( "Nets" ), fmt::format( "{}", (int) netCodes.size() ) );
+    aList.emplace_back( _( "Unrouted" ), fmt::format( "{}", unconnected ) );
 }
 
 
diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp
index ab5a12082c..a1272967f6 100644
--- a/pcbnew/pcb_track.cpp
+++ b/pcbnew/pcb_track.cpp
@@ -1814,16 +1814,12 @@ void PCB_TRACK::GetMsgPanelInfoBase_Common( EDA_DRAW_FRAME* aFrame,
 
 #if 0   // Enable for debugging
     if( GetBoard() )
-        aList.emplace_back( _( "NetCode" ), wxString::Format( wxT( "%d" ), GetNetCode() ) );
+        aList.emplace_back( _( "NetCode" ), fmt::format( "{}", GetNetCode() ) );
 
-    aList.emplace_back( wxT( "Flags" ), wxString::Format( wxT( "0x%08X" ), m_flags ) );
+    aList.emplace_back( wxT( "Flags" ), fmt::format( "#08X", m_flags ) );
 
-    aList.emplace_back( wxT( "Start pos" ), wxString::Format( wxT( "%d %d" ),
-                                                              m_Start.x,
-                                                              m_Start.y ) );
-    aList.emplace_back( wxT( "End pos" ), wxString::Format( wxT( "%d %d" ),
-                                                            m_End.x,
-                                                            m_End.y ) );
+    aList.emplace_back( wxT( "Start pos" ), fmt::format( "{} {}", m_Start.x, m_Start.y ) );
+    aList.emplace_back( wxT( "End pos" ), fmt::format( "{} {}", m_End.x, m_End.y ) );
 #endif
 
     if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )