blob: 06962b7247d20681b3df1e4347c85e30fde82e82 [file] [log] [blame]
Vitaly Bukacbed2062015-08-17 12:54:05 -07001// 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
15namespace base {
16
17// Return a C++ string given printf-like input.
Vitaly Buka60b8f002015-08-20 13:47:48 -070018std::string StringPrintf(const char* format, ...)
Vitaly Bukacbed2062015-08-17 12:54:05 -070019 PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
Vitaly Bukacbed2062015-08-17 12:54:05 -070020
21// Return a C++ string given vprintf-like input.
Vitaly Buka60b8f002015-08-20 13:47:48 -070022std::string StringPrintV(const char* format, va_list ap)
Vitaly Bukacbed2062015-08-17 12:54:05 -070023 PRINTF_FORMAT(1, 0) WARN_UNUSED_RESULT;
24
25// Store result into a supplied string and return it.
Vitaly Buka60b8f002015-08-20 13:47:48 -070026const std::string& SStringPrintf(std::string* dst, const char* format, ...)
Vitaly Bukacbed2062015-08-17 12:54:05 -070027 PRINTF_FORMAT(2, 3);
Vitaly Bukacbed2062015-08-17 12:54:05 -070028
29// Append result to a supplied string.
Vitaly Buka60b8f002015-08-20 13:47:48 -070030void StringAppendF(std::string* dst, const char* format, ...)
Vitaly Bukacbed2062015-08-17 12:54:05 -070031 PRINTF_FORMAT(2, 3);
Vitaly Bukacbed2062015-08-17 12:54:05 -070032
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 Buka60b8f002015-08-20 13:47:48 -070035void StringAppendV(std::string* dst, const char* format, va_list ap)
Vitaly Bukacbed2062015-08-17 12:54:05 -070036 PRINTF_FORMAT(2, 0);
Vitaly Bukacbed2062015-08-17 12:54:05 -070037
38} // namespace base
39
40#endif // BASE_STRINGS_STRINGPRINTF_H_