string_format.h 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright 2020 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef RTC_BASE_STRINGS_STRING_FORMAT_H_
  11. #define RTC_BASE_STRINGS_STRING_FORMAT_H_
  12. #include <string>
  13. namespace rtc {
  14. #if defined(__GNUC__)
  15. #define RTC_PRINTF_FORMAT(format_param, dots_param) \
  16. __attribute__((format(printf, format_param, dots_param)))
  17. #else
  18. #define RTC_PRINTF_FORMAT(format_param, dots_param)
  19. #endif
  20. // Return a C++ string given printf-like input.
  21. // Based on base::StringPrintf() in Chrome but without its fancy dynamic memory
  22. // allocation for any size of the input buffer.
  23. std::string StringFormat(const char* fmt, ...) RTC_PRINTF_FORMAT(1, 2);
  24. } // namespace rtc
  25. #endif // RTC_BASE_STRINGS_STRING_FORMAT_H_