• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/base_export.h"
13 #include "base/compiler_specific.h"
14 #include "build/build_config.h"
15 
16 namespace base {
17 
18 // Return a C++ string given printf-like input.
19 BASE_EXPORT std::string StringPrintf(_Printf_format_string_ const char* format,
20                                      ...)
21     PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
22 #if defined(OS_WIN)
23 BASE_EXPORT std::wstring StringPrintf(
24     _Printf_format_string_ const wchar_t* format,
25     ...) WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
26 #endif
27 
28 // Return a C++ string given vprintf-like input.
29 BASE_EXPORT std::string StringPrintV(const char* format, va_list ap)
30     PRINTF_FORMAT(1, 0) WARN_UNUSED_RESULT;
31 
32 // Store result into a supplied string and return it.
33 BASE_EXPORT const std::string& SStringPrintf(
34     std::string* dst,
35     _Printf_format_string_ const char* format,
36     ...) PRINTF_FORMAT(2, 3);
37 #if defined(OS_WIN)
38 BASE_EXPORT const std::wstring& SStringPrintf(
39     std::wstring* dst,
40     _Printf_format_string_ const wchar_t* format,
41     ...) WPRINTF_FORMAT(2, 3);
42 #endif
43 
44 // Append result to a supplied string.
45 BASE_EXPORT void StringAppendF(std::string* dst,
46                                _Printf_format_string_ const char* format,
47                                ...) PRINTF_FORMAT(2, 3);
48 #if defined(OS_WIN)
49 BASE_EXPORT void StringAppendF(std::wstring* dst,
50                                _Printf_format_string_ const wchar_t* format,
51                                ...) WPRINTF_FORMAT(2, 3);
52 #endif
53 
54 // Lower-level routine that takes a va_list and appends to a specified
55 // string.  All other routines are just convenience wrappers around it.
56 BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap)
57     PRINTF_FORMAT(2, 0);
58 #if defined(OS_WIN)
59 BASE_EXPORT void StringAppendV(std::wstring* dst,
60                                const wchar_t* format, va_list ap)
61     WPRINTF_FORMAT(2, 0);
62 #endif
63 
64 }  // namespace base
65 
66 #endif  // BASE_STRINGS_STRINGPRINTF_H_
67