Skip to content

Commit

Permalink
api: Change Strutil::format to default to std::format conventions
Browse files Browse the repository at this point in the history
This finally switches Strutil::format to use std::format conventions.
You can still access the old printf convention via
`Strutil::old::format()`, and can explicitly access the new convention
uniformly on both 2.x and 3.x via `Strutil::fmt::format()`.

We've been waiting for 3.0 to make this non-back-compatible change.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Oct 7, 2024
1 parent 704d0db commit 2017fde
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
11 changes: 1 addition & 10 deletions src/include/OpenImageIO/strutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// behave like sprintf (OIIO_FORMAT_IS_FMT==0) or like python / {fmt} /
// C++20ish std::format (OIIO_FORMAT_IS_FMT==1).
#ifndef OIIO_FORMAT_IS_FMT
# define OIIO_FORMAT_IS_FMT 0
# define OIIO_FORMAT_IS_FMT 1
#endif

#define OIIO_FORMAT_DEPRECATED OIIO_DEPRECATED("old style (printf-like) formatting version of this function is deprecated")
Expand Down Expand Up @@ -309,15 +309,6 @@ std::string OIIO_UTIL_API vsprintf (const char *fmt, va_list ap)
#endif
;

/// Return a std::string formatted like Strutil::format, but passed
/// already as a va_list. This is not guaranteed type-safe and is not
/// extensible like format(). Use with caution!
OIIO_DEPRECATED("use `vsprintf` instead")
std::string OIIO_UTIL_API vformat (const char *fmt, va_list ap)
#if defined(__GNUC__) && !defined(__CUDACC__)
__attribute__ ((format (printf, 1, 0) ))
#endif
;

/// Return a string expressing a number of bytes, in human readable form.
/// - memformat(153) -> "153 B"
Expand Down
9 changes: 0 additions & 9 deletions src/libutil/strutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,6 @@ Strutil::vsprintf(const char* fmt, va_list ap)



std::string
Strutil::vformat(const char* fmt, va_list ap)
{
// For now, just treat as a synonym for vsprintf
return vsprintf(fmt, ap);
}



std::string
Strutil::memformat(long long bytes, int digits)
{
Expand Down

0 comments on commit 2017fde

Please sign in to comment.