michael@0: // Copyright 2013 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_STRINGS_STRINGPRINTF_H_ michael@0: #define BASE_STRINGS_STRINGPRINTF_H_ michael@0: michael@0: #include // va_list michael@0: michael@0: #include michael@0: michael@0: #include "base/base_export.h" michael@0: #include "base/compiler_specific.h" michael@0: michael@0: namespace base { michael@0: michael@0: // Return a C++ string given printf-like input. michael@0: BASE_EXPORT std::string StringPrintf(const char* format, ...) michael@0: PRINTF_FORMAT(1, 2); michael@0: // OS_ANDROID's libc does not support wchar_t, so several overloads are omitted. michael@0: #if !defined(OS_ANDROID) michael@0: BASE_EXPORT std::wstring StringPrintf(const wchar_t* format, ...) michael@0: WPRINTF_FORMAT(1, 2); michael@0: #endif michael@0: michael@0: // Return a C++ string given vprintf-like input. michael@0: BASE_EXPORT std::string StringPrintV(const char* format, va_list ap) michael@0: PRINTF_FORMAT(1, 0); michael@0: michael@0: // Store result into a supplied string and return it. michael@0: BASE_EXPORT const std::string& SStringPrintf(std::string* dst, michael@0: const char* format, ...) michael@0: PRINTF_FORMAT(2, 3); michael@0: #if !defined(OS_ANDROID) michael@0: BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst, michael@0: const wchar_t* format, ...) michael@0: WPRINTF_FORMAT(2, 3); michael@0: #endif michael@0: michael@0: // Append result to a supplied string. michael@0: BASE_EXPORT void StringAppendF(std::string* dst, const char* format, ...) michael@0: PRINTF_FORMAT(2, 3); michael@0: #if !defined(OS_ANDROID) michael@0: // TODO(evanm): this is only used in a few places in the code; michael@0: // replace with string16 version. michael@0: BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...) michael@0: WPRINTF_FORMAT(2, 3); michael@0: #endif michael@0: michael@0: // Lower-level routine that takes a va_list and appends to a specified michael@0: // string. All other routines are just convenience wrappers around it. michael@0: BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap) michael@0: PRINTF_FORMAT(2, 0); michael@0: #if !defined(OS_ANDROID) michael@0: BASE_EXPORT void StringAppendV(std::wstring* dst, michael@0: const wchar_t* format, va_list ap) michael@0: WPRINTF_FORMAT(2, 0); michael@0: #endif michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_STRINGS_STRINGPRINTF_H_