string_printf.h 1.27 KB
Newer Older
gejun's avatar
gejun committed
1
// Copyright (c) 2011 Baidu, Inc.
gejun's avatar
gejun committed
2 3
// Date: Mon. Nov 7 14:47:36 CST 2011

gejun's avatar
gejun committed
4 5
#ifndef BAIDU_BASE_STRING_PRINTF_H
#define BAIDU_BASE_STRING_PRINTF_H
gejun's avatar
gejun committed
6 7 8 9

#include <string>                                // std::string
#include <stdarg.h>                              // va_list

10
namespace butil {
gejun's avatar
gejun committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

// Convert |format| and associated arguments to std::string
std::string string_printf(const char* format, ...)
    __attribute__ ((format (printf, 1, 2)));

// Write |format| and associated arguments into |output|
// Returns 0 on success, -1 otherwise.
int string_printf(std::string* output, const char* fmt, ...)
    __attribute__ ((format (printf, 2, 3)));

// Write |format| and associated arguments in form of va_list into |output|.
// Returns 0 on success, -1 otherwise.
int string_vprintf(std::string* output, const char* format, va_list args);

// Append |format| and associated arguments to |output|
// Returns 0 on success, -1 otherwise.
int string_appendf(std::string* output, const char* format, ...)
    __attribute__ ((format (printf, 2, 3)));

// Append |format| and associated arguments in form of va_list to |output|.
// Returns 0 on success, -1 otherwise.
int string_vappendf(std::string* output, const char* format, va_list args);


35
}  // namespace butil
gejun's avatar
gejun committed
36

gejun's avatar
gejun committed
37
#endif  // BAIDU_BASE_STRING_PRINTF_H