Skip to content

Commit

Permalink
StringUtil: Purge StdStringFromFormat()
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jul 19, 2024
1 parent 567b86c commit 24ef76b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 38 deletions.
33 changes: 0 additions & 33 deletions src/common/string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,6 @@
#include "windows_headers.h"
#endif

std::string StringUtil::StdStringFromFormat(const char* format, ...)
{
std::va_list ap;
va_start(ap, format);
std::string ret = StdStringFromFormatV(format, ap);
va_end(ap);
return ret;
}

std::string StringUtil::StdStringFromFormatV(const char* format, std::va_list ap)
{
std::va_list ap_copy;
va_copy(ap_copy, ap);

#ifdef _WIN32
int len = _vscprintf(format, ap_copy);
#else
int len = std::vsnprintf(nullptr, 0, format, ap_copy);
#endif
va_end(ap_copy);

std::string ret;

// If an encoding error occurs, len is -1. Which we definitely don't want to resize to.
if (len > 0)
{
ret.resize(len);
std::vsnprintf(ret.data(), ret.size() + 1, format, ap);
}

return ret;
}

bool StringUtil::WildcardMatch(const char* subject, const char* mask, bool case_sensitive /*= true*/)
{
if (case_sensitive)
Expand Down
5 changes: 0 additions & 5 deletions src/common/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once
#include "types.h"
#include <charconv>
#include <cstdarg>
#include <cstddef>
#include <cstring>
#include <iomanip>
Expand All @@ -27,10 +26,6 @@

namespace StringUtil {

/// Constructs a std::string from a format string.
std::string StdStringFromFormat(const char* format, ...) printflike(1, 2);
std::string StdStringFromFormatV(const char* format, std::va_list ap);

/// Checks if a wildcard matches a search string.
bool WildcardMatch(const char* subject, const char* mask, bool case_sensitive = true);

Expand Down

0 comments on commit 24ef76b

Please sign in to comment.