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/compiler_specific.h" 13#include "util/build_config.h" 14 15namespace base { 16 17// Return a C++ string given printf-like input. 18[[nodiscard]] std::string StringPrintf( 19 _Printf_format_string_ const char* format, 20 ...) PRINTF_FORMAT(1, 2); 21 22// Return a C++ string given vprintf-like input. 23[[nodiscard]] std::string StringPrintV(const char* format, va_list ap) 24 PRINTF_FORMAT(1, 0); 25 26// Store result into a supplied string and return it. 27const std::string& SStringPrintf(std::string* dst, 28 _Printf_format_string_ const char* format, 29 ...) PRINTF_FORMAT(2, 3); 30 31// Append result to a supplied string. 32void StringAppendF(std::string* dst, 33 _Printf_format_string_ const char* format, 34 ...) PRINTF_FORMAT(2, 3); 35 36// Lower-level routine that takes a va_list and appends to a specified 37// string. All other routines are just convenience wrappers around it. 38void StringAppendV(std::string* dst, const char* format, va_list ap) 39 PRINTF_FORMAT(2, 0); 40 41} // namespace base 42 43#endif // BASE_STRINGS_STRINGPRINTF_H_ 44