1 | // Copyright 2002 and onwards Google Inc. |
2 | // |
3 | // Printf variants that place their output in a C++ string. |
4 | // |
5 | // Usage: |
6 | // string result = StringPrintf("%d %s\n", 10, "hello"); |
7 | // SStringPrintf(&result, "%d %s\n", 10, "hello"); |
8 | // StringAppendF(&result, "%d %s\n", 20, "there"); |
9 | |
10 | #ifndef _BASE_STRINGPRINTF_H |
11 | #define _BASE_STRINGPRINTF_H |
12 | |
13 | #include <stdarg.h> |
14 | #include <string> |
15 | using std::string; |
16 | |
17 | #include <vector> |
18 | using std::vector; |
19 | |
20 | #include "base/stl_decl.h" |
21 | #include "base/port.h" |
22 | |
23 | // Return a C++ string |
24 | extern string StringPrintf(const char* format, ...) |
25 | // Tell the compiler to do printf format string checking. |
26 | PRINTF_ATTRIBUTE(1,2); |
27 | |
28 | // Store result into a supplied string and return it |
29 | extern const string& SStringPrintf(string* dst, const char* format, ...) |
30 | // Tell the compiler to do printf format string checking. |
31 | PRINTF_ATTRIBUTE(2,3); |
32 | |
33 | // Append result to a supplied string |
34 | extern void StringAppendF(string* dst, const char* format, ...) |
35 | // Tell the compiler to do printf format string checking. |
36 | PRINTF_ATTRIBUTE(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. |
40 | extern void StringAppendV(string* dst, const char* format, va_list ap); |
41 | |
42 | #endif /* _BASE_STRINGPRINTF_H */ |
43 | |