Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_STRINGS_STRINGPRINTF_H_ |
| 6 | #define BASE_STRINGS_STRINGPRINTF_H_ |
| 7 | |
| 8 | #include <stdarg.h> // va_list |
| 9 | |
| 10 | #include <string> |
| 11 | |
| 12 | #include "base/base_export.h" |
| 13 | #include "base/compiler_specific.h" |
| 14 | |
| 15 | namespace base { |
| 16 | |
| 17 | // Return a C++ string given printf-like input. |
Vitaly Buka | 60b8f00 | 2015-08-20 13:47:48 -0700 | [diff] [blame] | 18 | std::string StringPrintf(const char* format, ...) |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 19 | PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT; |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 20 | |
| 21 | // Return a C++ string given vprintf-like input. |
Vitaly Buka | 60b8f00 | 2015-08-20 13:47:48 -0700 | [diff] [blame] | 22 | std::string StringPrintV(const char* format, va_list ap) |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 23 | PRINTF_FORMAT(1, 0) WARN_UNUSED_RESULT; |
| 24 | |
| 25 | // Store result into a supplied string and return it. |
Vitaly Buka | 60b8f00 | 2015-08-20 13:47:48 -0700 | [diff] [blame] | 26 | const std::string& SStringPrintf(std::string* dst, const char* format, ...) |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 27 | PRINTF_FORMAT(2, 3); |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 28 | |
| 29 | // Append result to a supplied string. |
Vitaly Buka | 60b8f00 | 2015-08-20 13:47:48 -0700 | [diff] [blame] | 30 | void StringAppendF(std::string* dst, const char* format, ...) |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 31 | PRINTF_FORMAT(2, 3); |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 32 | |
| 33 | // Lower-level routine that takes a va_list and appends to a specified |
| 34 | // string. All other routines are just convenience wrappers around it. |
Vitaly Buka | 60b8f00 | 2015-08-20 13:47:48 -0700 | [diff] [blame] | 35 | void StringAppendV(std::string* dst, const char* format, va_list ap) |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 36 | PRINTF_FORMAT(2, 0); |
Vitaly Buka | cbed206 | 2015-08-17 12:54:05 -0700 | [diff] [blame] | 37 | |
| 38 | } // namespace base |
| 39 | |
| 40 | #endif // BASE_STRINGS_STRINGPRINTF_H_ |