diff --git a/common/text_eval/text_eval.lemon b/common/text_eval/text_eval.lemon index 8601a7ab03..afef6ff449 100644 --- a/common/text_eval/text_eval.lemon +++ b/common/text_eval/text_eval.lemon @@ -147,7 +147,7 @@ factor(F) ::= NUMBER(N). { { if (g_errorCollector) { - g_errorCollector->AddError( std::format( "Invalid number format: {}", GetTokenString( N ) ) ); + g_errorCollector->AddError( fmt::format( "Invalid number format: {}", GetTokenString( N ) ) ); } F = NODE::CreateNumberRaw( 0.0 ); } diff --git a/common/text_eval/text_eval_parser.cpp b/common/text_eval/text_eval_parser.cpp index aaf5c6fcac..d0a9ba5f9c 100644 --- a/common/text_eval/text_eval_parser.cpp +++ b/common/text_eval/text_eval_parser.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -274,23 +275,23 @@ public: auto [year, month, day] = DaysToYmd( aDaysSinceEpoch ); if( aFormat == "ISO" || aFormat == "iso" ) - return std::format( "{:04d}-{:02d}-{:02d}", year, month, day ); + return fmt::format( "{:04d}-{:02d}-{:02d}", year, month, day ); else if( aFormat == "US" || aFormat == "us" ) - return std::format( "{:02d}/{:02d}/{:04d}", month, day, year ); + return fmt::format( "{:02d}/{:02d}/{:04d}", month, day, year ); else if( aFormat == "EU" || aFormat == "european" ) - return std::format( "{:02d}/{:02d}/{:04d}", day, month, year ); + return fmt::format( "{:02d}/{:02d}/{:04d}", day, month, year ); else if( aFormat == "long" ) - return std::format( "{} {}, {}", monthNames[month-1], day, year ); + return fmt::format( "{} {}, {}", monthNames[month-1], day, year ); else if( aFormat == "short" ) - return std::format( "{} {}, {}", monthAbbrev[month-1], day, year ); + return fmt::format( "{} {}, {}", monthAbbrev[month-1], day, year ); else if( aFormat == "Chinese" || aFormat == "chinese" || aFormat == "CN" || aFormat == "cn" || aFormat == "中文" ) - return std::format( "{}年{:02d}月{:02d}日", year, month, day ); + return fmt::format( "{}年{:02d}月{:02d}日", year, month, day ); else if( aFormat == "Japanese" || aFormat == "japanese" || aFormat == "JP" || aFormat == "jp" || aFormat == "日本語" ) - return std::format( "{}年{:02d}月{:02d}日", year, month, day ); + return fmt::format( "{}年{:02d}月{:02d}日", year, month, day ); else if( aFormat == "Korean" || aFormat == "korean" || aFormat == "KR" || aFormat == "kr" || aFormat == "한국어" ) - return std::format( "{}년 {:02d}월 {:02d}일", year, month, day ); + return fmt::format( "{}년 {:02d}월 {:02d}일", year, month, day ); else - return std::format( "{:04d}-{:02d}-{:02d}", year, month, day ); + return fmt::format( "{:04d}-{:02d}-{:02d}", year, month, day ); } static auto GetWeekdayName( int aDaysSinceEpoch ) -> std::string @@ -342,7 +343,7 @@ auto EVAL_VISITOR::operator()( const NODE& aNode ) const -> Result if( m_variableCallback ) return m_variableCallback( varName ); - return MakeError( std::format( "No variable resolver configured for: {}", varName ) ); + return MakeError( fmt::format( "No variable resolver configured for: {}", varName ) ); } case NodeType::BinOp: @@ -436,7 +437,7 @@ auto EVAL_VISITOR::evaluateFunction( const FUNC_DATA& aFunc ) const -> Result( decResult.GetValue() ); } - return MakeValue( std::format( "{:.{}f}", value, decimals ) ); + return MakeValue( fmt::format( "{:.{}f}", value, decimals ) ); } else if( name == "currency" && argc >= 1 ) { @@ -447,7 +448,7 @@ auto EVAL_VISITOR::evaluateFunction( const FUNC_DATA& aFunc ) const -> Result 1 ? VALUE_UTILS::ToString( argValues[1] ) : "$"; - return MakeValue( std::format( "{}{:.2f}", symbol, amount ) ); + return MakeValue( fmt::format( "{}{:.2f}", symbol, amount ) ); } else if( name == "fixed" && argc >= 1 ) { @@ -464,7 +465,7 @@ auto EVAL_VISITOR::evaluateFunction( const FUNC_DATA& aFunc ) const -> Result( decResult.GetValue() ); } - return MakeValue( std::format( "{:.{}f}", value, decimals ) ); + return MakeValue( fmt::format( "{:.{}f}", value, decimals ) ); } // Date formatting functions (return strings!) @@ -579,7 +580,7 @@ auto EVAL_VISITOR::evaluateFunction( const FUNC_DATA& aFunc ) const -> Result( sum / static_cast( argc ) ); } - return MakeError( std::format( "Unknown function: {} with {} arguments", name, argc ) ); + return MakeError( fmt::format( "Unknown function: {} with {} arguments", name, argc ) ); } auto DOC_PROCESSOR::Process( const DOC& aDoc, VariableCallback aVariableCallback ) diff --git a/common/text_eval/text_eval_wrapper.cpp b/common/text_eval/text_eval_wrapper.cpp index df713db35d..084a0f44ac 100644 --- a/common/text_eval/text_eval_wrapper.cpp +++ b/common/text_eval/text_eval_wrapper.cpp @@ -18,6 +18,7 @@ */ #include +#include // Include the KiCad common functionality #include @@ -45,7 +46,6 @@ namespace KI_EVAL #include #include -#include #include // // Token type enum matching the generated parser @@ -507,7 +507,7 @@ private: { if( m_errorCollector ) { - auto error_msg = std::format( "Line {}, Column {}: {}", m_line, m_column, message ); + auto error_msg = fmt::format( "Line {}, Column {}: {}", m_line, m_column, message ); m_errorCollector->AddError( error_msg ); } } @@ -733,7 +733,7 @@ private: auto result = fast_float::from_chars( number_str.data(), number_str.data() + number_str.size(), value ); if( result.ec != std::errc() || result.ptr != number_str.data() + number_str.size() ) - throw std::invalid_argument( std::format( "Cannot convert '{}' to number", number_str ) ); + throw std::invalid_argument( fmt::format( "Cannot convert '{}' to number", number_str ) ); value *= multiplier; @@ -746,7 +746,7 @@ private: } catch( const std::exception& e ) { - add_error( std::format( "Invalid number format: {}", e.what() ) ); + add_error( fmt::format( "Invalid number format: {}", e.what() ) ); value = 0.0; } @@ -1544,7 +1544,7 @@ wxString EXPRESSION_EVALUATOR::expandVariablesOutsideExpressions( // Variable not found, record error but leave ${variable} unchanged if( !m_lastErrors ) m_lastErrors = std::make_unique(); - m_lastErrors->AddError( std::format( "Undefined variable: {}", wxStringToStdString( varName ) ) ); + m_lastErrors->AddError( fmt::format( "Undefined variable: {}", wxStringToStdString( varName ) ) ); pos = closePos + 1; } } @@ -1642,7 +1642,7 @@ EXPRESSION_EVALUATOR::VariableCallback EXPRESSION_EVALUATOR::createCombinedCallb auto result = fast_float::from_chars( resolvedStd.data(), resolvedStd.data() + resolvedStd.size(), numValue ); if( result.ec != std::errc() || result.ptr != resolvedStd.data() + resolvedStd.size() ) - throw std::invalid_argument( std::format( "Cannot convert '{}' to number", resolvedStd ) ); + throw std::invalid_argument( fmt::format( "Cannot convert '{}' to number", resolvedStd ) ); return calc_parser::MakeValue( numValue ); } @@ -1667,7 +1667,7 @@ EXPRESSION_EVALUATOR::VariableCallback EXPRESSION_EVALUATOR::createCombinedCallb // No variable found anywhere return calc_parser::MakeError( - std::format( "Undefined variable: {}", aVarName ) ); + fmt::format( "Undefined variable: {}", aVarName ) ); }; } @@ -1695,7 +1695,7 @@ std::pair EXPRESSION_EVALUATOR::evaluateWithParser( return {aInput, true}; } catch (const std::exception& e) { if (m_lastErrors) { - m_lastErrors->AddError(std::format("Exception: {}", e.what())); + m_lastErrors->AddError(fmt::format("Exception: {}", e.what())); } return {aInput, true}; } @@ -1781,7 +1781,7 @@ std::pair EXPRESSION_EVALUATOR::evaluateWithPartialErrorRecov if( !oldErrors ) oldErrors = std::make_unique(); - oldErrors->AddError( std::format( "Failed to evaluate expression: {}", fullExpr ) ); + oldErrors->AddError( fmt::format( "Failed to evaluate expression: {}", fullExpr ) ); } // Restore the main error collector @@ -1793,7 +1793,7 @@ std::pair EXPRESSION_EVALUATOR::evaluateWithPartialErrorRecov if( !m_lastErrors ) m_lastErrors = std::make_unique(); - m_lastErrors->AddError( std::format( "Exception in expression: {}", fullExpr ) ); + m_lastErrors->AddError( fmt::format( "Exception in expression: {}", fullExpr ) ); hadAnyErrors = true; } } @@ -1905,7 +1905,7 @@ std::pair EXPRESSION_EVALUATOR::evaluateWithFullParser( const { if( m_lastErrors ) { - m_lastErrors->AddError( std::format( "Exception: {}", e.what() ) ); + m_lastErrors->AddError( fmt::format( "Exception: {}", e.what() ) ); } return { aInput, true }; } diff --git a/include/text_eval/text_eval_parser.h b/include/text_eval/text_eval_parser.h index 7780344b22..37a94ba74d 100644 --- a/include/text_eval/text_eval_parser.h +++ b/include/text_eval/text_eval_parser.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -110,7 +110,7 @@ namespace calc_parser } catch( ... ) { - return MakeError( std::format( "Cannot convert '{}' to number", str ) ); + return MakeError( fmt::format( "Cannot convert '{}' to number", str ) ); } } @@ -128,9 +128,9 @@ namespace calc_parser // If the number is very close to a whole number, treat it as such if( std::abs( num - rounded ) < tolerance && std::abs( rounded ) < 1e15 ) - return std::format( "{:.0f}", rounded ); + return fmt::format( "{:.0f}", rounded ); - return std::format( "{}", num ); + return fmt::format( "{}", num ); } // Check if Value represents a "truthy" value for conditionals diff --git a/include/text_eval/text_eval_types.h b/include/text_eval/text_eval_types.h index 42091be47b..7777f7a6e9 100644 --- a/include/text_eval/text_eval_types.h +++ b/include/text_eval/text_eval_types.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace calc_parser { @@ -79,7 +79,7 @@ namespace calc_parser auto AddSyntaxError( int aLine = -1, int aColumn = -1 ) -> void { if( aLine >= 0 && aColumn >= 0 ) - AddError( std::format( "Syntax error at line {}, column {}", aLine, aColumn ) ); + AddError( fmt::format( "Syntax error at line {}, column {}", aLine, aColumn ) ); else AddError( "Syntax error in calculation expression" ); } @@ -98,10 +98,10 @@ namespace calc_parser { std::string result; for( const auto& error : m_errors ) - result += std::format( "Error: {}\n", error ); + result += fmt::format( "Error: {}\n", error ); for( const auto& warning : m_warnings ) - result += std::format( "Warning: {}\n", warning ); + result += fmt::format( "Warning: {}\n", warning ); return result; }