stringprintf.h revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 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_STRINGPRINTF_H_ 6#define BASE_STRINGPRINTF_H_ 7 8#include <stdarg.h> // va_list 9 10#include <string> 11 12#include "base/compiler_specific.h" 13 14namespace base { 15 16// Return a C++ string given printf-like input. 17std::string StringPrintf(const char* format, ...) PRINTF_FORMAT(1, 2); 18std::wstring StringPrintf(const wchar_t* format, ...) WPRINTF_FORMAT(1, 2); 19 20// Return a C++ string given vprintf-like input. 21std::string StringPrintV(const char* format, va_list ap) PRINTF_FORMAT(1, 0); 22 23// Store result into a supplied string and return it. 24const std::string& SStringPrintf(std::string* dst, const char* format, ...) 25 PRINTF_FORMAT(2, 3); 26const std::wstring& SStringPrintf(std::wstring* dst, 27 const wchar_t* format, ...) 28 WPRINTF_FORMAT(2, 3); 29 30// Append result to a supplied string. 31void StringAppendF(std::string* dst, const char* format, ...) 32 PRINTF_FORMAT(2, 3); 33// TODO(evanm): this is only used in a few places in the code; 34// replace with string16 version. 35void StringAppendF(std::wstring* dst, const wchar_t* format, ...) 36 WPRINTF_FORMAT(2, 3); 37 38// Lower-level routine that takes a va_list and appends to a specified 39// string. All other routines are just convenience wrappers around it. 40void StringAppendV(std::string* dst, const char* format, va_list ap) 41 PRINTF_FORMAT(2, 0); 42void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) 43 WPRINTF_FORMAT(2, 0); 44 45} // namespace base 46 47// Don't require the namespace for legacy code. New code should use "base::" or 48// have its own using decl. 49// 50// TODO(brettw) remove these when calling code is converted. 51using base::StringPrintf; 52using base::StringPrintV; 53using base::SStringPrintf; 54using base::StringAppendV; 55using base::StringAppendF; 56using base::StringAppendV; 57 58#endif // BASE_STRINGPRINTF_H_ 59