MCPcopy Create free account
hub / github.com/SpartanJ/eepp / format

Function format

include/eepp/core/string.hpp:539–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

537
538 template <typename... Args>
539 static std::string format( std::string_view format, Args&&... args ) {
540#ifdef __clang__
541#pragma clang diagnostic push
542#pragma clang diagnostic ignored "-Wformat-security"
543#elif defined( __GNUC__ )
544#pragma GCC diagnostic push
545#pragma GCC diagnostic ignored "-Wformat-security"
546#endif
547
548 int reqSize =
549 std::snprintf( nullptr, 0, format.data(),
550 FormatArg<std::decay_t<Args>>::get( std::forward<Args>( args ) )... );
551
552 if ( reqSize < 0 )
553 return "";
554
555 std::size_t bufSize = static_cast<std::size_t>( reqSize ) + 1;
556 std::string result( bufSize, '\0' );
557
558 int writtenChars =
559 std::snprintf( &result[0], bufSize, format.data(),
560 FormatArg<std::decay_t<Args>>::get( std::forward<Args>( args ) )... );
561
562 if ( writtenChars < 0 )
563 return "";
564
565 if ( static_cast<std::size_t>( writtenChars ) < bufSize ) {
566 result.resize( static_cast<std::size_t>( writtenChars ) );
567 } else {
568 result.resize( bufSize - 1 );
569 }
570
571#ifdef __clang__
572#pragma clang diagnostic pop
573#elif defined( __GNUC__ )
574#pragma GCC diagnostic pop
575#endif
576 return result;
577 }
578
579 /** Format a char buffer */
580 static void formatBuffer( char* Buffer, int BufferSize, const char* format, ... );

Callers 15

createNewLayoutMethod · 0.85
getVersionNumStringMethod · 0.85
getVersionFullNameMethod · 0.85
UITreeViewFSMethod · 0.85
moveFilesMethod · 0.85
deleteItemsMethod · 0.85
handle_stacktraceMethod · 0.85
updateStepMethod · 0.85
UIBuildSettingsMethod · 0.85
refreshTabMethod · 0.85
runUpdateMethod · 0.85
createDocumentMenuMethod · 0.85

Calls 2

dataMethod · 0.45
resizeMethod · 0.45

Tested by 9

UTESTFunction · 0.68
UTESTFunction · 0.68
UTESTFunction · 0.68
UTESTFunction · 0.68
renderMethod · 0.68
columnNameMethod · 0.68
dataMethod · 0.68
mainLoopFunction · 0.68
mainFunction · 0.68