blob: 9a992373159853075901c2dac7b16e414508bc64 [file] [log] [blame]
[email protected]90ea0782012-08-01 10:30:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]e6811ed52010-08-17 03:45:372// 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
[email protected]0bea7252011-08-05 15:34:0012#include "base/base_export.h"
[email protected]e6811ed52010-08-17 03:45:3713#include "base/compiler_specific.h"
14
15namespace base {
16
17// Return a C++ string given printf-like input.
[email protected]0bea7252011-08-05 15:34:0018BASE_EXPORT std::string StringPrintf(const char* format, ...)
19 PRINTF_FORMAT(1, 2);
[email protected]90ea0782012-08-01 10:30:0220// OS_ANDROID's libc does not support wchar_t, so several overloads are omitted.
21#if !defined(OS_ANDROID)
[email protected]0bea7252011-08-05 15:34:0022BASE_EXPORT std::wstring StringPrintf(const wchar_t* format, ...)
[email protected]f53121d2011-03-22 22:11:0823 WPRINTF_FORMAT(1, 2);
[email protected]90ea0782012-08-01 10:30:0224#endif
[email protected]e6811ed52010-08-17 03:45:3725
26// Return a C++ string given vprintf-like input.
[email protected]0bea7252011-08-05 15:34:0027BASE_EXPORT std::string StringPrintV(const char* format, va_list ap)
[email protected]f53121d2011-03-22 22:11:0828 PRINTF_FORMAT(1, 0);
[email protected]e6811ed52010-08-17 03:45:3729
30// Store result into a supplied string and return it.
[email protected]0bea7252011-08-05 15:34:0031BASE_EXPORT const std::string& SStringPrintf(std::string* dst,
32 const char* format, ...)
[email protected]e6811ed52010-08-17 03:45:3733 PRINTF_FORMAT(2, 3);
[email protected]90ea0782012-08-01 10:30:0234#if !defined(OS_ANDROID)
[email protected]0bea7252011-08-05 15:34:0035BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst,
36 const wchar_t* format, ...)
[email protected]e6811ed52010-08-17 03:45:3737 WPRINTF_FORMAT(2, 3);
[email protected]90ea0782012-08-01 10:30:0238#endif
[email protected]e6811ed52010-08-17 03:45:3739
40// Append result to a supplied string.
[email protected]0bea7252011-08-05 15:34:0041BASE_EXPORT void StringAppendF(std::string* dst, const char* format, ...)
[email protected]e6811ed52010-08-17 03:45:3742 PRINTF_FORMAT(2, 3);
[email protected]90ea0782012-08-01 10:30:0243#if !defined(OS_ANDROID)
[email protected]0f337f02010-10-14 18:02:5344// TODO(evanm): this is only used in a few places in the code;
45// replace with string16 version.
[email protected]0bea7252011-08-05 15:34:0046BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...)
[email protected]e6811ed52010-08-17 03:45:3747 WPRINTF_FORMAT(2, 3);
[email protected]90ea0782012-08-01 10:30:0248#endif
[email protected]e6811ed52010-08-17 03:45:3749
50// Lower-level routine that takes a va_list and appends to a specified
51// string. All other routines are just convenience wrappers around it.
[email protected]0bea7252011-08-05 15:34:0052BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap)
[email protected]e6811ed52010-08-17 03:45:3753 PRINTF_FORMAT(2, 0);
[email protected]90ea0782012-08-01 10:30:0254#if !defined(OS_ANDROID)
[email protected]0bea7252011-08-05 15:34:0055BASE_EXPORT void StringAppendV(std::wstring* dst,
56 const wchar_t* format, va_list ap)
[email protected]e6811ed52010-08-17 03:45:3757 WPRINTF_FORMAT(2, 0);
[email protected]90ea0782012-08-01 10:30:0258#endif
[email protected]e6811ed52010-08-17 03:45:3759
60} // namespace base
61
62// Don't require the namespace for legacy code. New code should use "base::" or
63// have its own using decl.
64//
65// TODO(brettw) remove these when calling code is converted.
66using base::StringPrintf;
[email protected]e6811ed52010-08-17 03:45:3767
68#endif // BASE_STRINGPRINTF_H_