foobar2000 SDK  2015-08-03
Public Member Functions | Static Public Member Functions
pfc::string_printf

#include <string_base.h>

+ Inheritance diagram for pfc::string_printf:

Public Member Functions

 string_printf (const char *fmt,...)
 
void run (const char *fmt, va_list list)
 

Static Public Member Functions

static void g_run (string_base &out, const char *fmt, va_list list)
 

Detailed Description

Definition at line 466 of file string_base.h.

Constructor & Destructor Documentation

pfc::string_printf::string_printf ( const char *  fmt,
  ... 
)
explicit

Definition at line 112 of file printf.cpp.

113 {
114  va_list list;
115  va_start(list,fmt);
116  run(fmt,list);
117  va_end(list);
118 }
void run(const char *fmt, va_list list)
Definition: printf.cpp:16

Member Function Documentation

void pfc::string_printf::g_run ( string_base out,
const char *  fmt,
va_list  list 
)
static

Definition at line 20 of file printf.cpp.

21 {
22  out.reset();
23  while(*fmt)
24  {
25  if (*fmt=='%')
26  {
27  fmt++;
28  if (*fmt=='%')
29  {
30  out.add_char('%');
31  fmt++;
32  }
33  else
34  {
35  bool force_sign = false;
36  if (*fmt=='+')
37  {
38  force_sign = true;
39  fmt++;
40  }
41  char padchar = (*fmt == '0') ? '0' : ' ';
42  t_size pad = 0;
43  while(*fmt>='0' && *fmt<='9')
44  {
45  pad = pad * 10 + (*fmt - '0');
46  fmt++;
47  }
48 
49  if (*fmt=='s' || *fmt=='S')
50  {
51  const char * ptr = va_arg(list,const char*);
52  t_size len = strlen(ptr);
53  if (pad>len) out.add_chars(padchar,pad-len);
54  out.add_string(ptr);
55  fmt++;
56 
57  }
58  else if (*fmt=='i' || *fmt=='I' || *fmt=='d' || *fmt=='D')
59  {
60  int val = va_arg(list,int);
61  if (force_sign && val>0) out.add_char('+');
62  pfc::format_int temp( val );
63  t_size len = strlen(temp);
64  if (pad>len) out.add_chars(padchar,pad-len);
65  out.add_string(temp);
66  fmt++;
67  }
68  else if (*fmt=='u' || *fmt=='U')
69  {
70  int val = va_arg(list,int);
71  if (force_sign && val>0) out.add_char('+');
72  pfc::format_uint temp(val);
73  t_size len = strlen(temp);
74  if (pad>len) out.add_chars(padchar,pad-len);
75  out.add_string(temp);
76  fmt++;
77  }
78  else if (*fmt=='x' || *fmt=='X')
79  {
80  int val = va_arg(list,int);
81  if (force_sign && val>0) out.add_char('+');
82  pfc::format_uint temp(val, 0, 16);
83  if (*fmt=='X')
84  {
85  char * t = const_cast< char* > ( temp.get_ptr() );
86  while(*t)
87  {
88  if (*t>='a' && *t<='z')
89  *t += 'A' - 'a';
90  t++;
91  }
92  }
93  t_size len = strlen(temp);
94  if (pad>len) out.add_chars(padchar,pad-len);
95  out.add_string(temp);
96  fmt++;
97  }
98  else if (*fmt=='c' || *fmt=='C')
99  {
100  out.add_char(va_arg(list,int));
101  fmt++;
102  }
103  }
104  }
105  else
106  {
107  out.add_char(*(fmt++));
108  }
109  }
110 }
size_t t_size
Definition: int_types.h:48
void pfc::string_printf::run ( const char *  fmt,
va_list  list 
)

Definition at line 16 of file printf.cpp.

16 {g_run(*this,fmt,list);}
static void g_run(string_base &out, const char *fmt, va_list list)
Definition: printf.cpp:20

The documentation for this class was generated from the following files: