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